Interface a Seven-Segment Display with an Arduino¶
Often, a more expensive liquid crystal display is not necessary for displaying data in most applications. A seven-segment display is simply sufficient.
Consider using a seven-segment display if your Arduino application solely needs to display numbers. This display has seven LEDs arranged into the number eight. They are both cost-effective and easy to use. The following picture shows a standard seven-segment display.
Experiment 1¶
In this experiment, we will turn LEDs on and off in order to become familiar with how a seven-segment display functions.
Hardware Required¶
- 1 x seven-segment display (common cathode)
- 1 x Arduino MEGA 2560
- 1 x breadboard
- jumper wires
- 1K resistors
Wiring Diagram¶
In this circuit, the pins of seven-segment display connect to Arduino pins 2-9, as shown in the following table. Pins 8 and 3, the common pins, connect to GND; however, dp is left without a connection. For this experiment, it is not needed.
pins of display are connected to Arduino pins 2-9
Seven segment pins | Arduino pins | Wire Color |
---|---|---|
1(e) | 6 | orange |
2(d) | 5 | white |
3,8(COM) | GND | black |
4(c) | 4 | yellow |
5(dp) | - | - |
6(b) | 3 | red |
7(a) | 2 | blue |
9(f) | 7 | light blue |
10(g) | 8 | green |
Circuit diagram¶
Arduino Code¶
void setup()
{
// define 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()
{
// loop to turn leds od seven seg ON
for(int i=2;i<9;i++)
{
digitalWrite(i,HIGH);
delay(600);
}
// loop to turn leds od seven seg OFF
for(int i=2;i<9;i++)
{
digitalWrite(i,LOW);
delay(600);
}
delay(1000);
}