Arduino UNO R4 - 74HC595 4-Digit 7-Segment Display

A typical 4-digit 7-segment display is used in projects like clocks, timers, and counters, and usually needs 12 connections. The 74HC595 module simplifies this by using only 5 connections: 2 for power and 3 to control the segments.

This tutorial will not give you too much complex information about hardware. Instead, you will learn how to connect a 4-digit 7-segment display to an Arduino UNO R4 and how to program it to display information.

Arduino UNO R4 74HC595 4-digit 7-segment display

This guide will show how to use the 4-dot, 4-digit, 7-seegment display module that can show float values. If you need to display a colon separator, please use the TM1637 4-digit 7-segment Display Module.

Hardware Preparation

1×Arduino UNO R4 WiFi
1×Arduino UNO R4 Minima (Alternatively)
1×USB Cable Type-C
1×74HC595 4-digit 7-segment Display
1×Jumper Wires
1×(Recommended) Screw Terminal Block Shield for Arduino UNO R4
1×(Recommended) Breadboard Shield For Arduino UNO R4
1×(Recommended) Enclosure For Arduino UNO R4
1×(Recommended) Power Splitter For Arduino UNO R4

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables.

Overview of 74HC595 4-digit 7-segment Display

A 74HC595 4-digit 7-segment display module usually includes 4 7-segment LEDs, 4 small dot LEDs, and a 74HC595 driver for each digit. It is perfect for showing temperatures or any numbers with decimals.

Pinout

The 74HC595 module for a 4-digit 7-segment display has 5 pins:

  • SCLK pin: This is a clock input pin. Connect it to any digital pin on the Arduino UNO R4.
  • RCLK pin: This is another clock input pin. Connect it to any digital pin on the Arduino UNO R4.
  • DIO pin: This is a Data Input/Output pin. Connect it to any digital pin on the Arduino UNO R4.
  • VCC pin: This pin provides power to the module. Connect it to a power supply between 3.3V and 5V.
  • GND pin: This is a ground pin. Connect it to the ground.
74HC595 module pinout

Wiring Diagram

This table shows how to connect the Arduino UNO R4 pins to a 74HC595 4-digit 7-segment display:

Arduino UNO R4 74HC595 7-segment display
5V5V
7SCLK
6RCLK
5DIO

If you use different pins, change the pin numbers in the code.

The wiring diagram between Arduino UNO R4 74HC595 Module

This image is created using Fritzing. Click to enlarge image

Library Installation

To easily set up programming for a 74HC595 4-digit 7-segment Display, install the DIYables_4Digit7Segment_74HC595 library from DIYables.io. Here are the steps to install the library:

  • Click on the Libraries icon on the left side of the Arduino IDE.
  • Type “DIYables_4Digit7Segment_74HC595” in the search box, and look for the DIYables_4Digit7Segment_74HC595 library from DIYables.io
  • Press the Install button.
Arduino UNO R4 74HC595 4-digit 7-segment display library

You can also view this library on Github

How To Program For 74HC595 4-digit 7-segment using Arduino UNO R4

  • Include the library
#include <DIYables_4Digit7Segment_74HC595.h>
  • Connect the Arduino UNO R4 to the display module like this: D7 to SCLK, D6 to RCLK, and D5 to DIO.
#define SCLK 7 // The Arduino UNO R4 pin connected to SCLK #define RCLK 6 // The Arduino UNO R4 pin connected to RCLK #define DIO 5 // The Arduino UNO R4 pin connected to DIO
  • Make a display item called DIYables_4Digit7Segment_74HC595.
DIYables_4Digit7Segment_74HC595 display = DIYables_4Digit7Segment_74HC595(CLK, DIO);
  • You can show whole numbers with leading zeros, including negative numbers.
display.printInt(-13, false); // displays an integer without leading zeros
  • You can show numbers with decimal points, add zeros in front, and include negative numbers.
display.printFloat(-9.2, 1, false);
  • You can also show each number, decimal point, or character one by one using basic functions.
