NAND latch
Two cross-coupled 74HC00 gates hold one bit, and a slide switch sets and resets it. There is no microcontroller in it: the simulator solves the 8 parts as a circuit, so it runs the moment you press Run, and nothing needs compiling.
Teaching? Assign it to your class in one click.
Intermediate About 20 minutes to build and run. Runs in your browser. Free, and no account needed.
Build it as the Logic Lab Kit: the parts in numbered bags and a booklet that checks every step. Retails for about $8.60, free on Mokxi.
What you'll learn
- How two NAND gates make a latch
- Cross-coupled feedback as one bit of memory
- Active-low inputs and pull-up resistors
- Set and reset states
- Switch debouncing with a latch
- Difficulty: Intermediate
- Time: About 20 minutes
- Parts: 10
How it works
Two NAND gates from a 74HC00 are cross-coupled: each gate's output feeds one input of the other. Together they hold one bit. Each gate has an LED on its output, so you can see which side is high.
Both control inputs are active low. They sit at 5 V through 10k pull-up resistors. The slide switch's middle contact is grounded, so it pulls one input low. That gate's output goes high, and the other gate goes low.
Flip the switch and the pair swaps over. A real switch lets go of one contact before touching the other, and in that gap the latch keeps its last state. That is memory. It also cleans up switch bounce.
Parts list
10 parts, plus the jumper wires. They retail for about $5.95; on Mokxi they're free.
- 1 × Full-size breadboard
- 1 × Power, 5 V
- 1 × Slide switchIn Logic Lab Kit, Spaceship Panel Kit.
- 1 × 74HC00 quad NANDIn Logic Lab Kit.
- 2 × Resistor, 10k ΩIn Starter Kit, Claw Machine Kit, Halloween Prop Kit.
- 2 × Resistor, 220 ΩIn Starter Kit, Claw Machine Kit, Halloween Prop Kit.
- 1 × LED, greenIn Starter Kit, Halloween Prop Kit, Logic Lab Kit.
- 1 × LED, redIn Starter Kit, Halloween Prop Kit, Logic Lab Kit.
Wiring table
Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.
| Part and pin | Connects to |
|---|---|
| 74HC00 quad NAND pin VCC | 5 V |
| Resistor, 10k Ω (1) pin 2 | 5 V |
| Resistor, 10k Ω (2) pin 2 | 5 V |
| Slide switch pin 2 | Ground |
| 74HC00 quad NAND pin GND | Ground |
| LED, green pin C | Ground |
| LED, red pin C | Ground |
| 74HC00 quad NAND pin 1A | Slide switch pin 1 |
| Resistor, 10k Ω (1) pin 1 | Slide switch pin 1 |
| 74HC00 quad NAND pin 2A | Slide switch pin 3 |
| Resistor, 10k Ω (2) pin 1 | Slide switch pin 3 |
| 74HC00 quad NAND pin 2Y | 74HC00 quad NAND pin 1B |
| Resistor, 220 Ω (2) pin 1 | 74HC00 quad NAND pin 1B |
| 74HC00 quad NAND pin 2B | 74HC00 quad NAND pin 1Y |
| Resistor, 220 Ω (1) pin 1 | 74HC00 quad NAND pin 1Y |
| LED, green pin A | Resistor, 220 Ω (1) pin 2 |
| LED, red pin A | Resistor, 220 Ω (2) pin 2 |
The notes that come with it
There is no microcontroller in this one, so nothing is compiled: the simulator solves the circuit itself. The file in the editor is the notes that come with it.
// An SR latch: two NAND gates that hold each other's answer.
//
// Q = NAND(set, Qbar)
// Qbar = NAND(reset, Q )
//
// Both inputs are active low and sit at 5 V through their pull-ups. The
// slide switch's pole is grounded, so it always holds one input down: that
// gate's output goes high, and the other gate (seeing a high on both inputs)
// goes low and feeds that back. Flip the switch and the pair swaps over.
//
// The switch here moves in one step, so Q simply follows it. The memory lives
// in the moment a real switch spends between its contacts: it lets go of one
// before it touches the other, both inputs are high for those milliseconds,
// and each gate holds the other one where it was. That is one bit of memory,
// and it is the same cell that is inside a static RAM.
//
// It is also the standard cure for switch bounce. A mechanical contact chatters
// for a few milliseconds when it closes; the latch flips on the first edge and
// then ignores every one after it, because the input it is bouncing on is no
// longer the one deciding anything.
Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- Both LEDs look the same or neither follows the switch This project
Check the cross-coupling: each gate's output must go to an input of the other gate. - An input floats and the LEDs flicker This project
Each switch side needs its 10k pull-up to 5 V. Without it the input has no defined level. - The input reads random values in one position. Slide switch
A switch only connects or disconnects. Add a pull-up or pull-down resistor, or use INPUT_PULLUP, so the pin has a defined level when the switch is open. - The load never turns on when the switch is flipped. Slide switch
Use the center (common) leg and one outer leg. The unused outer leg goes nowhere. Check that the switch is in series with the load. - The outputs do not follow the inputs. 74HC00 quad NAND
Power pin 14 (VCC) with 2 to 6 V and pin 7 to ground. Add a 0.1 uF capacitor close to the chip. - Unused inputs are floating and the output is erratic. 74HC00 quad NAND
Tie all unused inputs to VCC or ground. A floating CMOS input picks up noise and can waste current. - The LED is dim, burns out, or the pin reads wrong because the resistor value is off. Resistor
Read the color bands again. A 220 ohm to 330 ohm resistor suits a typical LED on 5 V. 10k is a common pull-up or pull-down value. Check with a multimeter if unsure. - A pull-up or pull-down resistor is missing, so the input floats and reads random values. Resistor
Tie the input to 5 V or ground through about 10k. Or use INPUT_PULLUP and wire the switch to ground.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.