Arduino Nano - 74HC595 4-Digit 7-Segment Display

This walkthrough takes you step by step through using a 4-digit 7-segment display with 74HC595 shift register on the Arduino Nano. The Nano packs the same ATmega328P as the Uno into a compact, breadboard-friendly form factor - great for tight builds and prototyping.

What you will walk through:

Arduino Nano 74HC595 4-Digit 7-Segment Display

Hardware Preparation

1×Official Arduino Nano
1×Alternatively, DIYables Nano V3.0 Development Board
1×USB A to Mini-B USB cable
1×74HC595 4-digit 7-segment Display
1×Jumper Wires
1×Breadboard
1×Recommended: Screw Terminal Expansion Board for Arduino Nano
1×Recommended: Breakout Expansion Board for Arduino Nano
1×Recommended: Power Splitter for Arduino Nano

Or you can buy the following kits:

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 .

What Is the 74HC595 4-Digit 7-Segment Display?

A four-digit LED display driven by a 74HC595 shift register. Only 3 wires are needed from the Nano to control all digits and decimal points. The shift register converts serial data into parallel segment outputs, and the library takes care of multiplexing each digit in turn.

Function Pin Description
SCLK (SH_CP) Serial Clock Clocks data bits into the shift register
RCLK (ST_CP) Register Clock Latches shifted data to outputs
DIO (DS) Data Input Serial data line
VCC Power 3.3V or 5V
GND Ground Common ground

Wiring Diagram

Connect the display module to the Nano:

  • SCLK to D7
  • RCLK to D6
  • DIO to D5
  • VCC to 5V
  • GND to GND

Both the Nano and the display module share a breadboard nicely, making the wiring straightforward.

The wiring diagram between Arduino Nano and 74HC595 4-Digit 7-Segment Display

This image is created using Fritzing. Click to enlarge image

You can also build this circuit without a breadboard. Here is the same wiring:

The wiring diagram between Arduino Nano and 74HC595 4-Digit 7-Segment Display  (No Breadboard)

This image is created using Fritzing. Click to enlarge image

Do you want the wiring to stay in place? To do that, mount the Arduino Nano on a Screw Terminal Expansion Board for Arduino Nano. See the diagram below for the screw terminal version.

The wiring diagram between Arduino Nano and 74HC595 4-Digit 7-Segment Display Screw Terminal

This image is created using Fritzing. Click to enlarge image

See The best way to supply power to the Arduino Nano and other components.

Setting Up the Library

  1. Plug the Arduino Nano into your computer with a Mini-B USB cable.
  2. Open Arduino IDE. Set the board to Arduino Nano and select the matching port.
  3. Go to the Libraries panel on the left.
  4. Type "DIYables_4Digit7Segment_74HC595" in the search box. Look for the library from DIYables.
  5. Click Install. Select version 2.0.0 or later.
Arduino Nano 74HC595 4-Digit 7-Segment Display library

The library is self-contained - no extra dependencies to install.

Note: If your Nano uses an older bootloader, select ATmega328P (Old Bootloader) under Processor in the Tools menu.

Foundation Code

Every sketch built with the DIYables_4Digit7Segment_74HC595 library starts from this foundation:

#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); } void loop() { display.loop(); }

Call begin() once, then keep display.loop() running. The display value is set with print() and stays until changed. Use display.delay() instead of delay() to keep things visible during waits.

Arduino Nano Code - Display Integers

Shows a series of integers and zero-padded output.

