Four-digit display on a 74HC595 (pins 8, 10 and 9), on an Arduino Uno
A 74HC595 with data on pin 8, clock on 10 and latch on 9 drives the segments of a four-digit display whose digits are all switched on, stepping through 0 to F. The whole build, an Arduino Uno and 6 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 Runs in your browser. Free, and no account needed.
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// A four-digit display on one 74HC595: every digit shows the same symbol.
//
// 74HC595 DS -> pin 8 SHCP -> pin 10 STCP -> pin 9
// 74HC595 VCC and MR -> 5V GND and OE -> GND
// Q0 to Q7 -> segments a to g and the decimal point
// each digit's common cathode (DIG1 to DIG4) -> its own 220 ohm -> GND
//
// The four digits share their segment lines: segment a of every digit is one
// wire. Each digit lights only while its common pin is grounded. Here all four
// are grounded all the time, so all four show the same symbol. To show four
// different symbols a sketch switches the digits on one after another, faster
// than the eye can follow; the stopwatch circuits do exactly that.
//
// The sketch steps through the sixteen hexadecimal digits, 0 to F, twice a
// second.
const int DATA_PIN = 8;
const int LATCH_PIN = 9;
const int CLOCK_PIN = 10;
// 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 show(byte pattern) {
digitalWrite(LATCH_PIN, LOW);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, pattern);
digitalWrite(LATCH_PIN, HIGH);
}
void setup() {
pinMode(DATA_PIN, OUTPUT);
pinMode(LATCH_PIN, OUTPUT);
pinMode(CLOCK_PIN, OUTPUT);
Serial.begin(9600);
Serial.println("Mokxi Uno: four digits on a 74HC595 (pins 8, 10 and 9)");
}
void loop() {
for (int i = 0; i < 16; i++) {
show(HEX_DIGITS[i]);
Serial.println(SYMBOLS[i]);
delay(500);
}
}
Parts list
8 parts, plus the jumper wires. Every one is in the editor's parts bin.
How it is wired
17 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- Ground: Arduino Uno R3 pin GND; 74HC595 shift register pin GND; 74HC595 shift register pin OE; Resistor, 220 Ω (1) pin 2; Resistor, 220 Ω (2) pin 2; Resistor, 220 Ω (3) pin 2; Resistor, 220 Ω (4) pin 2
- Arduino Uno R3 pin 10; 74HC595 shift register pin SHCP
- Arduino Uno R3 pin 9; 74HC595 shift register pin STCP
- Arduino Uno R3 pin 8; 74HC595 shift register pin DS
- Arduino Uno R3 pin 5V; 74HC595 shift register pin MR; 74HC595 shift register pin VCC
- 74HC595 shift register pin Q1; Four-digit seven segment, multiplexed pin B
- 74HC595 shift register pin Q2; Four-digit seven segment, multiplexed pin C
- 74HC595 shift register pin Q3; Four-digit seven segment, multiplexed pin D
- 74HC595 shift register pin Q4; Four-digit seven segment, multiplexed pin E
- 74HC595 shift register pin Q5; Four-digit seven segment, multiplexed pin F
- 74HC595 shift register pin Q6; Four-digit seven segment, multiplexed pin G
- 74HC595 shift register pin Q7; Four-digit seven segment, multiplexed pin DP
- 74HC595 shift register pin Q0; Four-digit seven segment, multiplexed pin A
- Four-digit seven segment, multiplexed pin DIG4; Resistor, 220 Ω (4) pin 1
- Four-digit seven segment, multiplexed pin DIG3; Resistor, 220 Ω (3) pin 1
- Four-digit seven segment, multiplexed pin DIG2; Resistor, 220 Ω (2) pin 1
- Four-digit seven segment, multiplexed pin DIG1; Resistor, 220 Ω (1) pin 1
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.