Arduino - 74HC595 4-Digit 7-Segment Display

by DIYables in Circuits > Arduino

8 Views, 0 Favorites, 0 Comments

Arduino - 74HC595 4-Digit 7-Segment Display

arduino-74hc595-4-digit-7-segment-display-cover.jpg

This is a compact build guide. The full tutorial, with the wiring diagram and a line-by-line walkthrough of the code, is here: https://arduinogetstarted.com/tutorials/arduino-74hc595-4-digit-7-segment-display

This build drives a 4-digit 7-segment display through a 74HC595 shift register, using only 3 pins from the Arduino instead of 12+. With the DIYables_4Digit7Segment_74HC595 library you can show integers, floats, text, a degree symbol, temperature, and clock-style time on the display, all with a few simple method calls.

Supplies

Wiring

arduino-74hc595-4-digit-7-segment-display-wiring-diagram.jpg

Connect SCLK on the display module to Arduino pin 7, RCLK to pin 6, and DIO to pin 5. Connect VCC to 5V and GND to GND. This tutorial uses the common anode version of the module; the library defaults to common anode.

How It Works

Each digit has 7 segments (A-G) plus a decimal point, and the 74HC595 shift register lets the Arduino control all 4 digits and their dots using only the SCLK, RCLK, and DIO pins. The display is multiplexed, meaning the digits are refreshed rapidly in sequence to appear lit at the same time. The display.loop() function handles this refresh cycle and must run constantly in loop(). You set content once with print(), and it stays on screen as long as loop() keeps executing. If you need a delay in your sketch, use display.delay(ms) instead of the standard delay(ms) so the refresh keeps running.

Code

After including the library and defining SCLK_PIN, RCLK_PIN, and DIO_PIN, you create a DIYables_4Digit7Segment_74HC595 display object and call display.begin() in setup(). You then call display.print() with an integer, float, or text string to set what shows on the display. In loop(), display.loop() must be called repeatedly to keep the digits refreshed. Other example sketches build on this same structure to show zero-padded numbers, floats with fixed decimal places, text and temperature values, blinking clock-style time, and blinking values using off() and on().

arduino-74hc595-4-digit-7-segment-display.ino - the sketch from the tutorial, unchanged.

#include <DIYables_4Digit7Segment_74HC595.h>

#define SCLK_PIN 7
#define RCLK_PIN 6
#define DIO_PIN 5

DIYables_4Digit7Segment_74HC595 display(SCLK_PIN, RCLK_PIN, DIO_PIN);

void setup() {
display.begin();
display.print(1234); // Set what to display
}

void loop() {
display.loop(); // Must be called frequently to refresh the display
}

Things That Go Wrong

If the display shows nothing, check the VCC and GND connections, confirm SCLK, RCLK, and DIO pins match your code, and make sure display.begin() is in setup() and display.loop() is in loop(). If segments show wrong characters, your module may be common cathode instead of the default common anode; pass false as the fourth constructor parameter to fix it. If the display flickers or goes blank, you are likely using delay() somewhere instead of display.delay(), which blocks the refresh cycle.

Full Tutorial

The complete tutorial, wiring diagram and code explanation: https://arduinogetstarted.com/tutorials/arduino-74hc595-4-digit-7-segment-display