Electronic circuits · no code

Transistor NAND Logic Gate

A NAND gate with two transistors in series: the LED goes off only when both inputs are 1. The NAND is the “universal” gate: any other gate can be built from it.

  • LevelBeginner
  • Time25 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
2 10 kΩ resistor (brown-black-orange) R1, R2
2 BC547 NPN transistor Q1, Q2
1 470 Ω resistor (yellow-violet-brown) R3
1 red LED D1
1 9 V battery with snap clip BT1
1 Breadboard (400 tie-points or more)
10 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 “Transistor NAND Logic Gate”
Circuit diagram
Breadboard layout of “Transistor NAND 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 6f, the middle one (common, C) in 7f and the right one (position 2) in 8f.
    • 10 kΩ resistor R1 (bands: brown, black, orange, gold): one leg in 4h and the other in 9h (either way round).
    • 10 kΩ resistor R2 (bands: brown, black, orange, gold): one leg in 10f and the other in 13f (either way round).
    • BC547 transistor Q1 with the flat face (the one with the text) towards you, left to right: collector (C) in 14h, base (B) in 15h, emitter (E) in 16h.
    • BC547 transistor Q2 with the flat face (the one with the text) towards you, left to right: collector (C) in 16f, base (B) in 17f, emitter (E) in 18f.
    • 470 Ω resistor R3 (bands: yellow, violet, brown, gold): one leg in 22f and the other in 19f (either way round).
    • red LED D1: the long leg (+, anode) in 19h and the short leg (−, cathode, flat side) in 18h.
  2. Add the jumper wires
    • Red wire: from 3j to the + (red) rail.
    • Red wire: from 6j to the + (red) rail.
    • Red wire: from 22j to the + (red) rail.
    • Black wire: from 5j to the − (blue) rail.
    • Black wire: from 8j to the − (blue) rail.
    • Black wire: from 18j to the − (blue) rail.
    • Orange wire: from 7j to 10j.
    • Turquoise wire: from 9j to 15j.
    • Purple wire: from 13j to 17j.
    • Pink wire: from 14j to 19j.
  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: the LED is on with A=0 and B=0, with A=1 and B=0 and with A=0 and B=1, and goes off only with A=1 and B=1. It is exactly the opposite of the AND. On a multimeter the output reads about 1.9 V when the LED is on and about 0.1 V when it goes off.

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. 2Each transistor conducts only if its input is 1
  3. 3With both conducting, the output falls to almost 0 V
  4. 4The LED goes off only with A=1 and B=1

Q1 and Q2 are in series between the output and GND, like two switches one behind the other. For the output to fall to 0 V both must conduct, and each one conducts only if its input (through R1 or R2, 10 kΩ) is 1. With A=1 and B=1 the output drops to about 0.1 V and the LED, which sits between the output and GND, goes off. In any other combination at least one transistor is cut off, the current from R3 (470 Ω) has no way to GND and goes entirely through the LED, which lights with about 15 mA. The output is 0 only if A and B are 1: that is a NAND (NOT-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≈ 1.92 V
LED current≈ 15 mA
A = 1, B = 0
Voltage at the output≈ 1.92 V
LED current≈ 16 mA
A = 0, B = 1
Voltage at the output≈ 1.92 V
LED current≈ 15 mA
A = 1, B = 1
Voltage at the output≈ 0.11 V
LED currentunder 0.1 mA

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

If something does not work

The LED goes off with only one input at 1?

The transistors must be in series: the emitter of Q1 goes to the collector of Q2 (not to GND), and only the emitter of Q2 goes to GND. If Q1 has its emitter straight to GND it behaves as a NOT of its own input.

The LED never goes off, even with both inputs at 1?

One of the two transistors is not getting base current. Check that R1 and R2 reach the middle leg of Q1 and Q2 and that both inputs are really at 1 (position-1 leg to the board +).

Want to automate this circuit with code?

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