Search Code

How to Use a Two-Digit LED Display with an Arduino Using the 74HC595

How to Use a Two-Digit LED Display with an Arduino Using the 74HC595

This project demonstrates how to control a two-digit seven-segment LED display with an Arduino using the 74HC595 shift register. This setup is ideal for displaying numerical data from your Arduino projects, such as sensor readings, counters, or timers.

Here are some practical applications for this project:

  • Displaying the temperature from a sensor.
  • Creating a simple timer or stopwatch.
  • Showing the score in a game.
  • Visualizing data from other sensors (e.g., humidity, pressure).
  • Building a digital clock.

Hardware/Components

  • Arduino Uno (or any compatible board)
  • Two-digit seven-segment LED display
  • 74HC595 shift register IC (2)
  • Jumper wires
  • Breadboard (optional)

Wiring Guide

The 74HC595 shift registers control the segments of the LED display. Connect the output pins of the shift registers to the corresponding segments of the display. The data, clock, and latch pins of the shift registers are connected to the Arduino's digital pins. Specific pin connections are defined in the code.

%%WIRING%%

Code Explanation

The code uses the ShiftRegister74HC595 library to simplify interaction with the shift registers. You'll need to install this library in your Arduino IDE.

The crucial part of the code defines the pin connections for the shift registers:


#define SDI 7
#define SCLK 6
#define LOAD 5
#define DIGITS 2

(in video at 05:45)

The digits array maps numerical values (0-9) to their corresponding seven-segment representations. Each byte in the array represents a digit, with each bit controlling a specific segment of the display.


uint8_t  digits[] = {B11000000, //0
                      B11111001, //1
                      // ... other digits
                     };

The showNumber function takes an integer as input and displays it on the two-digit LED display. It extracts the tens and units digits using integer division and the modulo operator and then sends the corresponding byte patterns to the shift registers via the sr.setAll function.


void showNumber(int num)
{
    digit2=num % 10 ;
    digit1=(num / 10) % 10 ;
    uint8_t numberToPrint[]= {digits[digit2],digits[digit1]};
    sr.setAll(numberToPrint);  
}

(in video at 07:08)

Live Project/Demonstration

(in video at 09:52) The video demonstrates the project in action, showing how the numbers are displayed on the LED display. The demonstration includes counting up and down, showcasing the functionality of the code and hardware.

Chapters

  • [00:00] Introduction and Project Overview
  • [00:49] Remote Control Options
  • [02:48] AC Bulb and Safety Precautions
  • [03:16] Relay Explanation
  • [05:29] Code Explanation
  • [09:52] Project Demonstration
  • [10:49] Using the Bare Module
  • [11:53] Using the Black Remote
  • [13:15] Using Your Own Remote

Images

2-Digit LED Display Setup
2 Digit LED Display setup
74HC595 LED Display: Display showing.
74HC595 LED Display: Display showing
74HC595 LED Display: Code Module
74HC595 LED Display: Code Module
74HC595 LED Display: back of the module
74HC595 LED Display: back of the module
74HC595 LED Display: Display Showing
74HC595 LED Display: Display showing
74HC595 LED Display: Wiring explained
74HC595 LED Display: Wiring is explained
74HC595 LED Display: Seven-Segment Explained
74HC595 LED Display: Seven Segment explained
74HC595 LED display: Decimal point displayed
74HC595 LED Display: Decimal point displayed
247-74HC595 Seven-Segment 2-Digit LED Display with Decimal Points for Arduino
Language: C++
++
/*
 *  74HC595 Seven Segment 2 Digits LED Display with decimal points for Arduino
 *  updated by Ahmad Shamshiri for Robojax
 *  On Monday, September 17, 2019 at 00:03 in Ajax, Ontario, Canada
 *
 *  Watch video instruction for this video: https://youtu.be/k-f6lwwUTAs
 *  At the moment, it doesn't display decimal points. It needs a little work to make it work.
 *
 * You can get the wiring diagram from my Arduino Course at Udemy.com.
 * Learn Arduino step by step with all libraries, codes, and wiring diagrams all in one place.
 * Visit my course now: http://robojax.com/L/?id=62
 *
 * If you found this tutorial helpful, please support me so I can continue creating
 * content like this. You can support me on Patreon: http://robojax.com/L/?id=63
 * or make a donation using PayPal: http://robojax.com/L/?id=64
 *
 * Code is available at: http://robojax.com/learn/arduino
 *
 * 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

Files📁

No files available.