Learn
Driving a 74HC595 Shift Register on a Raspberry Pi 4B
Control 8 LED outputs from just 3 GPIO pins using a 74HC595 shift register — bit-bang a byte in serially, then latch it to the real Q0-Q7 outputs all at once, the classic "control more outputs than you have pins" trick behind multi-digit displays and LED matrices.
Note: the 74HC595 Shift Register is a VIP-tier component in the simulator — you’ll need a VIP plan to use it there.
Try this directly in the free Raspberry Pi 4B simulator — no hardware or signup required. New to the GPIO header? Start with the interactive pinout guide.
What you’ll need
- Raspberry Pi 4B
- 74HC595 Shift Register
- 8x LED
- 8x Resistor (220Ω recommended)
Step by step
- Drag Raspberry Pi 4B onto the Canvas.
- Drag a 74HC595 Shift Register onto the Canvas — a real 16-pin DIP chip. Like the other DIP-style components in this simulator (MCP3008, A4988 Driver), it straddles the breadboard's own center gap when mounted, the same way a real chip this size actually sits.
Hover over its pins to see all 16 labels. One row reads Q1-Q7 then GND; the other reads VCC, Q0, DS, OE, STCP, SHCP, MR, and Q7' — this mirrors the chip's real physical pin layout (pin 9 sits directly opposite pin 8, pin 16 opposite pin 1), not just a flat numbered list.
- Power and enable the chip — this is a bare logic chip with no onboard pull resistors, so every control pin needs an explicit wire, not just VCC/GND:
| 74HC595 pin | Wire to |
|---|---|
| VCC | a Pi 5V pin |
| GND | a Pi GND pin |
| OE (Output Enable, active-LOW) | a Pi GND pin — LOW enables the Q0-Q7 outputs; left floating, they stay disabled |
| MR (Master Reset, active-LOW) | a Pi 5V pin — HIGH means "not in reset"; tie it explicitly rather than relying on it floating |
- Wire the 3 data/clock lines to 3 separate Pi GPIO pins: DS (serial data in), SHCP (shift clock), and STCP (storage/latch clock).
- Wire Q0 through Q7 to 8 LEDs, each through its own resistor, so all 8 outputs are visible at once.
- Go to the Code tab and write a script that bit-bangs a byte in, most-significant-bit first:
import RPi.GPIO as GPIO DS = 11 # physical pin wired to DSSHCP = 13 # physical pin wired to SHCPSTCP = 15 # physical pin wired to STCP GPIO.setmode(GPIO.BOARD)GPIO.setup(DS, GPIO.OUT)GPIO.setup(SHCP, GPIO.OUT)GPIO.setup(STCP, GPIO.OUT) def shift_out_msb_first(byte_value): for i in range(7, -1, -1): bit = (byte_value >> i) & 1 GPIO.output(DS, bool(bit)) GPIO.output(SHCP, True) # rising edge shifts the bit in GPIO.output(SHCP, False) GPIO.output(STCP, True) # rising edge latches shift -> Q0-Q7 GPIO.output(STCP, False) shift_out_msb_first(b10000001) # lights Q7 and Q0 onlyEach SHCP rising edge shifts exactly one bit into the chip's own internal 8-bit shift register — this alone changes nothing visible yet. STCP's own rising edge is what copies that whole register into the real Q0-Q7 outputs in one instant, which is why the LEDs update all together the moment STCP pulses, never one at a time while SHCP is still clocking bits in. The MSB (bit 7) sent first ends up on Q7; the LSB (bit 0) sent last ends up on Q0 — the same shiftOut(dataPin, clockPin, MSBFIRST, value) convention Arduino uses.
- Click Start.
The Q7 and Q0 LEDs light; the other six stay off — exactly matching 0b10000001 (bit 7 and bit 0 set, everything in between clear).
- Try a running-lights follow-up, shifting a single lit bit across all 8 outputs:
import asyncioimport RPi.GPIO as GPIO DS = 11SHCP = 13STCP = 15 GPIO.setmode(GPIO.BOARD)GPIO.setup(DS, GPIO.OUT)GPIO.setup(SHCP, GPIO.OUT)GPIO.setup(STCP, GPIO.OUT) def shift_out_msb_first(byte_value): for i in range(7, -1, -1): GPIO.output(DS, bool((byte_value >> i) & 1)) GPIO.output(SHCP, True) GPIO.output(SHCP, False) GPIO.output(STCP, True) GPIO.output(STCP, False) position = 0while not should_stop(): shift_out_msb_first(1 << position) position = (position + 1) % 8 await asyncio.sleep(0.15)One LED visibly walks from Q0 to Q7 and loops back — each loop iteration is a full shift-then-latch sequence, so the LEDs only ever show a fully-settled pattern, never a mid-shift flicker.
- Bonus, optional: to control 16 outputs from the same 3 Pi pins, wire this chip's Q7' (serial out) into a second 74HC595's DS pin, and wire SHCP/STCP to both chips in parallel (a shared clock line, the real daisy-chain wiring). The same shiftOut sequence, just sent twice as long (16 bits instead of 8), now reaches every output across both chips — a good pairing project once you've also tried the 7-Segment Display tutorial, since a shift register is exactly how a real multi-digit display is normally driven from only 3 pins.
What “working correctly” looks like
- A single shiftOut-style call lights exactly the LEDs matching each set bit — Q7 for bit 7 (the first bit sent), down to Q0 for bit 0 (the last bit sent) — and nothing else.
- The LEDs only change together, in one instant, when STCP pulses — not one at a time as each bit shifts in. Skipping the STCP pulse means the LEDs simply never update, no matter how much SHCP is clocked.
- OE tied LOW is required for Q0-Q7 to output anything at all — leaving it unwired (or HIGH) keeps every output in genuine high-impedance, matching real hardware, regardless of what's actually stored inside the chip.
- Pulling MR LOW at any point immediately clears the chip's internal shift register (not the visible LEDs) — the LEDs themselves only go dark once STCP is pulsed again afterward.
- The whole chip resets to a blank/idle state on Stop, and needs at least one fresh shift-and-latch sequence again after the next Start.
If something’s wrong
- Nothing lights up at all → confirm OE is wired to GND (or otherwise driven LOW) — a floating or HIGH OE keeps every output in real high-impedance, regardless of what's been shifted in.
- LEDs never change, even though the script runs with no errors → confirm STCP is being pulsed HIGH-then-LOW AFTER shifting all 8 bits in — SHCP alone only fills the chip's internal shift register, it never reaches the visible Q0-Q7 outputs until STCP latches it.
- The lit pattern looks reversed or shifted by one bit → double-check the bits are sent most-significant-bit first (bit 7, then 6, ... down to bit 0) — Q7 corresponds to the byte's bit 7, Q0 to bit 0.
- Only some LEDs respond → recheck each LED's own resistor and wiring, and confirm Q0-Q7 are wired to the correct 8 pins — GND and VCC sit on the opposite row from most of the Q outputs on this chip's real pinout, easy to mix up.
- Want more than 8 outputs from the same 3 Pi pins? Chain this chip's Q7' into a second 74HC595's DS pin and wire SHCP/STCP to both in parallel — see the bonus step above.