← All projects
Basics Beginner

The 74HC595 Shift Register: 8 LEDs From Three Pins

Running out of pins? A chip that costs pennies turns three GPIOs into eight outputs, and two chained chips into sixteen. We look at how shiftOut(), SHCP and STCP work, what MR and OE are for, and why eight LEDs at 20 mA burn the register.

Difficulty
Beginner
Time
45 min
Category
Basics
Updated

About the project

The 74HC595 is a serial-in, parallel-out register: the microcontroller sends a byte one bit at a time, and the chip sets all eight bits at once on pins Q0–Q7. It drives LED bar graphs, seven-segment displays and relays when free GPIOs run short — especially on an Arduino Uno or an ESP32-C3.

What you need

  • ESP32 DevKit (or an Arduino)
  • A 74HC595 chip (DIP-16)
  • A 10-segment LED bar graph or 8 LEDs
  • 8 resistors, 330–470 Ω
  • A breadboard

Pins

The notch on the package is on the left. Bottom row, pins 1–8: Q1–Q7, GND. Top row, right to left, 9–16: Q7', MR, SHCP, STCP, OE, DS, Q0, VCC.

74HC595 Purpose ESP32
VCC (16) 2–6 V supply 3V3
GND (8) ground GND
DS (14) data GPIO23
SHCP (11) shift clock GPIO18
STCP (12) latch GPIO5
MR (10) reset, active LOW 3V3
OE (13) output enable, active LOW GND
Q0–Q7 outputs to the LEDs through resistors

How it works

Inside there are two 8-bit registers:

  1. The shift register. On every rising edge of SHCP the bits move one place and the first one takes the level on DS.
  2. The output register (the latch). On a rising edge of STCP the whole shift register is copied to Q0–Q7 at once.

So while you clock in 8 bits, the LEDs never flash through intermediate states — everything changes at the STCP pulse. shiftOut(data, clock, MSBFIRST, value) does 8 rounds of "set DS → pulse SHCP".

MR and OE must not float: a floating MR clears the register at random, and OE switches the outputs off. The simulator warns about both. Instead of tying OE to GND you can feed it PWM — then one pin sets the brightness of all the LEDs (remember that OE is inverted).

Current is the main trap

A 74HC595 output is not a power driver: up to 35 mA per pin and only 70 mA for the whole chip through VCC and GND. Eight LEDs at 20 mA is 160 mA, and the register overheats. Use 330–470 Ω resistors (3–8 mA per LED is plenty for an indicator), and a ULN2803 or TPIC6B595 for real loads.

Code

// 8 LEDs from three pins: a 74HC595 shift register
const int DATA_PIN = 23;    // DS (14)
const int CLOCK_PIN = 18;   // SHCP (11)
const int LATCH_PIN = 5;    // STCP (12)

void writeLeds(byte pattern) {
  digitalWrite(LATCH_PIN, LOW);
  shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, pattern);
  digitalWrite(LATCH_PIN, HIGH);   // the outputs change here, all at once
}

void setup() {
  pinMode(DATA_PIN, OUTPUT);
  pinMode(CLOCK_PIN, OUTPUT);
  pinMode(LATCH_PIN, OUTPUT);
}

void loop() {
  // a light running back and forth
  for (int i = 0; i < 8; i++) { writeLeds(1 << i); delay(80); }
  for (int i = 6; i > 0; i--) { writeLeds(1 << i); delay(80); }
}

Chaining registers

Q7' (pin 9) is the bit that falls out of the shift register. Connect it to DS of a second 74HC595, and tie the SHCP and STCP pins of both chips together. Now two shiftOut() calls in a row send 16 bits: the first byte moves on into the second chip, the second stays in the first. Chains of 3, 4 or more registers work the same way — still with three microcontroller pins.

Ideas

  • A binary counter: writeLeds(counter++) shows what a number looks like in bits.
  • A level meter: writeLeds((1 << n) - 1) lights n segments — for example for a potentiometer level.
  • Faster than shiftOut(): on an ESP32 connect DS to MOSI and SHCP to SCK, and send the byte with SPI.transfer().