Diode OR Logic Gate
An OR logic gate built from two diodes: the LED lights when at least one of the two inputs is 1. The simplest version of a diode gate.
Bill of materials
Everything you need to build it, with the reference you will see on the schematic.
| Qty | Part | Ref. |
|---|---|---|
| 2 | Slide switch (SPDT, 3 legs) | SA, SB |
| 2 | Diode 1N4148 | D1, D2 |
| 1 | 470 Ω resistor (yellow-violet-brown) | R1 |
| 1 | red LED | D3 |
| 1 | 9 V battery with snap clip | BT1 |
| 1 | Breadboard (400 tie-points or more) | |
| 6 | Jumper wires |
Missing parts? The kits recommended by Impeca Tech include almost all of them. See the kits
Schematic & wiring
On the left, the circuit diagram; on the right, the same circuit built on a breadboard. Both connect exactly the same things.
Wire it step by step
-
Place the components
- Slide switch SA with its three legs on row f: the left one (position 1) in 3f, the middle one (common, C) in 4f and the right one (position 2) in 5f.
- Slide switch SB with its three legs on row f: the left one (position 1) in 6f, the middle one (common, C) in 7f and the right one (position 2) in 8f.
- 1N4148 diode D1: the end with the silver stripe (cathode) in 9h and the other end (anode) in 4h.
- 1N4148 diode D2: the end with the silver stripe (cathode) in 9f and the other end (anode) in 12f.
- 470 Ω resistor R1 (bands: yellow, violet, brown, gold): one leg in 9i and the other in 13i (either way round).
- red LED D3: the long leg (+, anode) in 13f and the short leg (−, cathode, flat side) in 14f.
-
Add the jumper wires
- Red wire: from 3j to the + (red) rail.
- Red wire: from 6j to the + (red) rail.
- Black wire: from 5j to the − (blue) rail.
- Black wire: from 8j to the − (blue) rail.
- Black wire: from 14j to the − (blue) rail.
- Orange wire: from 7j to 12j.
-
Connect the battery
- Connect the 9 V battery to its clip: the clip’s red lead to the + (red) rail and the black one to the − (blue) rail. Do this last, once everything else is in place.
-
Test the circuit
- Try the four combinations: with A=0 and B=0 the LED is off; with A=1 and B=0, A=0 and B=1, and A=1 and B=1 it lights, always with the same brightness. On a multimeter the output reads about 0 V in the first case and about 8 V in the other three.
How to read the holes: the letter is the row and the number is the column of the breadboard (for example 7f). The red (+) and blue (−) rails are the two long lines along the edge.
How does it work?
- 1You set A and B to 1 or 0
- 2A diode whose input is 1 conducts towards the output
- 3The output rises to almost the battery voltage
- 4The LED lights
The two 1N4148 diodes are placed so that they conduct from the input towards the output. If either input is 1 (at the battery +), its diode conducts, pushes the output up to about 8.2 V (the battery voltage minus the roughly 0.7 V that the diode keeps) and current flows through R1 and the LED: it lights with about 13 mA. If both are 0, neither diode conducts, the output stays at 0 V and the LED is off. The output is 1 when A or B (or both) is 1: that is an OR. Notice that when both inputs are 1 the LED does not shine twice as bright: each diode only lets one input switch the output on. Each input (A and B) is set to 1 or 0 with a 3-leg slide switch: towards position 1 it is tied to the battery + (level 1) and towards position 2 to GND (level 0). That way the input is never left “floating”, as it would be with a pushbutton.
Testing & troubleshooting
What you should see
- A = 0, B = 0
- Voltage at the output≈ 0.00 V
- LED currentunder 0.1 mA
- A = 1, B = 0
- Voltage at the output≈ 8.24 V
- LED current≈ 13 mA
- A = 0, B = 1
- Voltage at the output≈ 8.24 V
- LED current≈ 13 mA
- A = 1, B = 1
- Voltage at the output≈ 8.27 V
- LED current≈ 14 mA
Approximate values, calculated with typical parts. With real parts they can vary by 10 % or more.
If something does not work
The LED does not light with any combination?
Check the diode orientation: here the band (cathode) of D1 and D2 goes towards the output (R1), not towards the switches. Also check the LED (long leg + towards R1).
The LED stays on with both inputs at 0?
An input is not really at GND: check that the position-2 leg of each switch reaches the board − and that no leg sits in the wrong hole.
Want to automate this circuit with code?
Learn how to program sensors and custom schedules in our e-book “Arduino from Scratch”.