Build a latch from NAND gates
Build it step by step
0 of 8 donePlace the chip
Straddle the breadboard gap, notch to the left.
Wire power
Pin 14 to 5V, pin 7 to GND.
Tie unused inputs
Pins 9, 10, 12 and 13 to GND.
Wire the latch
Pin 3 to pin 5, pin 6 to pin 2.
Add the buttons
Pin 1 and pin 4 each with a 10 kilohm pull-up and a button to GND.
Add the LEDs
Pin 3 and pin 6 each through 330 ohm to an LED to GND.
Press set
The red LED lights and stays on after release.
Press reset
The green LED lights and stays on after release.
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
- Integrated CircuitsBuy
- SwitchesBuy
- SemiconductorsBuyLED 5 mm red × 1
- SemiconductorsBuyLED 5 mm green × 1
- PassivesBuyResistor 10 kΩ × 2
- PassivesBuyResistor 330 Ω × 2
- ConnectorsBuy
- PowerBuy
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Chip pin 14 (VCC) | 5V from the USB breakout | Power |
| Chip pin 7 (GND) | GND from the USB breakout | Ground |
| Set button | Chip pin 1 with a 10 kilohm pull-up to 5V, button to GND | Active-low set input |
| Reset button | Chip pin 4 with a 10 kilohm pull-up to 5V, button to GND | Active-low reset input |
| Gate A output pin 3 (Q) | Gate B input pin 5, and a red LED through 330 ohm to GND | Output Q |
| Gate B output pin 6 (Q-bar) | Gate A input pin 2, and a green LED through 330 ohm to GND | Output Q-bar |
| Unused gate inputs | Pins 9, 10, 12 and 13 to GND | Never 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.
| Check | Expected |
|---|---|
| Power on | One LED lit, random which one |
| Set pressed and released | Red stays on |
| Reset pressed and released | Green stays on |
| Both pressed | Both LEDs on |
| Both released together | Unpredictable 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 →
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.
