Switch shifter
A 74HC165 loads an 8-way DIP switch at the press of a button and clocks the byte out one bit a second onto an LED. 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 25 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 a parallel-in, serial-out shift register works
- Turning eight switches into one wire of data
- What load, clock and serial output do on a 74HC165
- Reading a byte as bits from most significant to least
- Difficulty: Intermediate
- Time: About 25 minutes
- Parts: 10
How it works
An 8-way DIP switch sets a byte: switch 1 is bit 0, switch 8 is bit 7, and a switch that is on is a 1. The 74HC165 can read all eight at once and then send them out one at a time on a single wire.
Hold the LOAD button and the chip's PL pin goes low. The chip copies all eight switches into its register. The last bit, bit 7, shows on the green LED right away: lit for a 1, dark for a 0.
Let go, and each rising edge of the 1 Hz clock shifts the register one place. Bit 6, then bit 5, down to bit 0 come out on the LED, one per second. After that the LED stays dark, because the serial input DS is tied to ground.
Parts list
10 parts, plus the jumper wires. They retail for about $6.25; on Mokxi they're free.
- 1 × Full-size breadboard
- 1 × Power, 5 V
- 1 × ClockIn Logic Lab Kit.
- 1 × PushbuttonIn Starter Kit, Christmas Lights Kit, Logic Lab Kit.
- 1 × Resistor, 10k ΩIn Starter Kit, Claw Machine Kit, Halloween Prop Kit.
- 1 × 8-way DIP switchIn Logic Lab Kit.
- 1 × 8-resistor networkIn Logic Lab Kit, Spaceship Panel Kit.
- 1 × 74HC165 input shift registerIn Logic Lab Kit.
- 1 × Resistor, 330 ΩIn Starter Kit, Claw Machine Kit, Halloween Prop Kit.
- 1 × LED, greenIn 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 |
|---|---|
| Resistor, 10k Ω pin 1 | 5 V |
| 8-way DIP switch pin 8B | 5 V |
| 8-way DIP switch pin 7B | 5 V |
| 8-way DIP switch pin 6B | 5 V |
| 8-way DIP switch pin 5B | 5 V |
| 8-way DIP switch pin 4B | 5 V |
| 8-way DIP switch pin 3B | 5 V |
| 8-way DIP switch pin 2B | 5 V |
| 8-way DIP switch pin 1B | 5 V |
| 74HC165 input shift register pin VCC | 5 V |
| Pushbutton pin 2a | Ground |
| 8-resistor network pin C | Ground |
| 74HC165 input shift register pin GND | Ground |
| 74HC165 input shift register pin DS | Ground |
| 74HC165 input shift register pin CE | Ground |
| LED, green pin C | Ground |
| 74HC165 input shift register pin CP | Clock pin OUT |
| Resistor, 10k Ω pin 2 | Pushbutton pin 1a |
| 74HC165 input shift register pin PL | Pushbutton pin 1b |
| 8-resistor network pin 8 | 8-way DIP switch pin 1A |
| 74HC165 input shift register pin D0 | 8-way DIP switch pin 1A |
| 8-resistor network pin 7 | 8-way DIP switch pin 2A |
| 74HC165 input shift register pin D1 | 8-way DIP switch pin 2A |
| 8-resistor network pin 6 | 8-way DIP switch pin 3A |
| 74HC165 input shift register pin D2 | 8-way DIP switch pin 3A |
| 8-resistor network pin 5 | 8-way DIP switch pin 4A |
| 74HC165 input shift register pin D3 | 8-way DIP switch pin 4A |
| 8-resistor network pin 4 | 8-way DIP switch pin 5A |
| 74HC165 input shift register pin D4 | 8-way DIP switch pin 5A |
| 8-resistor network pin 3 | 8-way DIP switch pin 6A |
| 74HC165 input shift register pin D5 | 8-way DIP switch pin 6A |
| 8-resistor network pin 2 | 8-way DIP switch pin 7A |
| 74HC165 input shift register pin D6 | 8-way DIP switch pin 7A |
| 8-resistor network pin 1 | 8-way DIP switch pin 8A |
| 74HC165 input shift register pin D7 | 8-way DIP switch pin 8A |
| Resistor, 330 Ω pin 1 | 74HC165 input shift register pin Q7 |
| LED, green pin A | Resistor, 330 Ω 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 74HC165 reading eight switches, slowly enough to watch.
//
// The DIP switch is a byte: switch 1 is bit 0, switch 8 is bit 7, and a
// switch that is on (lever up) is a 1. It starts at 1011 0010.
//
// Press and hold LOAD: PL goes low and the 165 copies all eight switches into
// its register at once. Q7 shows bit 7 right away, so the LED lights for a
// 1 and stays dark for a 0.
//
// Let go, and every rising edge of the 1 Hz clock shifts the register one place
// towards Q7: bit 6, bit 5 ... bit 0 come out on the LED one second at a time,
// most significant first. Then zeros, because DS (the serial input at the far
// end) is tied to ground. Change a switch and press LOAD again.
//
// A microcontroller does exactly this, only fast: pulse PL low, then read Q7
// before each of eight clock pulses (not shiftIn(), which clocks first and
// loses bit 7). Three pins for eight switches, and a second 165 chained off
// Q7 would make it sixteen.
Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- The LED stays dark. This project
Press and hold LOAD at least once. Until the chip loads, there is nothing to shift out. - The pattern is in the wrong order. This project
Check that switch 1 goes to D0 and switch 8 to D7. The first bit out is bit 7. - Changing a switch does nothing. This project
The chip only reads the switches when you press LOAD, so press it again. - 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. - 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.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.