Your Arduino Uno has 14 digital I/O pins. That might seem like a lot when you’re just blinking a single LED or reading a single button. But what if you want to build an LED cube, a digital clock, or a scrolling text display? You will quickly run out of pins.
Instead of buying a larger, more expensive microcontroller, you can use a clever integrated circuit called a Shift Register.
A shift register acts like an expansion module, turning a few control pins into many output pins.
The 74HC595 is one of the most famous shift registers. It takes serial data (data sent one bit at a time, sequentially down a single wire) and converts it into parallel data (multiple bits output simultaneously across multiple wires).
In practical terms: you use just three pins on your Arduino to talk to the 74HC595, and the 74HC595 gives you eight new digital output pins! Even better, you can “daisy-chain” multiple shift registers together. Connect two 74HC595 chips, and you get 16 outputs, still using those same original three Arduino pins.
The 74HC595 has 16 pins. The three critical pins connected to the Arduino are:
Wiring 8 LEDs can be messy, so take your time!
Here is the code to make the LEDs light up in a sequence using the shiftOut() function built into Arduino.
// Define the pins connected to the 74HC595
const int latchPin = 8; // STCP
const int clockPin = 12; // SHCP
const int dataPin = 11; // DS
void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop() {
// Loop through all 8 LEDs
for (int i = 0; i < 8; i++) {
// Ground the latch pin so the LEDs don't flicker while transmitting
digitalWrite(latchPin, LOW);
// Shift out a byte (8 bits).
// bit(i) creates a byte with only the i-th bit set to 1.
shiftOut(dataPin, clockPin, MSBFIRST, bit(i));
// Pulse the latch pin high to push the data to the outputs
digitalWrite(latchPin, HIGH);
delay(200); // Wait so we can see the LED
}
}
By mastering the shift register, you unlock the ability to build massive LED displays and complex indicators without worrying about running out of pins!