How to interface 7 segment display with Arduino
7 Segment Display Interfacing with Arduino is easy and fun to learn topic due to its versatile use in the electronics industry because of its ease of use and readability to display numeric data in devices such as calculators, digital clocks, and measuring instruments. In this blog post, we will learn how to interface a 7 segment display with an Arduino board.
Components Required:
To interface a 7-segment display with an Arduino, you will need the following components:
- Arduino Board (UNO, Nano )
- Breadboard
- 7 segment display
- 220Ω Resistor (7)
- Jumper Wires
How 7 Segment Display Works:
A 7 segment display consists of seven individual LED segments arranged in the shape of a digit eight, with one additional segment used for a decimal point. Each segment is numbered from a to g and can be turned on or off to create any number between 0 and 9. By controlling each segment of the display, we can display any number or character we want.
Types Of 7 Segment Displays:
- Common Cathode : In this type of 7-segment display, all the anodes of the LED segments are connected together and to a positive voltage supply, while each cathode is connected to an individual pin. When a pin is set to LOW, the corresponding LED segment will light up. This type of display is commonly used in electronic devices and is easier to interface with digital circuits.
- Common Anode : In this type of 7-segment display, all the anodes of the LED segments are connected together and to a positive voltage supply, while each cathode is connected to an individual pin. When a pin is set to LOW, the corresponding LED segment will light up. This type of display is commonly used in electronic devices and is easier to interface with digital circuits.
Interfacing Common Cathode
The first step in interfacing a Common Cathode 7-segment display with an Arduino is to connect the display to the Arduino board. Here’s how you can do it:
- Connect the common cathode (-) pin of the 7-segment display to the GND pin of the Arduino.
- Connect the a, b, c, d, e, f, and g pins of the 7-segment display to digital pins 8, 9, 10, 4, 5, 7, and 6 of the Arduino, respectively.
- Connect a 220Ω resistor between each of the Arduino digital pins and the respective segment of the display.
Read More: Fun With Arduino and Buzzer: Basic, Siren, Morse, Melody
Code & Simulation:-
#define A 8 // Pin 8 of Arduino To A Segment of 7-Segment Display
#define B 9 // Pin 9 of Arduino To B Segment of 7-Segment Display
#define C 10 // Pin 10 of Arduino To C Segment of 7-Segment Display
#define D 4 // Pin 4 of Arduino To D Segment of 7-Segment Display
#define E 5 // Pin 5 of Arduino To E Segment of 7-Segment Display
#define F 7 // Pin 7 of Arduino To F Segment of 7-Segment Display
#define G 6 // Pin 6 of Arduino To G Segment of 7-Segment Display
void setup() {
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
pinMode(C, OUTPUT);
pinMode(D, OUTPUT);
pinMode(E, OUTPUT);
pinMode(F, OUTPUT);
pinMode(G, OUTPUT);
}
void loop() {
digitalWrite(A, HIGH);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
}
- In the above code, we have defined the pins used for each segment and set them as output in the
setup
function. - In the
loop
function, we have turned on theA
,B
, andC
segments, and turned off theD
,E
,F
, andG
segments to display the number 7. - The segments to be turned on are set
HIGH
for common cathode configuration
Simulation Common Cathode:
Interfacing Common Anode
The first step in interfacing a Common Anode 7-segment display with an Arduino is to connect the display to the Arduino board. Here’s how you can do it:
- Connect the common anode (+) pin of the 7-segment display to the +5v pin of the Arduino with a resistor in series.
- Connect the a, b, c, d, e, f, and g pins of the 7-segment display to digital pins 8, 9, 10, 4, 5, 7, and 6 of the Arduino, respectively.
Read More: What Is Electronics: Interactive Presentation
Code & Simulation:-
#define A 8 // Pin 8 of Arduino To A Segment of 7-Segment Display
#define B 9 // Pin 9 of Arduino To B Segment of 7-Segment Display
#define C 10 // Pin 10 of Arduino To C Segment of 7-Segment Display
#define D 4 // Pin 4 of Arduino To D Segment of 7-Segment Display
#define E 5 // Pin 5 of Arduino To E Segment of 7-Segment Display
#define F 7 // Pin 7 of Arduino To F Segment of 7-Segment Display
#define G 6 // Pin 6 of Arduino To G Segment of 7-Segment Display
void setup() {
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
pinMode(C, OUTPUT);
pinMode(D, OUTPUT);
pinMode(E, OUTPUT);
pinMode(F, OUTPUT);
pinMode(G, OUTPUT);
}
void loop() {
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
digitalWrite(D, HIGH);
digitalWrite(E, HIGH);
digitalWrite(F, HIGH);
digitalWrite(G, HIGH);
}
- In the above code, we have defined the pins used for each segment and set them as output in the
setup
function. - In the
loop
function, we have turned on theA
,B
, andC
segments, and turned off theD
,E
,F
, andG
segments to display the number 7. - The segments to be turned on are set
LOW
for common anode configuration.
Simulation Common Anode:
https://www.tinkercad.com/embed/hjjRvPYsTW1
Summary:
Interfacing a 7 segment display with an Arduino is an easy and fun way to learn about basic electronics and programming. In this blog post, we have learned how to connect a 7-segment display to an Arduino board and display a number on it. With this knowledge, you can start exploring more complex projects and applications that use 7 segment displays.