/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-74hc595-4-digit-7-segment-display */ #include <DIYables_4Digit7Segment_74HC595.h> // Pin configuration - change these to match your wiring #define SCLK_PIN 7 // The Arduino Nano pin connected to the Serial clock pin of 7-segment display #define RCLK_PIN 6 // The Arduino Nano pin connected to the Register clock / latch pin of 7-segment display #define DIO_PIN 5 // The Arduino Nano pin connected to the Data (DS) pin of 7-segment display DIYables_4Digit7Segment_74HC595 display(SCLK_PIN, RCLK_PIN, DIO_PIN); int numbers[] = {0, 42, 1234, -5, -123, 9999}; int numCount = 6; int currentIndex = 0; bool showZeroPad = false; unsigned long lastChange = 0; void setup() { Serial.begin(9600); display.begin(); Serial.println("4-Digit 7-Segment 74HC595 - Integer Example"); } void loop() { display.loop(); // Must be called frequently to refresh the display if (millis() - lastChange >= 2000) { lastChange = millis(); if (!showZeroPad) { display.print(numbers[currentIndex]); Serial.print("Displaying: "); Serial.println(numbers[currentIndex]); currentIndex++; if (currentIndex >= numCount) { currentIndex = 0; showZeroPad = true; } } else { display.print(42, true); // Shows "0042" Serial.println("Displaying: 0042 (zero-padded)"); showZeroPad = false; } } }

Follow Along

  • Wire the display to the Nano as shown above.
  • Connect the Nano to your computer with a Mini-B USB cable.
  • Open Arduino IDE, pick the board and port, paste the code, and click Upload.
  • Open the Serial Monitor to view the output.

Cycles through 0, 42, 1234, -5, -123, 9999, and then 0042 with zero-padding.

Method Overview

Method Explanation Call Example
print(int) Show an integer (-999 to 9999) display.print(1234)
print(int, true) Integer with leading zeros display.print(42, true)
loop() Refresh the multiplexed display display.loop()

Arduino Nano Code - Display Floats

Demonstrates floats with auto and fixed decimal places.

/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-74hc595-4-digit-7-segment-display */ #include <DIYables_4Digit7Segment_74HC595.h> // Pin configuration - change these to match your wiring #define SCLK_PIN 7 // The Arduino Nano pin connected to the Serial clock pin of 7-segment display #define RCLK_PIN 6 // The Arduino Nano pin connected to the Register clock / latch pin of 7-segment display #define DIO_PIN 5 // The Arduino Nano pin connected to the Data (DS) pin of 7-segment display DIYables_4Digit7Segment_74HC595 display(SCLK_PIN, RCLK_PIN, DIO_PIN); void setup() { Serial.begin(9600); display.begin(); Serial.println("4-Digit 7-Segment 74HC595 - Float Example"); } void loop() { // Auto decimal placement display.print(1.5); // Shows " 1.5" Serial.println("Auto decimal: 1.5"); display.delay(2000); display.print(12.34); // Shows "12.34" Serial.println("Auto decimal: 12.34"); display.delay(2000); display.print(3.141); // Shows "3.141" Serial.println("Auto decimal: 3.141"); display.delay(2000); display.print(-1.2); // Shows "-1.20" Serial.println("Auto decimal: -1.20"); display.delay(2000); display.print(0.5); // Shows " 0.5" Serial.println("Auto decimal: 0.5"); display.delay(2000); // Fixed decimal places display.print(23.5, 1); // 1 decimal place: shows "23.5" Serial.println("1 decimal place: 23.5"); display.delay(2000); display.print(1.5, 2); // 2 decimal places: shows "1.50" Serial.println("2 decimal places: 1.50"); display.delay(2000); // Zero-padded display.print(1.5, 2, true); // Shows "01.50" Serial.println("2 decimal places, zero-padded: 01.50"); display.delay(2000); }

Follow Along

  • Upload the sketch and open the Serial Monitor.

Shows floats with auto decimals, then 1 and 2 fixed places, then zero-padded.

Arduino Nano Code - Text and Temperature

Shows text, degree symbol, and temperature values.

