Hex digits through a 74HC595 (pins 11, 8 and 12), on an Arduino Uno
A 74HC595 with DS on pin 11, SH_CP on 8 and ST_CP on 12 drives a one-digit display through all sixteen hexadecimal digits, 0 to F. The whole build, an Arduino Uno and 3 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 $33. On Mokxi they're free.
What you'll learn
- Shift registers: many outputs from three pins
- Data, clock and latch signals
- One bit per segment on a seven-segment display
- Lookup tables of byte patterns
- Using
shiftOutinstead of toggling pins by hand
- Difficulty: Intermediate
- Time: About 20 minutes
- Board: Arduino Uno R3
- Parts: 5
How it works
A 74HC595 turns three Arduino pins into eight outputs. Pin 11 sends data (DS), pin 8 pulses the clock (SH_CP) and pin 12 latches the result (ST_CP). Outputs Q0 to Q6 go to segments a to g of one seven-segment digit, with one 220 ohm resistor on its common leg.
Each digit is a byte with one bit per segment. The sketch loops through 16 patterns, one per second: 0 to 9, then A to F. It shifts out a byte, latches it, and prints the matching symbol to the serial monitor.
Parts list
5 parts, plus the jumper wires. They retail for about $33; 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.
- 1 × Seven segment displayIn Display Kit.
- 1 × Resistor, 220 ΩIn Starter Kit, Claw Machine Kit, Halloween Prop Kit.
Kits that can build it
These 8 starter kits have every part in the circuit. Each kit's page lists what else it can build.
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 |
| Resistor, 220 Ω pin 2 | Arduino Uno R3 pin GND |
| 74HC595 shift register pin STCP | Arduino Uno R3 pin 12 |
| 74HC595 shift register pin DS | Arduino Uno R3 pin 11 |
| 74HC595 shift register pin SHCP | Arduino Uno R3 pin 8 |
| 74HC595 shift register pin MR | Arduino Uno R3 pin 5V |
| 74HC595 shift register pin VCC | Arduino Uno R3 pin 5V |
| Seven segment display pin B | 74HC595 shift register pin Q1 |
| Seven segment display pin C | 74HC595 shift register pin Q2 |
| Seven segment display pin D | 74HC595 shift register pin Q3 |
| Seven segment display pin E | 74HC595 shift register pin Q4 |
| Seven segment display pin F | 74HC595 shift register pin Q5 |
| Seven segment display pin G | 74HC595 shift register pin Q6 |
| Seven segment display pin A | 74HC595 shift register pin Q0 |
| Resistor, 220 Ω pin 1 | Seven segment display pin COM1 |
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// A 74HC595 drives one seven-segment digit: 0 to 9, then A to F.
//
// 74HC595 DS -> pin 11 SH_CP -> pin 8 ST_CP -> pin 12
// 74HC595 VCC and MR -> 5V GND and OE -> GND
// Q0 to Q6 -> segments a to g, Q7 -> the dot
// the display's common cathode -> 220 ohm -> GND
//
// shiftOut() sends a byte one bit at a time on DS, with a pulse on SH_CP for
// each bit; a pulse on ST_CP then copies all eight to the outputs at once.
// With MSBFIRST and segment a in the lowest bit, bit 0 ends up on Q0.
const int DS = 11;
const int SHCP = 8;
const int STCP = 12;
// gfedcba
const byte HEX_DIGITS[16] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07,
0x7F, 0x6F, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71};
const char SYMBOLS[] = "0123456789ABCDEF";
void setup() {
pinMode(DS, OUTPUT);
pinMode(SHCP, OUTPUT);
pinMode(STCP, OUTPUT);
Serial.begin(9600);
Serial.println("Mokxi Uno: 74HC595 on pins 11, 8 and 12");
}
void loop() {
for (int i = 0; i < 16; i++) {
digitalWrite(STCP, LOW);
shiftOut(DS, SHCP, MSBFIRST, HEX_DIGITS[i]);
digitalWrite(STCP, HIGH);
Serial.println(SYMBOLS[i]);
delay(1000);
}
}
Code walkthrough
The key functions of the sketch, and what each one does.
setup sketch.ino
Makes pins DS, SHCP and STCP outputs, then starts the serial port and prints a hello line. The shift register needs no other setup, because MR is tied to 5V and OE to ground.
void setup() {
pinMode(DS, OUTPUT);
pinMode(SHCP, OUTPUT);
pinMode(STCP, OUTPUT);
Serial.begin(9600);
Serial.println("Mokxi Uno: 74HC595 on pins 11, 8 and 12");
}loop sketch.ino
Walks through the 16 entries of HEX_DIGITS. For each, it pulls STCP low, uses shiftOut to send the byte most significant bit first, then raises STCP so all eight outputs change at once. It prints the symbol and waits one second.
void loop() {
for (int i = 0; i < 16; i++) {
digitalWrite(STCP, LOW);
shiftOut(DS, SHCP, MSBFIRST, HEX_DIGITS[i]);
digitalWrite(STCP, HIGH);
Serial.println(SYMBOLS[i]);
delay(1000);
}
}Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- Segments light in the wrong pattern This project
Check that Q0 to Q6 go to segments a to g in order. A swapped wire shows a wrong shape. - The display stays dark This project
OE must go to ground, MR and VCC to 5V, and the common leg through the resistor to ground. - 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. - Segments stay dark, or light when they should be off. Seven segment display
Check whether the display is common cathode or common anode. Common cathode: common pin to GND, drive segments HIGH. Common anode: common pin to VCC, drive segments LOW. - One segment is very bright or the LEDs burn out. Seven segment display
Each segment is an LED, so it needs its own resistor, about 220 ohm to 330 ohm on 5 V. One resistor on the common pin makes brightness change with the number of lit segments. - 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.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.