These type of displays are found in many day-to-day applications. Let’s discuss what are they and their types. Also, its interfacing with Arduino.

A 7-segment display is the best affordable option when it comes to displaying numbers. Such display is widely used in devices that need to show only numerical information.
You may have seen the 7-segment display in counter machines, fancy shop banners, etc.
To display alphabets and symbols, opting-in for LCD would be the best choice. But the LCDs are costlier than LED displays.
So for basic needs (displaying numbers) 7-segment LED display is good to go!
In this article, you will learn the interfacing of the 7-segment display with Arduino. And, we will start with the basics so that you will understand how these displays work.
Now without any further ado, let’s start,
What is a 7-Segment Display?
A 7-segment display is nothing but a pack of seven LEDs connected together.
Each LED is called a segment. All of them are controlled individually.
I am assuming that you are familiar with the LED (Light Emitting Diode) and its working principle. If so, then you might be wondering that how these 7 LED’s are connected together to work as a display.
There are two possible ways of connecting LEDs in 7-segment displays,
- Common Cathode Configuration
- Common Anode Configuration
We will discuss these configurations later in this article.
These displays are available in various colors (Red, Blue, and Green) and sizes (0.56 to 6.5 inches). Sometimes two to four 7-segment displays are packed together to form a big display (refer to the image below)

As mentioned earlier, each LED is individually controlled, so connecting the 7-segment LED to the Arduino is a real struggle because it leads to the big wire clutter.
Few of the 7-segment displays has 8 LEDs in each pack. There is a circular LED on board, as shown in the image below,

That circular LED is for representing a decimal point in the numeral.
7-Segment Display Types
Depending upon the connection of anode and cathode of the LED 7-segment displays are divided into the two types.
We will discuss these two types and their configuration briefly,
1. Common Cathode (CC)

As the name says a lot, all the cathode terminals are connected, and anode terminals are left open.
In this case, you need to connect the cathode to the GND terminal and the anode to the 5V supply.
2. Common Anode (CA)

In this configuration, all anode terminals are connected, and cathode terminals are kept open.
To turn on the LED display, connect the anode to the 5V supply and cathode to the GND.
Interfacing 7-segment Display with Arduino

For interfacing purpose let we consider a common anode (CA) 7-segment display.
As the anode is the common terminal here so let us connect it to the 5V supply on Arduino. The remaining pins will be connected to the GPIO pins on Arduino.
We will be using separate wiring (refer to the connection diagram) for each LED segment and turn on the display in an ornate fashion.
Truth Table for 7-Segment Display
Refer to the following Truth Table to understand the code logic.

Code for turning ON all the LEDs one by one
void setup()
{
// define pins as an output pins
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
}
void loop()
{
// loop to turn on the led
for(int i=2;i<9;i++)
{
digitalWrite(i,HIGH);
delay(1000);
}
// loop to turn on the led
for(int i=2;i<9;i++)
{
digitalWrite(i,LOW);
delay(1000);
}
delay(1000);
}
There are two “for” loops in code for switching each LED segment ON and OFF.
Initially, all of the pins are high (all LEDs will glow) at the initial stage. After an interval, the first “for” loop will come into action, and each LED will start glowing one by one.
Once the cycle completes, the second “for” loop will come into action and turn of all the LED segments.
You can add more delay to see the results more clearly.
Code for displaying digits/numbers
If you are familiar with the arrays in C++, you will quickly understand the following code. But no worries if you don’t.
Copy-paste the code below without any modification.
// make an array to save Sev Seg pin configuration of numbers
int num_array[10][7] = { { 1,1,1,1,1,1,0 }, // 0
{ 0,1,1,0,0,0,0 }, // 1
{ 1,1,0,1,1,0,1 }, // 2
{ 1,1,1,1,0,0,1 }, // 3
{ 0,1,1,0,0,1,1 }, // 4
{ 1,0,1,1,0,1,1 }, // 5
{ 1,0,1,1,1,1,1 }, // 6
{ 1,1,1,0,0,0,0 }, // 7
{ 1,1,1,1,1,1,1 }, // 8
{ 1,1,1,0,0,1,1 }}; // 9
//function header
void Num_Write(int);
void setup()
{
// set pin modes
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
}
void loop()
{
//counter loop
for (int counter = 10; counter > 0; --counter)
{
delay(1000);
Num_Write(counter-1);
}
delay(3000);
}
// this functions writes values to the sev seg pins
void Num_Write(int number)
{
int pin= 2;
for (int j=0; j < 7; j++) {
digitalWrite(pin, num_array[number][j]);
pin++;
}
}
Final Words
So that is it. Do not forget to come back and share your 7-segment LED project in the comment section below.
It is an excellent Arduino based project for beginners. One can also use the 7-segment display with Arduino in projects that need to display numbers.
Thanks for reading till the end. If you have any doubts, then ask me. I will be glad to help you out.
Comments