Projects / Build a latch from NAND gates

Build a latch from NAND gates

Beginner1.7 hGuided buildReviewed

Build it step by step

0 of 8 done
  1. Place the chip

    Straddle the breadboard gap, notch to the left.

  2. Wire power

    Pin 14 to 5V, pin 7 to GND.

  3. Tie unused inputs

    Pins 9, 10, 12 and 13 to GND.

  4. Wire the latch

    Pin 3 to pin 5, pin 6 to pin 2.

  5. Add the buttons

    Pin 1 and pin 4 each with a 10 kilohm pull-up and a button to GND.

  6. 15.7 mA

    Add the LEDs

    Pin 3 and pin 6 each through 330 ohm to an LED to GND.

  7. 15.7 mA

    Press set

    The red LED lights and stays on after release.

  8. 15.7 mA

    Press reset

    The green LED lights and stays on after release.

In short

How do you build a build a latch from NAND gates?

Build an SR latch from two NAND gates and see its memory behaviour with two buttons and two LEDs. You need 74HC00 quad NAND gate, Tactile push button 6 mm × 2, LED 5 mm red, LED 5 mm green, Resistor 10 kΩ × 2, Resistor 330 Ω × 2, Micro USB breakout board, 5 V 2 A USB adapter, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 8 steps and about 100 minutes.

Level
Beginner
Time
About 100 min
Parts
10

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Chip pin 14 (VCC)5V from the USB breakoutPower
Chip pin 7 (GND)GND from the USB breakoutGround
Set buttonChip pin 1 with a 10 kilohm pull-up to 5V, button to GNDActive-low set input
Reset buttonChip pin 4 with a 10 kilohm pull-up to 5V, button to GNDActive-low reset input
Gate A output pin 3 (Q)Gate B input pin 5, and a red LED through 330 ohm to GNDOutput Q
Gate B output pin 6 (Q-bar)Gate A input pin 2, and a green LED through 330 ohm to GNDOutput Q-bar
Unused gate inputsPins 9, 10, 12 and 13 to GNDNever leave CMOS inputs open

Code

Two NAND gates, each feeding its output into the other's input, make the simplest memory circuit. When both inputs are high the circuit holds whatever state it was in, which is the memory. Pressing set pulls one input low, which forces that gate's output high and flips the pair into the set state; pressing reset does the opposite. The red LED shows Q and the green LED shows its opposite, so exactly one is lit once the latch has settled. If you press both buttons together, both outputs go high, which is the forbidden state; when you release both at once the result depends on tiny differences between the gates and may be either way. Building the latch makes a flip-flop less mysterious: the registers and counters inside every microcontroller are made from this feedback idea, with extra gates to make them clocked and tidy. The pull-up resistors keep the inputs high when a button is not pressed, and the four unused inputs are tied to ground because floating CMOS inputs behave unpredictably and can waste power.

No code is needed. This is pure logic, built from two gates.

Truth table for the NAND latch (inputs are active low, a button press makes an input 0):
  Set  Reset   Q   Q-bar
   1     1     hold the last state  (the latch remembers)
   0     1     1   0      (set)
   1     0     0   1      (reset)
   0     0     1   1      (forbidden: both outputs high)

Releasing both buttons from the forbidden state at the same moment leaves the
latch in an unpredictable state, which shows why real designs avoid it.

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Power onOne LED lit, random which one
Set pressed and releasedRed stays on
Reset pressed and releasedGreen stays on
Both pressedBoth LEDs on
Both released togetherUnpredictable result

If it does not work

Both LEDs always off

Check pin 14 and pin 7 and the LED direction.

Latch does not hold

Check the cross wires pin 3 to 5 and pin 6 to 2.

Buttons do nothing

Check the pull-ups and that buttons go to GND.

LEDs dim

Check 330 ohm resistors and a good 5 V supply.

Random flips

A floating input, tie unused pins to GND.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the build a latch from NAND gates?

74HC00 quad NAND gate, Tactile push button 6 mm × 2, LED 5 mm red, LED 5 mm green, Resistor 10 kΩ × 2, Resistor 330 Ω × 2, Micro USB breakout board, 5 V 2 A USB adapter, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).

How long does the build a latch from NAND gates take to build?

About 100 minutes for a beginner maker, in 8 steps.

How do I know the build a latch from NAND gates works?

Power on: One LED lit, random which one. Set pressed and released: Red stays on. Reset pressed and released: Green stays on.

Both LEDs always off: what should I check?

Check pin 14 and pin 7 and the LED direction.

Latch does not hold: what should I check?

Check the cross wires pin 3 to 5 and pin 6 to 2.

Buttons do nothing: what should I check?

Check the pull-ups and that buttons go to GND.

LEDs dim: what should I check?

Check 330 ohm resistors and a good 5 V supply.