This display is used in many applications that we see in our life such as calculators, digital clocks, and much more, so do you want to learn how to interface 7 segment display with Arduino?
In this tutorial, you will learn in-depth everything you need to know about seven segment how to interface with Arduino, and also pinout, sizes, types, truth table, and the code to count from 0 to 9 even you will see the output at the end of this tutorial.
So stay with us to know all the details you need.
7 Segment Display
7 segment display is an electronic device consisting of 7 LEDs connected to each other in the shape of the number ‘8’.Each of the 7 LEDs is called a segment named from A-G, all of them controlled to display numbers in both (Decimal and Hex). there is an additional LED called (DP) used as a decimal point.
7 Segment Display Pinout
Seven segment display consists of 10 Pins, 8 of them are LEDs which are (A, B, C, D, E, F, G, DP) pins, and 2 of them are common(Com) pins in the middle of the 7 segment.
Take a look at the picture down below and let’s talk about them in detail.
A-G: all of these pins are connected to the Arduino digital pins to display any number you want, by controlling the LEDs that are connected to each pin to be on or off.
DP: it is a segment decimal point, it’s also connected to the Arduino digital pins.
Com: this is a common pin connected to GND or +5V depending on which type of 7 segments you are using Common Cathode(CC) or Common Anode(CA) which you will know when we interface 7 segment with Arduino in this tutorial.
7 Segment Display Sizes
7 segment display mainly it is a single digit, but by multiplexing a single digit it can be provided in several sizes such as:
- ٍSingle digit 7 segment display
- 2 digit 7 segment display
- 3 digit 7 segment display
- 4 digit 7 segment display
7 Segment Display Types
There are different types of 7 segment displays: the first one is Common Anode(CA) and the second is Common Cathode(CC).
Common Cathode vs Common Anode
The main difference between Common Cathode and Common Anode is that the Common Cathode has all of the LEDs cathodes connected together to the GND, and the Common Anode is the opposite it has all of the LEDs Anodes connected together to the +5V.
7 Segment Display Common Anode
In the 7 segment display Common Cathode type all of the LEDs cathodes are connected together to the GND or Low (0 Logic). And each LED (segment) will be lit by applying +5V or High(1 Logic) to the LED’s anode for each one (A-G).
Let’s just say we need to display the number ‘5’ so we must apply +5V (1 Logic) for these pins (A, C, D, F, G).
7 Segment Display Common Cathode
In the 7 segment display Common Anode type all of the LEDs Anodes are connected together to the +5V or High(1 Logic). And each LED (segment) will be lit by applying GND or Low (0 Logic) to the LED’s cathode for each one (A-G).
Let’s just say we need to display the number ‘4’ so we must apply GND (0 Logic) for these pins (B, C, F, G).
Truth Table For 7 Segment Display
The truth table guides you with which segment needs to be on or off to display numbers (0-9) or characters (A-F), for each type: Common Cathode 7 segment display and Common Anode 7 segment display.
Common Anode 7 Segment Display Truth Table
This is a truth table for Common Anode seven segment display, which shows you how to display each number in both (Decimal and Hex).
Common Cathode 7 Segment Display Truth Table
This is a truth table for Common Cathode seven segment display that shows you how to display each number in both (Decimal and Hex) which is the opposite of Common Anode.
7 Segment Display Datasheet
This file down below is 7 segment display datasheet you can download it.
7 Segment Display With Arduino
To interface 7 segment with Arduino Uno, you need to connect (A-G) & DP with the digital pins of the Arduino with resistors between them, and the (GND or +5V) Arduino pin with the (com) of the 7 segment display depending on which type you are using Common Anode or Common Cathode.
Parts Requirement:
- Arduino Uno.
- 7 segment display Common Cathode or Common Anode.
- Breadboard.
- Hook-up wires.
- (8) 220-ohm resistor.
Common Anode 7 Segment Display With Arduino
To connect the Common Anode 7 segment display with Arduino Uno, you need to connect (A, B, C, D, E, F, G, DP) in the 7 segment with the ( 2, 3, 4, 5, 6, 7, 8, 9) Arduino digital pins and the (Com) pin with the +5V pin in the Arduino.
Look at the circuit diagram down below to see all the detail.
Common Cathode 7 Segment Display With Arduino
To connect the Common Cathode 7 segment display with Arduino Uno, you need to connect (A, B, C, D, E, F, G, DP) in the 7 segment with the ( 2, 3, 4, 5, 6, 7, 8, 9) Arduino digital pins and the (Com) pin with the GND pin in the Arduino.
Look at the circuit diagram down below to see all the detail.
7 Segment Display Arduino Code
Now after you connect 7 segment display with Arduino you need to write the code or copy it so that you can use it on your project, and you can see the output in this tutorial after the code.
Common Anode 7 Segment Display Arduino Code
This is the Arduino code for the Common Anode 7 segment display, which counts numbers from 0 to 9.
#define A 2
#define B 3
#define C 4
#define D 5
#define E 6
#define F 7
#define G 8
#define DP 9
void setup()
{
//make pin 'A' as an output
pinMode (A, OUTPUT);
//make pin 'B' as an output
pinMode (B, OUTPUT);
//make pin 'C' as an output
pinMode (C, OUTPUT);
//make pin 'D' as an output
pinMode (D, OUTPUT);
//make pin 'E' as an output
pinMode (E, OUTPUT);
//make pin 'F' as an output
pinMode (F, OUTPUT);
//make pin 'G' as an output
pinMode (G, OUTPUT);
//make pin 'DP' as an output
pinMode (DP, OUTPUT);
}
void loop()
{
//Display 0 then 1s delay
zero();
delay(1000);
//Display 1 then 1s delay
one();
delay(1000);
//Display 2 then 1s delay
two();
delay(1000);
//Display 3 then 1s delay
three();
delay(1000);
//Display 4 then 1s delay
four();
delay(1000);
//Display 5 then 1s delay
five();
delay(1000);
//Display 6 then 1s delay
six();
delay(1000);
//Display 7 then 1s delay
seven();
delay(1000);
//Display 8 then 1s delay
eight();
delay(1000);
//Display 9 then 1s delay
nine();
delay(1000);
}
//generating number '0'
void zero()
{
digitalWrite (A, LOW);
digitalWrite (B, LOW);
digitalWrite (C, LOW);
digitalWrite (D, LOW);
digitalWrite (E, LOW);
digitalWrite (F, LOW);
digitalWrite (G, HIGH);
digitalWrite (DP, HIGH);
}
//generating number '1'
void one()
{
digitalWrite (A, HIGH);
digitalWrite (B, LOW);
digitalWrite (C, LOW);
digitalWrite (D, HIGH);
digitalWrite (E, HIGH);
digitalWrite (F, HIGH);
digitalWrite (G, HIGH);
digitalWrite (DP, HIGH);
}
//generating number '2'
void two()
{
digitalWrite (A, LOW);
digitalWrite (B, LOW);
digitalWrite (C, HIGH);
digitalWrite (D, LOW);
digitalWrite (E, LOW);
digitalWrite (F, HIGH);
digitalWrite (G, LOW);
digitalWrite (DP, HIGH);
}
//generating number '3'
void three()
{
digitalWrite (A, LOW);
digitalWrite (B, LOW);
digitalWrite (C, LOW);
digitalWrite (D, LOW);
digitalWrite (E, HIGH);
digitalWrite (F, HIGH);
digitalWrite (G, LOW);
digitalWrite (DP, HIGH);
}
//generating number '4'
void four()
{
digitalWrite (A, HIGH);
digitalWrite (B, LOW);
digitalWrite (C, LOW);
digitalWrite (D, HIGH);
digitalWrite (E, HIGH);
digitalWrite (F, LOW);
digitalWrite (G, LOW);
digitalWrite (DP, HIGH);
}
//generating number '5'
void five()
{
digitalWrite (A, LOW);
digitalWrite (B, HIGH);
digitalWrite (C, LOW);
digitalWrite (D, LOW);
digitalWrite (E, HIGH);
digitalWrite (F, LOW);
digitalWrite (G, LOW);
digitalWrite (DP, HIGH);
}
//generating number '6'
void six()
{
digitalWrite (A, LOW);
digitalWrite (B, HIGH);
digitalWrite (C, LOW);
digitalWrite (D, LOW);
digitalWrite (E, LOW);
digitalWrite (F, LOW);
digitalWrite (G, LOW);
digitalWrite (DP, HIGH);
}
//generating number '7'
void seven()
{
digitalWrite (A, LOW);
digitalWrite (B, LOW);
digitalWrite (C, LOW);
digitalWrite (D, HIGH);
digitalWrite (E, HIGH);
digitalWrite (F, HIGH);
digitalWrite (G, HIGH);
digitalWrite (DP, HIGH);
}
//generating number '8'
void eight()
{
digitalWrite (A, LOW);
digitalWrite (B, LOW);
digitalWrite (C, LOW);
digitalWrite (D, LOW);
digitalWrite (E, LOW);
digitalWrite (F, LOW);
digitalWrite (G, LOW);
digitalWrite (DP, HIGH);
}
//generating number '9'
void nine()
{
digitalWrite (A, LOW);
digitalWrite (B, LOW);
digitalWrite (C, LOW);
digitalWrite (D, LOW);
digitalWrite (E, HIGH);
digitalWrite (F, LOW);
digitalWrite (G, LOW);
digitalWrite (DP, HIGH);
}
7 Segment Display 0 to 9 Code Output
This is the output that you will see when you follow all the steps before.
Frequently Asked Questions
How does a 7 segment display work?
7 segment display works by illuminating the 7 LEDs which are connected to each other in the shape of the number ‘8’. Each of the 7 LEDs is called a segment named from A-G, all of them controlled to display numbers in both (Decimal and Hex).
How to connect 7 segment display?
To connect 7 segment display with Arduino you need to connect (A, B, C, D, E, F, G, DP) in the 7 segment with the ( 2, 3, 4, 5, 6, 7, 8, 9) Arduino digital pins and the (Com) pin with the +5V pin in the Arduino if it is Common Anode type or with the GND for Common Cathode.
Do 7 segment displays need resistors?
7 segment displays need a resistor for each LED in order to protect 7 segment from overcurrent, you need at least 100 Ω but the recommended value is 220 Ω. The lower the resistor the brighter the 7 segment will be.
What are the types of 7 segment display?
There are two types of 7 segment display: Common Cathode and Common Anode the main difference between that the Common Cathode has all of the LEDs cathodes connected together to the GND, and the Common Anode is the opposite it has all of the LEDs Anodes connected together to the +5V.
How many pins are in a 7 segment display?
There are 10 pins in the 7-segment display, 8 of them are LEDs which are (A, B, C, D, E, F, G, DP)pins, and 2 of them are common(Com) pins in the middle of the 7 segment.
Thank you for being with us, I hope you find everything you need about a 7 segment display with Arduino if you are passionate about Arduino and want to learn more.
ROBOSANS is the best place to start your learning journey with a brief Arduino tutorial and to the point.
Do you want to learn more? read these articles down below.
Interfacing 4×4 Keypad with Arduino
16×2 LCD Interfacing With Arduino
Sources: