Using a 7-segment display with an Arduino microcontroller is a great way to visually represent numeric data in a project. The simplicity of the 7-segment display makes it ideal for learning basic concepts of interfacing, controlling LEDs, and handling digital outputs with a microcontroller. Each digit in the display has 7 individual segments. These segments form a recognizable digit when you turn them on in different combinations.
Objective #
The aim of this experiment is to help the user:
- To familiarize with the general working of 7-segment displays.
- To understand how to interconnect a 7-segment display to the Arduino microcontroller to display characters.
Component knowledge #
What’s a 7-Segment Display?
A 7-segment display shows numbers or certain characters as an electronic component. It consists of seven individual LEDs (segments) arranged in the shape of the number “8”. By lighting different combinations of these segments, you can display numbers (0-9) and some letters. You’ll commonly find it in devices like digital clocks, calculators, and meters.
Figure: 7-segment display
There are two main types of 7-segment displays:
- Common Cathode (CC): They connect all the cathodes (negative terminals) of the LEDs together.
- Common Anode (CA): You connect all the anodes (positive terminals) together.
Figure: Common anode and common cathode configuration
- Pin Identification of a 7-Segment Display
A typical 7-segment display has 10 pins: 7 pins for the segments (A-G), 1 for the decimal point, and 2 common pins (anode or cathode). You’ll label the segments A to G, and the decimal point DP.
A: Top segment
B: Top-right segment
C: Bottom-right segment
D: Bottom segment
E: Bottom-left segment
F: Top-left segment
G: Middle segment
DP: Decimal point
Depending on whether the display is common cathode or common anode, you’ll connect the common pin (DP) to either ground (GND) (for CC) or power (+5V) (for CA).
Here’s a typical pinout for a 7-segment display:
| Pin | Segment | Description |
| 1 | E | Bottom-left segment |
| 2 | D | Bottom segment |
| 3 | DP | Decimal point |
| 4 | C | Bottom-right segment |
| 5 | G | Middle segment |
| 6 | Common (Anode or Cathode) | Common pin |
| 7 | B | Top-right segment |
| 8 | A | Top segment |
| 9 | F | Top-left segment |
| 10 | Common (Anode or Cathode) | Common pin |
- How to Test a 7-Segment Display
- Identify the Type (Common Cathode or Common Anode)
Before testing, determine whether you are dealing with a common cathode (CC) or common anode (CA) display. You can usually find this in the datasheet of the component or determine it using a multimeter.
- Test with a Multimeter (Continuity Mode)
To test the individual segments of the display:
- Set the multimeter to diode testing mode (or continuity mode).
- For Common Cathode:
- Connect the black probe (negative) to one of the common cathode pins (Pin 6 or Pin 10).
- Use the red probe (positive) to touch the other pins (A to DP). The corresponding segment should light up.
- For Common Anode:
- Connect the red probe (positive) to one of the common anode pins (Pin 6 or Pin 10).
- Use the black probe (negative) to touch the other pins (A to DP). The corresponding segment should light up.
If the appropriate segment lights up, that means the segment is working.
- Test with a Microcontroller
You can also test the display using a microcontroller (like Arduino). Here’s how you can wire and program it to display numbers:
- Connect the common pin to ground (for CC) or power (for CA).
- Connect the segment pins (A-G, DP) to digital pins on the microcontroller.
- Use a simple program to light the segments in the desired pattern to display numbers.
Materials to use #
Circuit diagram #
Figure: Schematic diagram
Figure: Components used to make connection on the board
Arduino Codes #
int pinA = 2;
int pinB = 3;
int pinC = 4;
int pinD = 5;
int pinE = 6;
int pinF = 7;
int pinG = 8;
int D1 = 9;
int D2 = 10;
int D3 = 11;
int D4 = 12;
void setup() {
pinMode(pinA, OUTPUT);
pinMode(pinB, OUTPUT);
pinMode(pinC, OUTPUT);
pinMode(pinD, OUTPUT);
pinMode(pinE, OUTPUT);
pinMode(pinF, OUTPUT);
pinMode(pinG, OUTPUT);
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
pinMode(D4, OUTPUT);
}
void loop() {
digitalWrite(D1, HIGH);
digitalWrite(D2, HIGH);
digitalWrite(D3, HIGH);
digitalWrite(D4, HIGH);
delay(10);
digitalWrite(pinA, LOW); //0
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
digitalWrite(pinE, LOW);
digitalWrite(pinF, LOW);
digitalWrite(pinG, HIGH);
delay(1000);// wait for a second
digitalWrite(D1, HIGH);
digitalWrite(D2, HIGH);
digitalWrite(D3, HIGH);
digitalWrite(D4, HIGH);
digitalWrite(pinA, HIGH); //1
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, HIGH);
delay(1000);// wait for a second
digitalWrite(D1, HIGH);
digitalWrite(D2 , HIGH);
digitalWrite(D3, HIGH);
digitalWrite(D4, HIGH);
digitalWrite(pinA, LOW); //2
digitalWrite(pinB, LOW);
digitalWrite(pinC, HIGH);
digitalWrite(pinD, LOW);
digitalWrite(pinE, LOW);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, LOW);
delay(1000);// wait for a second
digitalWrite(D1, HIGH);
digitalWrite(D2, HIGH);
digitalWrite(D3, HIGH);
digitalWrite(D4, HIGH);
digitalWrite(pinA, LOW); //3
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, LOW);
delay(1000);
}
Code knowledge #
This code controls a 4-digit 7-segment display using an Arduino. The program lights up specific segments to display digits (0, 1, 2, and 3) on the 7-segment display.
int pinA = 2;
int pinB = 3;
int pinC = 4;
int pinD = 5;
int pinE = 6;
int pinF = 7;
int pinG = 8;
int D1 = 9;
int D2 = 10;
int D3 = 11;
int D4 = 12;
pinA, pinB, pinC, pinD, pinE, pinF, pinG represent the segments of a single 7-segment display. These pins control each segment (A to G) to form different digits.
D1, D2, D3, D4 represent the digit select pins. These pins select which of the four digits on the display is active.
void setup() {
pinMode(pinA, OUTPUT);
pinMode(pinB, OUTPUT);
pinMode(pinC, OUTPUT);
pinMode(pinD, OUTPUT);
pinMode(pinE, OUTPUT);
pinMode(pinF, OUTPUT);
pinMode(pinG, OUTPUT);
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
pinMode(D4, OUTPUT);
}
In these codes, the setup() function defines all pins as output pins because they control the segments and digits of the display.
void loop()
{
digitalWrite(D1, HIGH);
digitalWrite(D2, HIGH);
digitalWrite(D3, HIGH);
digitalWrite(D4, HIGH);
delay(1000);
The loop() function continuously cycles through displaying the numbers 0, 1, 2, and 3 on the 7-segment display.
The above block turns on all four digit select pins (D1, D2, D3, D4). Setting the digits to HIGH prepares them to display content. The delay(10) function adds a short pause before updating the segments.
digitalWrite(pinA, LOW); //0
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
digitalWrite(pinE, LOW);
digitalWrite(pinF, LOW);
digitalWrite(pinG, HIGH);
delay(1000);// wait for a second
This block displays the number 0 on the 7-segment display by turning ON segments A, B, C, D, E, and F (setting them to LOW) and turning OFF segment G (setting it to HIGH). This combination lights up the segments in the shape of the digit 0. The delay(1000) adds a 1-second pause before moving to the next digit.
digitalWrite(D1, HIGH);
digitalWrite(D2, HIGH);
digitalWrite(D3, HIGH);
digitalWrite(D4, HIGH);
digitalWrite(pinA, HIGH); //1
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, HIGH);
delay(1000);// wait for a second
To display the number 1, the system turns ON (sets to LOW) only segments B and C. It turns OFF (sets to HIGH) all other segments, forming the shape of the digit 1.
Note: This pattern continues for the seven segment display to display 2 and 3.
Check out our YouTube video — it gives you a quick, easy-to-follow overview.