Eight LEDs on a 74HC595 (pins 12, 9 and 11), on an Arduino Uno
A 74HC595 shift register drives eight LEDs from three Uno pins, data on 12, clock on 9 and latch on 11: the LEDs fill up one at a time, then clear. The whole build, an Arduino Uno and 17 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Intermediate About 20 minutes to build and run. Runs in your browser. Free, and no account needed.
The parts retail for about $34. On Mokxi they're free.
What you'll learn
- Turning three pins into eight outputs
- Clock, data and latch: what each wire does
- Setting single bits in a byte with bitSet
- Why one resistor per LED is needed
- Difficulty: Intermediate
- Time: About 20 minutes
- Board: Arduino Uno R3
- Parts: 19
How it works
A 74HC595 shift register gives you eight outputs from three Uno pins: data on 12, clock on 9 and latch on 11. Each output Q0 to Q7 drives one yellow LED through a 220 ohm resistor.
The sketch keeps one byte called leds, one bit per LED. It starts with all off, then sets one more bit every 300 ms, so the row fills up from Q0 to Q7. After all eight are lit, the loop starts over by clearing them.
Parts list
19 parts, plus the jumper wires. They retail for about $34; on Mokxi they're free.
- 1 × Arduino Uno R3In Starter Kit, Claw Machine Kit, Vending Machine Kit.
- 1 × Full-size breadboard
- 1 × 74HC595 shift registerIn LED Cube Kit.
- 8 × Resistor, 220 ΩIn Starter Kit, Claw Machine Kit, Halloween Prop Kit.
- 8 × LED, yellowIn Starter Kit, Halloween Prop Kit, Logic Lab Kit.
Kits that can build it
These 11 starter kits have every part in the circuit. Each kit's page lists what else it can build.
- ELEGOO UNO R3 Super Starter Kit
- ELEGOO UNO R3 Most Complete Starter Kit
- Freenove Ultimate Starter Kit
- ELEGOO UNO R3 Basic Starter Kit
- SunFounder Starter Kit for Arduino Uno R3
- SunFounder Inventor Lab Kit
- REXQualis UNO R3 Super Starter Kit
- LAFVIN Super Starter Kit
- keyestudio Super Starter Kit
- Vilros Arduino Uno 3 Ultimate Starter Kit
- Adafruit MetroX Classic Kit
Wiring table
Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.
| Part and pin | Connects to |
|---|---|
| 74HC595 shift register pin GND | Arduino Uno R3 pin GND |
| 74HC595 shift register pin OE | Arduino Uno R3 pin GND |
| LED, yellow (1) pin C | Arduino Uno R3 pin GND |
| LED, yellow (2) pin C | Arduino Uno R3 pin GND |
| LED, yellow (3) pin C | Arduino Uno R3 pin GND |
| LED, yellow (4) pin C | Arduino Uno R3 pin GND |
| LED, yellow (5) pin C | Arduino Uno R3 pin GND |
| LED, yellow (6) pin C | Arduino Uno R3 pin GND |
| LED, yellow (7) pin C | Arduino Uno R3 pin GND |
| LED, yellow (8) pin C | Arduino Uno R3 pin GND |
| 74HC595 shift register pin DS | Arduino Uno R3 pin 12 |
| 74HC595 shift register pin STCP | Arduino Uno R3 pin 11 |
| 74HC595 shift register pin SHCP | Arduino Uno R3 pin 9 |
| 74HC595 shift register pin MR | Arduino Uno R3 pin 5V |
| 74HC595 shift register pin VCC | Arduino Uno R3 pin 5V |
| Resistor, 220 Ω (2) pin 1 | 74HC595 shift register pin Q1 |
| Resistor, 220 Ω (3) pin 1 | 74HC595 shift register pin Q2 |
| Resistor, 220 Ω (4) pin 1 | 74HC595 shift register pin Q3 |
| Resistor, 220 Ω (5) pin 1 | 74HC595 shift register pin Q4 |
| Resistor, 220 Ω (6) pin 1 | 74HC595 shift register pin Q5 |
| Resistor, 220 Ω (7) pin 1 | 74HC595 shift register pin Q6 |
| Resistor, 220 Ω (8) pin 1 | 74HC595 shift register pin Q7 |
| Resistor, 220 Ω (1) pin 1 | 74HC595 shift register pin Q0 |
| LED, yellow (1) pin A | Resistor, 220 Ω (1) pin 2 |
| LED, yellow (2) pin A | Resistor, 220 Ω (2) pin 2 |
| LED, yellow (3) pin A | Resistor, 220 Ω (3) pin 2 |
| LED, yellow (4) pin A | Resistor, 220 Ω (4) pin 2 |
| LED, yellow (5) pin A | Resistor, 220 Ω (5) pin 2 |
| LED, yellow (6) pin A | Resistor, 220 Ω (6) pin 2 |
| LED, yellow (7) pin A | Resistor, 220 Ω (7) pin 2 |
| LED, yellow (8) pin A | Resistor, 220 Ω (8) pin 2 |
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// Eight LEDs from three pins, through a 74HC595 shift register.
//
// 74HC595 DS (pin 14) -> Uno pin 12 (data)
// 74HC595 SHCP (pin 11) -> Uno pin 9 (clock)
// 74HC595 STCP (pin 12) -> Uno pin 11 (latch)
// 74HC595 VCC and MR -> 5V GND and OE -> GND
// Q0 to Q7 -> eight LEDs, each through 220 ohm to GND
//
// The chip has eight outputs but takes its data one bit at a time. shiftOut()
// clocks the eight bits of a byte in over DS and SHCP; nothing changes on the
// outputs until the latch pin goes from LOW to HIGH, and then all eight change
// at once. So three Uno pins drive eight LEDs, and two chips chained together
// would drive sixteen.
//
// The sketch lights the LEDs one more at a time, then clears them all.
const int DATA_PIN = 12;
const int CLOCK_PIN = 9;
const int LATCH_PIN = 11;
byte leds = 0;
void show(byte value) {
digitalWrite(LATCH_PIN, LOW);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, value); // bit 0 lands on Q0
digitalWrite(LATCH_PIN, HIGH);
}
void setup() {
pinMode(DATA_PIN, OUTPUT);
pinMode(CLOCK_PIN, OUTPUT);
pinMode(LATCH_PIN, OUTPUT);
Serial.begin(9600);
Serial.println("Mokxi Uno: 74HC595 on pins 12 (data), 9 (clock) and 11 (latch)");
}
void loop() {
leds = 0;
show(leds);
delay(300);
for (int i = 0; i < 8; i++) {
bitSet(leds, i);
show(leds);
Serial.print("LEDs lit: ");
Serial.println(i + 1);
delay(300);
}
}
Code walkthrough
The key functions of the sketch, and what each one does.
show sketch.ino
Lowers the latch, clocks the byte into the chip with shiftOut, then raises the latch. Nothing visible happens while bits shift. When the latch goes HIGH, all eight outputs change at once. Bit 0 lands on Q0.
void show(byte value) {
digitalWrite(LATCH_PIN, LOW);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, value); // bit 0 lands on Q0
digitalWrite(LATCH_PIN, HIGH);
}setup sketch.ino
Sets the data, clock and latch pins as outputs and starts serial at 9600 with a hello line.
void setup() {
pinMode(DATA_PIN, OUTPUT);
pinMode(CLOCK_PIN, OUTPUT);
pinMode(LATCH_PIN, OUTPUT);
Serial.begin(9600);
Serial.println("Mokxi Uno: 74HC595 on pins 12 (data), 9 (clock) and 11 (latch)");
}loop sketch.ino
Clears leds and shows it, waits 300 ms, then runs a loop from 0 to 7. Each round uses bitSet to turn on the next bit, shows the byte, prints how many LEDs are lit, and waits 300 ms again.
void loop() {
leds = 0;
show(leds);
delay(300);
for (int i = 0; i < 8; i++) {
bitSet(leds, i);
show(leds);
Serial.print("LEDs lit: ");
Serial.println(i + 1);
delay(300);
}
}Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- Only the wrong LEDs light, or they light in a jumbled order. This project
Check each output Q0 to Q7 goes to its own resistor and LED, in order, with the LED cathodes to GND. - Nothing lights at all. This project
Check data is on pin 12, clock on 9 and latch on 11. These differ from other 595 examples. OE should be at GND and MR at 5V. - Outputs show garbage, or the register never clears. 74HC595 shift register
Tie OE low and SRCLR (pin 10) high. Left floating, these pins make the chip behave randomly. Then pulse the latch pin after shifting the byte. - The bits come out in the wrong order, or LEDs are dim. 74HC595 shift register
Choose MSBFIRST or LSBFIRST in shiftOut to flip the order. Give each LED its own resistor, since each output can source only about 6 mA safely. - The LED is dim, burns out, or the pin reads wrong because the resistor value is off. Resistor
Read the color bands again. A 220 ohm to 330 ohm resistor suits a typical LED on 5 V. 10k is a common pull-up or pull-down value. Check with a multimeter if unsure. - A pull-up or pull-down resistor is missing, so the input floats and reads random values. Resistor
Tie the input to 5 V or ground through about 10k. Or use INPUT_PULLUP and wire the switch to ground. - The LED does not light, or it lights once and then dies. LED
LEDs have polarity. The longer leg (anode) goes toward the positive side. Always add a series resistor, about 220 ohms to 1 k ohm on a 5 V pin. - A blue or white LED stays dark on 3.3 V. LED
Blue and white LEDs drop about 3 V, so 3.3 V leaves almost nothing for the resistor. Use a 5 V supply, or a smaller resistor and a red or green LED.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.