Bench NotesUno handbook

More Outputs with a 74HC595 Shift Register

Drive eight LEDs from three Uno pins with a 74HC595 and shiftOut().

Intermediate74HC595LEDResistor

Overview

The 74HC595 takes eight bits one at a time on a data pin, clocked by a second pin, then copies them to its eight outputs when a third (latch) pin rises. Three Uno pins give eight outputs, and chips can be chained for more.

You will need

  • Arduino Uno R3
  • 74HC595 (DIP-16)
  • 8 LEDs
  • 8 × 1 kΩ resistors
  • 0.1 µF ceramic capacitor
  • Breadboard and jumper wires

Wiring

Uno pinConnects toNotes
1174HC595 pin 14 (DS, serial data)
1274HC595 pin 11 (SHCP, shift clock)
874HC595 pin 12 (STCP, latch)
5VPin 16 (VCC) and pin 10 (MR, active-low reset)Keep MR HIGH
GNDPin 8 (GND) and pin 13 (OE, active-low output enable)Keep OE LOW
—Q0–Q7 (pins 15, 1–7) → 1 kΩ → LED anode; LED cathodes to GND
—0.1 µF capacitor between pins 16 and 8Close to the chip
Wiring for More Outputs with a 74HC595 Shift RegisterArduino Uno D11 to 74HC595 14 DS (data); Arduino Uno D12 to 74HC595 11 SHCP (clock); Arduino Uno D8 to 74HC595 12 STCP (latch); Arduino Uno 5V to 74HC595 16 VCC; Arduino Uno 5V to 74HC595 10 MR (reset, keep HIGH); Arduino Uno GND to 74HC595 8 GND; Arduino Uno GND to 74HC595 13 OE (enable, keep LOW).Connections (each line is one wire)Arduino Uno74HC595D1114 DS (data)D1211 SHCP (clock)D812 STCP (latch)5V16 VCC5V 10 MR (reset, keep HIGH)GND8 GNDGND 13 OE (enable, keep LOW)
Original wiring diagram. Each line is one jumper wire; boxes on a line are series resistors.

Current

The 74HC595's outputs are meant for a few milliamps each and about 70 mA for the whole chip. Use 1 kΩ resistors (about 3 mA per LED) so all eight can be on at once. For a seven-segment display, put the resistors between the outputs and the segments, just like with direct pins.

The sketch

shift_register_leds.ino
const int DATA_PIN = 11;   // 74HC595 DS
const int CLOCK_PIN = 12;  // 74HC595 SHCP
const int LATCH_PIN = 8;   // 74HC595 STCP

void writeShiftRegister(byte value) {
  digitalWrite(LATCH_PIN, LOW);
  shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, value);
  digitalWrite(LATCH_PIN, HIGH);    // outputs update on this rising edge
}

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

void loop() {
  // One LED at a time, Q0 to Q7
  for (int bit = 0; bit < 8; bit++) {
    writeShiftRegister((byte)(1 << bit));
    delay(150);
  }
  // Count 0 to 255 in binary
  for (int value = 0; value < 256; value++) {
    writeShiftRegister((byte)value);
    delay(60);
  }
}

How the code works

With MSBFIRST the first bit sent ends up on Q7, so bit 0 of the value appears on Q0. Holding the latch LOW while shifting keeps the LEDs from flickering through intermediate patterns. To chain a second chip, connect Q7' (pin 9) of the first to DS of the second, share clock and latch, and call shiftOut() twice.

What you should observe

  • A single light runs from Q0 to Q7, then the LEDs count in binary.
  • Nothing lights: check OE is at GND and MR is at 5V. Random patterns at power-up are normal until the first write.