Built-in project · no microcontroller

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.

The circuit runs here once the page has loaded.

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.

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
Resistor, 10k Ω pin 15 V
8-way DIP switch pin 8B5 V
8-way DIP switch pin 7B5 V
8-way DIP switch pin 6B5 V
8-way DIP switch pin 5B5 V
8-way DIP switch pin 4B5 V
8-way DIP switch pin 3B5 V
8-way DIP switch pin 2B5 V
8-way DIP switch pin 1B5 V
74HC165 input shift register pin VCC5 V
Pushbutton pin 2aGround
8-resistor network pin CGround
74HC165 input shift register pin GNDGround
74HC165 input shift register pin DSGround
74HC165 input shift register pin CEGround
LED, green pin CGround
74HC165 input shift register pin CPClock pin OUT
Resistor, 10k Ω pin 2Pushbutton pin 1a
74HC165 input shift register pin PLPushbutton pin 1b
8-resistor network pin 88-way DIP switch pin 1A
74HC165 input shift register pin D08-way DIP switch pin 1A
8-resistor network pin 78-way DIP switch pin 2A
74HC165 input shift register pin D18-way DIP switch pin 2A
8-resistor network pin 68-way DIP switch pin 3A
74HC165 input shift register pin D28-way DIP switch pin 3A
8-resistor network pin 58-way DIP switch pin 4A
74HC165 input shift register pin D38-way DIP switch pin 4A
8-resistor network pin 48-way DIP switch pin 5A
74HC165 input shift register pin D48-way DIP switch pin 5A
8-resistor network pin 38-way DIP switch pin 6A
74HC165 input shift register pin D58-way DIP switch pin 6A
8-resistor network pin 28-way DIP switch pin 7A
74HC165 input shift register pin D68-way DIP switch pin 7A
8-resistor network pin 18-way DIP switch pin 8A
74HC165 input shift register pin D78-way DIP switch pin 8A
Resistor, 330 Ω pin 174HC165 input shift register pin Q7
LED, green pin AResistor, 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.

sketch.ino
// 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.