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.
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.
- 1 × Full-size breadboard
- 1 × Power, 5 V
- 3 × PushbuttonIn Starter Kit, Christmas Lights Kit, Logic Lab Kit.
- 3 × Resistor, 10k ΩIn Starter Kit, Claw Machine Kit, Halloween Prop Kit.
- 1 × ClockIn Logic Lab Kit.
- 1 × D flip-flop
- 1 × D flip-flop with set and reset
- 1 × 2-to-1 multiplexer
- 3 × Resistor, 220 ΩIn Starter Kit, Claw Machine Kit, Halloween Prop Kit.
- 1 × LED, greenIn Starter Kit, Halloween Prop Kit, Logic Lab Kit.
- 1 × LED, yellowIn Starter Kit, Halloween Prop Kit, Logic Lab Kit.
- 1 × LED, blueIn 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 |
|---|---|
| Pushbutton (1) pin 2a | 5 V |
| Pushbutton (2) pin 2a | 5 V |
| Pushbutton (3) pin 2a | 5 V |
| Resistor, 10k Ω (1) pin 1 | Ground |
| Resistor, 10k Ω (2) pin 1 | Ground |
| Resistor, 10k Ω (3) pin 1 | Ground |
| LED, green pin C | Ground |
| LED, yellow pin C | Ground |
| LED, blue pin C | Ground |
| Resistor, 10k Ω (1) pin 2 | Pushbutton (1) pin 1a |
| D flip-flop with set and reset pin S | Pushbutton (1) pin 1a |
| Resistor, 10k Ω (2) pin 2 | Pushbutton (2) pin 1a |
| D flip-flop with set and reset pin R | Pushbutton (2) pin 1a |
| Resistor, 10k Ω (3) pin 2 | Pushbutton (3) pin 1a |
| 2-to-1 multiplexer pin SEL | Pushbutton (3) pin 1a |
| D flip-flop pin CLK | Clock pin OUT |
| D flip-flop with set and reset pin CLK | Clock pin OUT |
| D flip-flop pin QN | D flip-flop pin D |
| D flip-flop with set and reset pin D | D flip-flop pin Q |
| 2-to-1 multiplexer pin A | D flip-flop pin Q |
| Resistor, 220 Ω (1) pin 1 | D flip-flop pin Q |
| 2-to-1 multiplexer pin B | D flip-flop with set and reset pin Q |
| Resistor, 220 Ω (2) pin 1 | D flip-flop with set and reset pin Q |
| Resistor, 220 Ω (3) pin 1 | 2-to-1 multiplexer pin Y |
| LED, green pin A | Resistor, 220 Ω (1) pin 2 |
| LED, yellow pin A | Resistor, 220 Ω (2) pin 2 |
| LED, blue pin A | Resistor, 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.
// 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.