
E582 Lesson 24: 74HC595 Two-Digit Display | Arduino Step-by-Step Course
🔢 Display Numbers Using 74HC595 and 7-Segment Displays
In this tutorial, you’ll learn how to use a 74HC595 shift register IC to control a 2-digit 7-segment display using an Arduino. This setup drastically reduces the number of required GPIO pins on the Arduino, making it ideal for microcontroller projects with limited pin availability.
The demonstration includes full wiring instructions, code walkthrough, and a working example. This article also explains the internal logic of the 74HC595 and how it helps multiplex multiple displays with only three control pins.
📦 You can download the complete source code and required library files (ShiftRegister74HC595.h and .cpp) as a ZIP package at the end of this article.
⏱️ Video Chapters
00:00 Introduction
03:10 Wiring Explained
03:48 Arduino Code Explained
18:20 Demonstration
🧠 How the 74HC595 Works
The 74HC595 is an 8-bit serial-in, parallel-out shift register with a storage register and 3-state outputs. It allows you to shift in serial data and output it in parallel, reducing the number of control pins needed.
It operates using 3 main lines:
DS (Data) – Input serial data
SHCP (Shift Clock) – Moves the bit inside shift register
STCP (Storage Clock/Latch) – Sends the bits to output pins
Each clock pulse shifts a bit through the register. After 8 bits are in, the latch pin updates the outputs all at once. This makes it perfect for driving 7-segment displays (which typically require 8 lines per digit).
🔌 Wiring Overview
To connect the two-digit 7-segment display with the 74HC595:
Connect DS, SHCP, and STCP of the 74HC595 to Arduino digital pins (defined in code).
Each segment of the digit is connected via current-limiting resistors to the output of the shift register.
The digit control (for selecting left or right digit) is handled by enabling transistor or direct pin toggle.
This lets us multiplex digits: display one digit at a time fast enough that both appear lit continuously to the human eye.
💻 Arduino Code Overview
This project uses a custom library ShiftRegister74HC595
that handles digit-to-segment logic. Below are key parts of the code:
1. Library and Pin Configuration
cppCopyEdit#include <ShiftRegister74HC595.h>
#define DATA_PIN 2
#define LATCH_PIN 3
#define CLOCK_PIN 4
ShiftRegister74HC595 sr(DATA_PIN, LATCH_PIN, CLOCK_PIN);
Initializes the shift register with designated pins.
Only 3 Arduino pins are used for the entire 2-digit display.
2. Digit Control
cppCopyEditint digit1 = 5; // right digit
int digit2 = 6; // left digit
void setup() {
pinMode(digit1, OUTPUT);
pinMode(digit2, OUTPUT);
}
digit1
anddigit2
are used to control which of the two digits is active.The loop alternates between the two to show complete 2-digit numbers.
3. Displaying Numbers
cppCopyEditvoid displayNumber(int value) {
int rightDigit = value % 10;
int leftDigit = value / 10;
digitalWrite(digit2, LOW);
sr.displayNumber(rightDigit);
digitalWrite(digit1, HIGH);
delay(5);
digitalWrite(digit1, LOW);
sr.displayNumber(leftDigit);
digitalWrite(digit2, HIGH);
delay(5);
digitalWrite(digit2, LOW);
}
The number is split into two digits.
Each digit is turned on and updated briefly using the shift register.
This function is called repeatedly in the
loop()
to refresh the display.
4. Main Loop
cppCopyEditint number = 0;
void loop() {
displayNumber(number);
number++;
if (number > 99) number = 0;
delay(1000);
}
Continuously counts from 0 to 99, displaying the value on the 2-digit 7-segment display.
✅ Demonstration
At 18:20 in the video, you can see the full demo of the counter incrementing on the 2-digit display. The digits switch rapidly and appear stable to the human eye, thanks to fast multiplexing.
📥 Download Section
You can download the following files as a ZIP archive:
Seven_segment_2_digits.ino
(Arduino Sketch)ShiftRegister74HC595.h
ShiftRegister74HC595.cpp
This project is ideal for learning multiplexing and shift register logic. It can easily be extended to more digits or used in combination with sensors and inputs to build interactive counters or timers.
Related Links
- Purchase an authentic Arduino UNO R3 from Amazon USA
- Purchase an Arduino Starter Kit from Amazon USA
- Purchase an Arduino Starter Kit from Amazon Canada
- Original Source Page (www.Ardumotive.com)
- 74HC595 datasheet (PDF)
- Purchase an authentic Arduino board from Amazon Canada
- Purchase ESP32 Ultimate Starter Kit from SunFounder's Store
Downloads
-
74HC595 Display Driver .cpp and .h files 0 MB You need this for this tutorial. Download and save them in the same folder as your Arduino file.Download
Comments will be displayed here.