/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-74hc595-4-digit-7-segment-display */ #include <DIYables_4Digit7Segment_74HC595.h> // Pin configuration - change these to match your wiring #define SCLK_PIN 7 // The Arduino Nano pin connected to the Serial clock pin of 7-segment display #define RCLK_PIN 6 // The Arduino Nano pin connected to the Register clock / latch pin of 7-segment display #define DIO_PIN 5 // The Arduino Nano pin connected to the Data (DS) pin of 7-segment display DIYables_4Digit7Segment_74HC595 display(SCLK_PIN, RCLK_PIN, DIO_PIN); const char* texts[] = {"HELP", "Hi", "COOL", "done"}; int textCount = 4; int currentIndex = 0; int phase = 0; unsigned long lastChange = 0; void setup() { Serial.begin(9600); display.begin(); Serial.println("4-Digit 7-Segment 74HC595 - Text and Degree Example"); } void loop() { display.loop(); // Must be called frequently to refresh the display if (millis() - lastChange >= 2000) { lastChange = millis(); if (phase == 0) { // Display text strings display.print(texts[currentIndex]); Serial.print("Text: "); Serial.println(texts[currentIndex]); currentIndex++; if (currentIndex >= textCount) { currentIndex = 0; phase = 1; } } else if (phase == 1) { // Display temperature 25 degrees C display.printTemperature(25, 'C'); Serial.println("Temperature: 25 C"); phase = 2; } else if (phase == 2) { // Display temperature 72 degrees F display.printTemperature(72, 'F'); Serial.println("Temperature: 72 F"); phase = 3; } else if (phase == 3) { // Display degree symbol using string with DEGREE_CHAR constant char degStr[5]; degStr[0] = '2'; degStr[1] = '5'; degStr[2] = DEGREE_CHAR; degStr[3] = 'C'; degStr[4] = '\0'; display.print(degStr); Serial.println("String with degree: 25 deg C"); phase = 4; } else { // Display string with dots display.print("1.2.3.4"); Serial.println("Dots: 1.2.3.4"); phase = 0; } } }

Follow Along

  • Upload the sketch and open the Serial Monitor.

Displays "HELP", "Hi", "COOL", "done", then temperature values and inline dots.

Arduino Nano Code - Time

Clock-style HH.MM with blinking separator.

/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-74hc595-4-digit-7-segment-display */ #include <DIYables_4Digit7Segment_74HC595.h> // Pin configuration - change these to match your wiring #define SCLK_PIN 7 // The Arduino Nano pin connected to the Serial clock pin of 7-segment display #define RCLK_PIN 6 // The Arduino Nano pin connected to the Register clock / latch pin of 7-segment display #define DIO_PIN 5 // The Arduino Nano pin connected to the Data (DS) pin of 7-segment display DIYables_4Digit7Segment_74HC595 display(SCLK_PIN, RCLK_PIN, DIO_PIN); int hours = 12; int minutes = 30; bool colonOn = true; unsigned long lastToggle = 0; void setup() { Serial.begin(9600); display.begin(); Serial.println("4-Digit 7-Segment 74HC595 - Time Example"); Serial.println("Displaying 12:30 with blinking dot separator"); } void loop() { display.loop(); // Must be called frequently to refresh the display if (millis() - lastToggle >= 500) { lastToggle = millis(); display.printTime(hours, minutes, colonOn); colonOn = !colonOn; // Toggle dot separator every 500ms for blinking effect } }

Follow Along

  • Upload the sketch and open the Serial Monitor.

Shows 12.30 with the dot blinking every 500ms.

Troubleshoot

  1. Display stays blank - Check wiring. Verify SCLK, RCLK, DIO pin numbers match the code. Confirm begin() and loop() are in the right places.
  2. Wrong characters shown - Default is common anode. Pass false as 4th constructor argument for common cathode modules.
  3. Flickering display - Avoid delay() in your code. Use display.delay() instead.
  4. Upload fails with "not in sync" - Try selecting ATmega328P (Old Bootloader) in the Processor menu.

Platform Support

The library uses only Arduino standard APIs (pinMode, digitalWrite, millis) and works on all Arduino-compatible platforms.

※ 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!