When the Nano runs out of pins, a ₹15 74HC595 adds eight outputs from three wires. It is how LED bar graphs, 7-segment displays and relay boards with many channels are usually driven.
Instead of the usual shiftOut() this guide uses the Nano’s hardware SPI — data on D11, clock on D13, latch on D10 — which is far faster and leaves the CPU free. The sketch runs a back-and-forth scanner across eight LEDs.
Wiring
| Arduino Nano | 74HC595 8-bit shift register (DIP-16) | Wire | Notes |
|---|---|---|---|
| — | Q0 | — | To 220 Ω → LED 1 → GND (not drawn) |
| — | Q1 | — | To 220 Ω → LED 2 → GND (not drawn) |
| — | Q2 | — | To 220 Ω → LED 3 → GND (not drawn) |
| — | Q3 | — | To 220 Ω → LED 4 → GND (not drawn) |
| — | Q4 | — | To 220 Ω → LED 5 → GND (not drawn) |
| — | Q5 | — | To 220 Ω → LED 6 → GND (not drawn) |
| — | Q6 | — | To 220 Ω → LED 7 → GND (not drawn) |
| — | Q7 | — | To 220 Ω → LED 8 → GND (not drawn) |
| 5V | VCC | red | 100 nF capacitor from VCC to GND, right at the chip. |
| GND | GND | black | |
| D11 | DS | green | MOSI |
| D13 | SH_CP | yellow | SCK |
| D10 | ST_CP | purple | Latch |
| GND | OE | black | Outputs always on. Wire to a PWM pin instead to dim all LEDs. |
| 5V | MR | red | Reset held inactive. |
2–6 V part, 5 V board. Power it from the same voltage as your board: 3.3 V on ESP32 and Pico, 5 V on Uno. At 5 V the 74HC595 needs about 3.15 V for a HIGH, so a 3.3 V board driving a 5 V-powered chip is marginal — use a 74HCT595 at 5 V for that.
Board quirks
- DS and SH_CP on D11 and D13 let the Nano’s hardware SPI clock out a byte in about 2 µs — roughly 50× faster than
shiftOut(). The latch can be any pin; D10 is used because it must stay an output for SPI anyway. - D13 is also the on-board LED, so it flickers with the clock. Harmless.
- The 74HC595 can source about 6 mA per output and 70 mA in total. 220 Ω LEDs are fine; relays and motors need a ULN2803 after it.
- Chain more chips by wiring Q7S to the next DS and sharing SH_CP/ST_CP; then send one byte per chip before latching.
- Pin names differ by maker (SER/SRCLK/RCLK on TI datasheets). See the component page for the mapping.
Code
// 74HC595 shift register on an Arduino Nano driving 8 LEDs with hardware SPI (fast, 3 pins).
// DS → D11 (MOSI), SH_CP → D13 (SCK), ST_CP → D10 (latch), OE → GND, MR → 5V, VCC → 5V, GND → GND.
// Q0-Q7 each → 220 Ω → LED → GND.
#include <SPI.h>
const uint8_t LATCH_PIN = 10;
void write595(uint8_t bits) {
digitalWrite(LATCH_PIN, LOW);
SPI.transfer(bits); // Q7 gets the first bit out (MSB first)
digitalWrite(LATCH_PIN, HIGH); // rising edge on ST_CP copies the byte to Q0-Q7
}
void setup() {
Serial.begin(115200);
pinMode(LATCH_PIN, OUTPUT);
SPI.begin();
SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
write595(0);
Serial.println(F("Scanner pattern on Q0-Q7"));
}
void loop() {
for (int8_t i = 0; i < 8; i++) { // Q0 → Q7
write595(1 << i);
delay(70);
}
for (int8_t i = 6; i > 0; i--) { // and back
write595(1 << i);
delay(70);
}
static uint8_t rounds = 0;
if (++rounds % 10 == 0) {
Serial.print(F("Rounds: "));
Serial.println(rounds);
}
}// 74HC595 shift register on an Arduino Nano driving 8 LEDs with hardware SPI (fast, 3 pins).
// DS → D11 (MOSI), SH_CP → D13 (SCK), ST_CP → D10 (latch), OE → GND, MR → 5V, VCC → 5V, GND → GND.
// Q0-Q7 each → 220 Ω → LED → GND.
#include <SPI.h>
const uint8_t LATCH_PIN = 10;
void write595(uint8_t bits) {
digitalWrite(LATCH_PIN, LOW);
SPI.transfer(bits); // Q7 gets the first bit out (MSB first)
digitalWrite(LATCH_PIN, HIGH); // rising edge on ST_CP copies the byte to Q0-Q7
}
void setup() {
Serial.begin(115200);
pinMode(LATCH_PIN, OUTPUT);
SPI.begin();
SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
write595(0);
Serial.println(F("Scanner pattern on Q0-Q7"));
}
void loop() {
for (int8_t i = 0; i < 8; i++) { // Q0 → Q7
write595(1 << i);
delay(70);
}
for (int8_t i = 6; i > 0; i--) { // and back
write595(1 << i);
delay(70);
}
static uint8_t rounds = 0;
if (++rounds % 10 == 0) {
Serial.print(F("Rounds: "));
Serial.println(rounds);
}
}Expected serial output
Scanner pattern on Q0-Q7
Rounds: 10
Rounds: 20Scanner pattern on Q0-Q7 Rounds: 10 Rounds: 20
Common errors
All LEDs on or random
MR floating or OE not grounded. Both must be tied, as in the table.
Pattern runs backwards
Change MSBFIRST to LSBFIRST, or wire the LEDs in the other order.