Electronic circuits · no code

Diode AND Logic Gate

An AND logic gate built from two diodes: the LED lights only when both inputs are 1. Try it with two switches and check its truth table.

  • LevelBeginner
  • Time20 min
  • Power9 V DC
  • CategoryLights & LEDs

Bill of materials

Everything you need to build it, with the reference you will see on the schematic.

Bill of materials
Qty Part Ref.
2 Slide switch (SPDT, 3 legs) SA, SB
1 470 Ω resistor (yellow-violet-brown) R1
2 Diode 1N4148 D1, D2
1 red LED D3
1 9 V battery with snap clip BT1
1 Breadboard (400 tie-points or more)
7 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.

Circuit diagram of “Diode AND Logic Gate”
Circuit diagram
Breadboard layout of “Diode AND Logic Gate”
Breadboard layout

Wire it step by step

  1. 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 7f, the middle one (common, C) in 8f and the right one (position 2) in 9f.
    • 470 Ω resistor R1 (bands: yellow, violet, brown, gold): one leg in 3h and the other in 6h (either way round).
    • 1N4148 diode D1: the end with the silver stripe (cathode) in 10f and the other end (anode) in 13f.
    • 1N4148 diode D2: the end with the silver stripe (cathode) in 8i and the other end (anode) in 13i.
    • red LED D3: the long leg (+, anode) in 13g and the short leg (−, cathode, flat side) in 14g.
  2. Add the jumper wires
    • Red wire: from 3j to the + (red) rail.
    • Red wire: from 7j to the + (red) rail.
    • Orange wire: from 4j to 10j.
    • Black wire: from 5j to the − (blue) rail.
    • Black wire: from 9j to the − (blue) rail.
    • Black wire: from 14j to the − (blue) rail.
    • Turquoise wire: from 6j to 13j.
  3. 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.
  4. Test the circuit
    • Try the four combinations: A=0 and B=0, A=1 and B=0, A=0 and B=1 should leave the LED off; only A=1 and B=1 lights it. With a multimeter, measure the output: about 0.7 V in the first three cases and about 1.9 V in the fourth.

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?

  1. 1You set A and B to 1 or 0
  2. 2A diode whose input is 0 conducts and holds the output near 0 V
  3. 3Only with A and B both 1 does neither conduct
  4. 4The output rises and the LED lights

Resistor R1 pushes the output towards the battery +, but each input is tied to the output by a 1N4148 diode placed so that it conducts towards the input. If A or B is 0 (at GND), its diode conducts and “pulls” the output down to about 0.7 V, which is too little for the LED (it needs almost 2 V): it stays off. Only when A and B are both 1 are the two diodes blocked, the current from R1 has no other way than through the LED, and the output rises to about 1.9 V: the LED lights with about 15 mA. So the output is 1 only if A and B are 1: that is an AND. 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.71 V
LED currentunder 0.1 mA
A = 1, B = 0
Voltage at the output≈ 0.75 V
LED currentunder 0.1 mA
A = 0, B = 1
Voltage at the output≈ 0.75 V
LED currentunder 0.1 mA
A = 1, B = 1
Voltage at the output≈ 1.92 V
LED current≈ 15 mA

Approximate values, calculated with typical parts. With real parts they can vary by 10 % or more.

If something does not work

The LED lights with only one input at 1?

One of the diodes is the wrong way round: the band (cathode) of D1 and D2 must be on the switch side, not on the R1 side. With a reversed diode that input can no longer turn the LED off.

The LED never lights?

Check the LED (long leg + towards R1) and that each switch has its common leg (the middle one) in its diode’s row and the end legs on the + and − of the board.

Want to automate this circuit with code?

Learn how to program sensors and custom schedules in our e-book “Arduino from Scratch”.