Arduino UNO 7 Segment Display using a register shifter

Description of the Arduino 7-Segment Display Code with Shift Register
This Arduino code is designed to control two 7-segment displays using a shift register. The code defines three pins for communication with the shift register: dataPin (A5), clockPin (A4), and resetPin (A3). The numbers array contains the byte representations of the digits 0 through 9, which are used to display the corresponding numbers on the 7-segment displays.
In the setup() function, the data, clock, and reset pins are configured as outputs. The loop() function iterates through the numbers 0 to 9, displaying each number on the first 7-segment display while simultaneously showing the next number on the second display. The displayNumber() function handles the reset of the shift register and sends the appropriate data to each display. The shiftOut() function is responsible for shifting out the data bits to the shift register, controlling the segments that light up for each digit.
This project is a great introduction to shift registers and 7-segment display interfacing with Arduino, allowing beginners to learn about digital output control and data handling in electronics.
SCHEMATIC:

CODE:
// Define pins
const int dataPin = A5; // The D1 pin of the shift register is connected to pin A5 of the Arduino
const int clockPin = A4; // The clock input pin of the shift register is connected to pin A4 of the Arduino
const int resetPin = A3; // The reset pin of the shift register is connected to pin A3 of the Arduino
// Common cathode 7-segment display characters
byte numbers[] = {
0x3F, // 0
0x06, // 1
0x5B, // 2
0x4F, // 3
0x66, // 4
0x6D, // 5
0x7D, // 6
0x07, // 7
0x7F, // 8
0x6F // 9
};
void setup() {
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(resetPin, OUTPUT);
}
void loop() {
for (int i = 0; i < 10; i++) {
displayNumber(i, (i + 1) % 10);
delay(1000);
}
}
void displayNumber(int num1, int num2) {
digitalWrite(resetPin, LOW); // Reset shift register
digitalWrite(resetPin, HIGH);
//Send data to the first 7-segment display shiftOut(dataPin, clockPin, MSBFIRST, numbers[num1]); // Send data to the second 7-segment display shiftOut(dataPin, clockPin, MSBFIRST, numbers[num2]);
}
void shiftOut(int value) {
for (int i = 0; i < 8; i++) {
digitalWrite(dataPin, (value & (1 << (7 - i))) ? HIGH : LOW);
digitalWrite(clockPin, HIGH);
digitalWrite(clockPin, LOW);
}
}
- Arduino projects
- 7-segment display tutorial
- Shift register interfacing
- Arduino programming for beginners
- Electronics projects for beginners
- Digital display projects
- DIY electronics projects
- Arduino shiftOut function
- Controlling multiple displays with Arduino
- 7-segment display with shift register
You may also like
EmbedLab Team
Embedded systems engineer and educator. Writes weekly tutorials at EmbedLab to help beginners ship real hardware.
Related projects
Arduino and shift register
Project Description This Arduino project with code is a smart parking status display system designed to monitor and show the availability of parking spots in real-time. It leverages a 74HC165 s
Arduino traffic lights
This project implements a traffic light system with a countdown timer , designed using an Arduino microcontroller. It controls a sequence of traffic lights (red, yellow, and green) and a 7-segme
Arduino and Multiplexer
Hello In this article we will see how you can increase the output of the Arduino UNO board by using the 74HC4051 Multiplixer , we wil controll 8 LEDS! This Project is simulated using Proteu
Arduino UNO and EEPROM
Project Description: EEPROM SPI Communication with Arduino In this quick tutorial, we'll explore how to communicate with an EEPROM (Electrically Erasable Programmable Read-Only Memory) using SPI (Seri
Arduino buzzer + 4511 bcd + 7SEG
This Arduino code implements a countdown timer with a 7-segment display driven by a 4511 IC, a buzzer for an alarm, and an optional start/reset button. Here's a brief explanation: Components and



