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);
}
digit1anddigit2are 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.hShiftRegister74HC595.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.
/*
* updated by Ahmad Shamshiri for Robojax
Lesson 24: 2 digits display using 74HC595 chip
* On Monday, September 17, 2019 at 00:03 in Ajax, Ontario, Canada
*
* Watch video instruction for this video: https://youtu.be/pJPdH7mOUzk
* At the moment, it doesn't display decimal points. It needs a little work to make it work
* This code is part of Arduino Step by Step Course which starts here: https://youtu.be/-6qSrDUA5a8
*
* for library of this code visit http://robojax.com/
*
If you found this tutorial helpful, please support me so I can continue creating
content like this. Make a donation using PayPal by credit card https://bit.ly/donate-robojax
* This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.*
* This code has been downloaded from Robojax.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
* Original source and text.
* 2 Digit 7-segment display PCB board with (2) 74HC595 shift register ICs
* Arduino Tutorial - www.Ardumotive.com
* Dev: Michalis Vasilakis // Date: 31/1/2018 // Ver:1.0
*/
#include <ShiftRegister74HC595.h>
#define SDI 7
#define SCLK 6
#define LOAD 5
#define DIGITS 2
// create shift register object (number of shift registers, data pin, clock pin, latch pin)
ShiftRegister74HC595 sr (DIGITS, SDI, SCLK, LOAD);
int value,digit1,digit2,digit3,digit4;
uint8_t digits[] = {B11000000, //0
B11111001, //1
B10100100, //2
B10110000, //3
B10011001, //4
B10010010, //5
B10000010, //6
B11111000, //7
B10000000, //8
B10010000 //9
};
void setup() {
}
void loop() {
showNumber(18);
delay(2000);//
for(int i=0; i<=99; i++)
{
showNumber(i);
delay(100);
}
delay(2000);
for(int i=99; i >=0; i--)
{
showNumber(i);
delay(50);
}
delay(2000);
}// loop
/*
* @brief shows number on the Seven Segment Display
* @param "num" is an integer
* @return returns none
* Usage to show 18: showNumber(18);
* Written by Ahmad Shamshiri on September 17, 2019.
* in Ajax, Ontario, Canada
* www.Robojax.com
*/
void showNumber(int num)
{
digit2=num % 10 ;
digit1=(num / 10) % 10 ;
//Send them to 7 segment displays
uint8_t numberToPrint[]= {digits[digit2],digits[digit1]};
sr.setAll(numberToPrint);
}
Resources & references
-
External74HC595 datasheet (PDF)ti.com
-
ExternalOriginal Source Page (www.Ardumotive.com)ardumotive.com
-
External
Files📁
Other files
-
74HC595 Display Driver .cpp and .h filesYou need this for this tutorial. Download and save them in the same folder as your Arduino file.
ShiftRegister74HC595.zip