// display temperature 9.3°C display.clear(); display.setNumber(1, 9); // Display number '9' at position 1 display.setDot(1); // Enable decimal point at position 1 display.setNumber(2, 3); // Display number '3' at position 2 display.setChar(3, SegChars::DEGREE); // Display degree symbol at position 3 display.setChar(4, SegChars::C); // Display character 'C' at position 4 display.show(); // Refresh display to show the set characters and numbers
  • The 74HC595 4-digit 7-segment module controls each segment and LED by using a method called multiplexing. Therefore, the Arduino UNO R4 code MUST:
    • Use the display.show() function in the main loop.
    • Avoid using the delay() function in the main loop.

    For more details, visit the library reference.

Arduino UNO R4 Code - Display Integer

#include <DIYables_4Digit7Segment_74HC595.h> // DIYables_4Digit7Segment_74HC595 library #define SCLK 7 // The Arduino UNO R4 pin connected to SCLK #define RCLK 6 // The Arduino UNO R4 pin connected to RCLK #define DIO 5 // The Arduino UNO R4 pin connected to DIO DIYables_4Digit7Segment_74HC595 display(SCLK, RCLK, DIO); void setup() { Serial.begin(9600); display.printInt(-13, false); // you can display a value from -999 to 9999 //display.printInt(-132, false); //display.printInt(9132, false); //display.printInt(132, false); //display.printInt(32, false); //display.printInt(2, false); //display.printInt(2, true); } void loop() { display.loop(); // MUST call the display.loop() function in loop() // DO SOMETHING HERE // NOTE: do NOT use the delay() function in loop because it affects to the multiplexing }

Detailed Instructions

Follow these instructions step by step:

  • If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.
  • Connect the 74HC595 4-digit 7-segment Display to the Arduino Uno R4 according to the provided diagram.
  • Connect the Arduino Uno R4 board to your computer using a USB cable.
  • Launch the Arduino IDE on your computer.
  • Select the appropriate Arduino Uno R4 board (e.g., Arduino Uno R4 WiFi) and COM port.
  • Copy the code and open it using Arduino IDE.
  • Click the Upload button in Arduino IDE to send the code to Arduino UNO R4.
  • Observe the changes on the 7-segment display.

Arduino UNO R4 Code - Display Float

#include <DIYables_4Digit7Segment_74HC595.h> // DIYables_4Digit7Segment_74HC595 library #define SCLK 7 // The Arduino UNO R4 pin connected to SCLK #define RCLK 6 // The Arduino UNO R4 pin connected to RCLK #define DIO 5 // The Arduino UNO R4 pin connected to DIO DIYables_4Digit7Segment_74HC595 display(SCLK, RCLK, DIO); void setup() { Serial.begin(9600); display.printFloat(-9.2, 1, false); //display.printFloat(-92.4, 1, false); //display.printFloat(-9.24, 2, false); //display.printFloat(192.4, 1, false); //display.printFloat(19.24, 2, false); //display.printFloat(1.924, 3, false); } void loop() { display.loop(); // MUST call the display.loop() function in loop() // DO SOMETHING HERE // NOTE: do NOT use the delay() function in loop because it affects to the multiplexing }

Arduino UNO R4 Code - Display Temperature

#include <DIYables_4Digit7Segment_74HC595.h> // DIYables_4Digit7Segment_74HC595 library #define SCLK 7 // The Arduino UNO R4 pin connected to SCLK #define RCLK 6 // The Arduino UNO R4 pin connected to RCLK #define DIO 5 // The Arduino UNO R4 pin connected to DIO DIYables_4Digit7Segment_74HC595 display(SCLK, RCLK, DIO); void setup() { Serial.begin(9600); // display 9.3°C by controlling digit by digit display.clear(); display.setNumber(1, 9); // set 9 at the 1st digit display.setDot(1); // set . at the 1st digit display.setNumber(2, 3); // set 3 at the 2nd digit display.setChar(3, SegChars::DEGREE); // set ° at the 3rd digit display.setChar(4, SegChars::C); // set C at the 3rd digit display.show(); // show on the display } void loop() { display.loop(); // MUST call the display.loop() function in loop() // DO SOMETHING HERE // NOTE: do NOT use the delay() function in loop because it affects to the multiplexing }

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!