Maker.io main logo

How to Interface a Seven-Segment Display with an Arduino

2018-02-21 | By All About Circuits

License: See Original Project Arduino

Courtesy of All About Circuits

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.

a standard seven-segment display

There are two types of seven-segment displays: common anode and common cathode. The Internal structure of each of these types is nearly the identical. However, the polarity of the LEDs and common terminal are different. In most standard cathode seven-segment displays (the one we used in the experiments), all seven LEDs, in addition to a dot LED, have the cathodes connected to pins 8 and pin 3. To use this display, we must connect GROUND to pin 3 and pin 8, then connect +5V to the other pins and make each of the individual segments light up. The diagram below shows the internal structure of the common cathode seven-segment display:

internal structure of common cathode display

In contrast, the common anode display is the opposite. In a common anode display, the positive terminal of the eight-shaped LEDs are connected together. They are then connected to pin 3 and pin 8. To turn on an individual segment, one of the pins is grounded. The diagram below shows the internal structure of the common anode seven-segment display. 

internal structure of the common anode display

The dot is labeled “dp”, while the the seven segments are labelled a-g, as shown in the figure below:

SSD Configuration

You turn on the individual segments to display a particular number, as seen in the following table:

individual segments to display a particular number

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

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

Wiring Diagram 

Copy 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);

}

 

Experiment 2

Description

In this experiment, we will interface a seven-segment display with Arduino mega. We will learn to display a countdown from nine, with a one-second delay, on the seven-segment display.

Hardware Required

Experiment 1 has the same hardware required as this experiment.

Wiring Diagram

The circuit for Experiment 1 has the same writing diagram as this experiment. 

Copy Code
// 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++;
}
}

 

Download the code for this project here.

 

 

 

 

制造商零件编号 LSHD-A101
DISPLAY 7-SEG 0.3" SGL RED 10DIP
Lite-On Inc.
¥12.39
Details
制造商零件编号 A000067
ARDUINO MEGA2560 ATMEGA2560
Arduino
¥334.88
Details
制造商零件编号 TW-E41-1020
BREADBRD TERM STRP 6.5X2.14 70PC
Twin Industries
¥92.60
Details
制造商零件编号 153
JUMPER WIRE M TO M VARIOUS
Adafruit Industries LLC
¥40.29
Details
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum