Built-in project · no microcontroller

Flip-flop lab

A clock, two D flip-flops and a multiplexer on three LEDs: a toggle, a one-tick delay, and set and reset on buttons. There is no microcontroller in it: the simulator solves the 16 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.

Beginner About 15 minutes to build and run. Runs in your browser. Free, and no account needed.

The parts retail for about $5.90. On Mokxi they're free.

Flip-flop lablive0.000 s 0.00x
Hold the button
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

What you'll learn

  • Toggling with a flip-flop fed back on itself
  • Delaying a signal by one clock tick
  • Asynchronous set and reset
  • Choosing between signals with a multiplexer
  • Dividing a clock frequency by two
  • Difficulty: Beginner
  • Time: About 15 minutes
  • Parts: 18

How it works

A clock ticks once a second into two D flip-flops. The first has its inverted output wired back to its own D input, so it flips on every tick. The green LED shows that, blinking at half the clock speed.

The second flip-flop takes its D from the first one's output. It copies the green state one tick later, and the yellow LED shows it. A multiplexer feeds the blue LED with the green signal, or the yellow one while you hold button C.

Hold button A to set the second flip-flop (yellow on) and button B to reset it (yellow off), whatever the clock is doing.

Parts list

18 parts, plus the jumper wires. They retail for about $5.90; on Mokxi they're free.

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 pinConnects to
Pushbutton (1) pin 2a5 V
Pushbutton (2) pin 2a5 V
Pushbutton (3) pin 2a5 V
Resistor, 10k Ω (1) pin 1Ground
Resistor, 10k Ω (2) pin 1Ground
Resistor, 10k Ω (3) pin 1Ground
LED, green pin CGround
LED, yellow pin CGround
LED, blue pin CGround
Resistor, 10k Ω (1) pin 2Pushbutton (1) pin 1a
D flip-flop with set and reset pin SPushbutton (1) pin 1a
Resistor, 10k Ω (2) pin 2Pushbutton (2) pin 1a
D flip-flop with set and reset pin RPushbutton (2) pin 1a
Resistor, 10k Ω (3) pin 2Pushbutton (3) pin 1a
2-to-1 multiplexer pin SELPushbutton (3) pin 1a
D flip-flop pin CLKClock pin OUT
D flip-flop with set and reset pin CLKClock pin OUT
D flip-flop pin QND flip-flop pin D
D flip-flop with set and reset pin DD flip-flop pin Q
2-to-1 multiplexer pin AD flip-flop pin Q
Resistor, 220 Ω (1) pin 1D flip-flop pin Q
2-to-1 multiplexer pin BD flip-flop with set and reset pin Q
Resistor, 220 Ω (2) pin 1D flip-flop with set and reset pin Q
Resistor, 220 Ω (3) pin 12-to-1 multiplexer pin Y
LED, green pin AResistor, 220 Ω (1) pin 2
LED, yellow pin AResistor, 220 Ω (2) pin 2
LED, blue pin AResistor, 220 Ω (3) 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.

sketch.ino
// A flip-flop lab: memory, a shift, and a switch for logic.
//
// The clock ticks once a second.
//
//   Green LED   the first flip-flop. Q-bar goes back to D, so it flips on
//               every tick and blinks at half the clock.
//   Yellow LED  the second flip-flop. Its D is the first one's Q, so it
//               shows the green LED one tick late.
//   Blue LED    the multiplexer: the green LED's signal, or the yellow
//               one's while you hold button C.
//
// Hold button A to set the second flip-flop (yellow on) and button B to reset
// it (yellow off), whatever the clock is doing. Let go and the next tick
// takes over again.
//
// These are ideal parts: no supply pins and a 10 ns delay. The 74HC74 in the
// binary counter is the real chip, with a supply you have to wire.

Troubleshooting

The usual mistakes with this circuit, and the fix for each.

  • Buttons do nothing This project
    Each button needs its 10k pulldown to ground. Without it the input floats when the button is not pressed.
  • Yellow does not follow green This project
    The second flip-flop's D must connect to the first one's Q, and both need the same clock.
  • The input reads random HIGH and LOW when the button is not pressed. Pushbutton
    A floating pin picks up noise. Add a 10 k pull-down or pull-up resistor, or use INPUT_PULLUP and wire the button between the pin and GND. Then pressed reads LOW.
  • The button seems always pressed, or never changes. Pushbutton
    A 4-leg tactile switch has legs joined in pairs. Place it across the breadboard center gap so the pairs sit on different rows. Wired along one side, the legs are already connected.
  • 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.
  • The circuit does not behave as expected at the set frequency. Clock
    Pick a frequency slow enough to watch, such as 1 Hz, when learning. Fast clocks look like steady signals. Make sure the clock output and your circuit share a ground.
  • A counter or flip-flop skips steps. Clock
    Check that the clock edge matches the chip, rising or falling. Slow, clean edges are best. Do not connect a mechanical switch as a clock without debouncing it.

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.