Projects / Set-reset latch from two gates

Set-reset latch from two gates

Beginner1 hGuided buildReviewed

Build it step by step

0 of 8 done
  1. Wire the power

    Pins 14 and 7, unused inputs to ground.

  2. 74HC02

    Cross-link the gates

    Pin 1 to pin 6, pin 4 to pin 3.

  3. Wire the inputs

    Buttons with 10k pull-downs on pins 2 and 5.

  4. 8.0 mA

    Wire the LEDs

    Pins 1 and 4 through 1 kilohm to LEDs.

  5. 8.0 mA

    Press Set

    The Q LED lights and stays on.

  6. 8.0 mA

    Press Reset

    The Q-bar LED lights.

  7. Release both

    The state is held.

  8. Try both buttons

    Note the outputs and the final state.

In short

How do you build a set-reset latch from two gates?

Two NOR gates cross-linked make a latch that remembers a button press, a first look at memory. You need 74HC02 quad NOR gate, Tactile push button 6 mm × 2, Resistor 10 kΩ × 2, LED 5 mm red × 2, Resistor 1 kΩ × 2, 5 V 2 A USB adapter, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points. It takes 8 steps and about 60 minutes.

Level
Beginner
Time
About 60 min
Parts
8

Parts list

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

Wiring

FromToWhy
5 V adapter positiveRed railSupply
5 V adapter negativeBlue railGround
74HC02 pin 14 (VCC) and pin 7 (GND)Red rail and blue railPower
Unused inputs, pins 8, 9, 11 and 12Blue railCMOS inputs must never float
Reset buttonRed rail to pin 2 (gate 1 input), with 10k from pin 2 to GNDR input
Set buttonRed rail to pin 5 (gate 2 input), with 10k from pin 5 to GNDS input
Pin 4 (gate 2 output, Q-bar)Pin 3 (gate 1 second input)Cross link
Pin 1 (gate 1 output, Q)Pin 6 (gate 2 second input)Cross link
Pin 1 (Q)1 kilohm to a red LED to GNDShows Q
Pin 4 (Q-bar)1 kilohm to a second red LED to GNDShows Q-bar

Code

Memory in a computer begins with a tiny circuit like this one: two gates whose outputs feed each other's inputs. A NOR gate gives a one only when both its inputs are zero. Connect two NOR gates so that each one's output goes to the other's input, and the pair has two stable states: either the first output is one and the second is zero, or the other way round. Pressing Set forces the first gate's output high, pressing Reset forces it low, and with both buttons released the cross connection holds whichever state was last, so the latch remembers which button was pressed last. That is one bit of memory. You can see this with the two LEDs: they always show opposite states, and neither changes when you release a button. The one combination to avoid is pressing both buttons together, which drives both outputs low, and when you release them the circuit may end up either way depending on tiny differences between the gates. A real design avoids that input, and the improved flip-flops used in counters and registers are built from latches like this one. All the unused inputs on the chip are tied to ground, because unconnected CMOS inputs pick up noise and make the chip draw extra current. The chip is a 74HC02, which must be run at no more than 6 volts, so use a 5 volt supply.

Build notes (no code needed for this build)

74HC02 pins: 1 Y1 (out), 2 A1, 3 B1, 4 Y2 (out), 5 A2, 6 B2, 7 GND, 8 A3, 9 B3, 10 Y3 (out), 11 A4, 12 B4, 13 Y4 (out), 14 VCC.
A NOR gate outputs 1 only when both inputs are 0.

Cross-coupled latch:   Q = NOR(R, Q-bar)    Q-bar = NOR(S, Q)
  Gate 1: output pin 1 = Q, inputs pin 2 = R and pin 3 = Q-bar (from pin 4).
  Gate 2: output pin 4 = Q-bar, inputs pin 5 = S and pin 6 = Q (from pin 1).

Behaviour:
  S = 0, R = 0 : HOLD, keeps its last state (this is the memory)
  S = 1, R = 0 : SET, Q = 1 and Q-bar = 0
  S = 0, R = 1 : RESET, Q = 0 and Q-bar = 1
  S = 1, R = 1 : FORBIDDEN, both outputs go to 0 and then, when both buttons are released, the final state depends on which gate wins the race

Check: pressing Set lights the Q LED, and it stays lit after you release the button. Pressing Reset puts it out and lights the Q-bar LED.
On power up the latch starts in a random state, which is normal for this circuit.
The HC family has a 6 volt limit, so use 5 V and not a 9 V battery.
The LEDs use 1 kilohm because a CMOS output sinks only a few milliamps.

Test checklist

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

CheckExpected
Set pressed and releasedQ LED stays lit
Reset pressed and releasedQ-bar LED stays lit
Neither pressedLast state held
Both pressedBoth LEDs off
Power cycleRandom starting state

If it does not work

Both LEDs lit

Check the cross links and the pin numbers.

Latch does not hold

A button input is floating, check the pull-downs.

Chip hot

Check the supply is not above 6 V.

LEDs dim

Normal at 1 kilohm with a CMOS output.

Odd behaviour

Check unused inputs are tied to ground.

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

Ask Lark AI

Common questions

What parts do I need for the set-reset latch from two gates?

74HC02 quad NOR gate, Tactile push button 6 mm × 2, Resistor 10 kΩ × 2, LED 5 mm red × 2, Resistor 1 kΩ × 2, 5 V 2 A USB adapter, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points.

How long does the set-reset latch from two gates take to build?

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

How do I know the set-reset latch from two gates works?

Set pressed and released: Q LED stays lit. Reset pressed and released: Q-bar LED stays lit. Neither pressed: Last state held.

Both LEDs lit: what should I check?

Check the cross links and the pin numbers.

Latch does not hold: what should I check?

A button input is floating, check the pull-downs.

Chip hot: what should I check?

Check the supply is not above 6 V.

LEDs dim: what should I check?

Normal at 1 kilohm with a CMOS output.