7 Segment Display interfacing with Arduino Uno

In this tutorial we are going to interface 7 Segment LED Display with Arduino Uno.

Components Required :

7 Segment Led Display

For many applications, there’s no need to use a more expensive liquid crystal display to display data. A simple seven-segment display is sufficient.

If your Arduino application only needs to display numbers, consider using a seven-segment display. The seven-segment display has seven LEDs arranged in the shape of number eight. They are easy to use and cost effective.

 

7 Seg Display | Alpha ELectronz
7 Seg Display

Seven segment displays are of two types: common anode and common cathode. The Internal structure of both types is nearly the same. The difference is the polarity of the LEDs and common terminal.

In a common cathode seven-segment display (the one we used in the experiments), all seven LEDs plus a dot LED have the cathodes connected to pins 3 and pin 8. To use this display, we need to connect GROUND to pin 3 and pin 8 and,  and connect +5V to the other pins to make the individual segments light up. The following diagram shows the internal structure of common-cathode seven-segment display: 

The common anode display is the exact opposite. In a common-anode display, the positive terminal of all the eight LEDs  are connected together and then connected to pin 3 and pin 8. To turn on an individual segment, you ground one of the pins. The following diagram shows the internal structure of the common-anode seven-segment display.

The seven segment are labelled a-g, with the dot being “dp,” as shown in the figure below:

7 Segment Display | Alpha Electronz

To display a particular number, you turn on the individual segments as shown in the table below:

Digit    gfedcba

abcdefg

a

b

c

d

e

f

g

 

0             0×3F

0×7E

on

on

on

on

on

on

off

 

1             0×06

0×30

off

on

on

off

off

off

off

 

2             0×5B

0×6D

on

on

off

on

on

off

on

 

3             0×4F

0×79

on

on

on

on

off

off

on

 

4             0×66

0×33

off

on

on

off

off

on

on

 

5             0×6D

0×5B

on

off

on

on

off

on

on

 

6             0×7D

0×5F

on

off

on

on

on

on

on

 

7             0×07

0×70

on

on

on

off

off

off

off

 

8             0×7F

0×7F

on

on

on

on

on

on

on

 

9             0×6F

0×7B

on

on

on

on

off

on

on

 

A             0×77

0×77

on

on

on

off

on

on

on

 

B             0×7C

0×1F

off

off

on

on

on

on

on

 

C             0×39

0×4E

on

off

off

on

on

on

off

 

D             0×5E

0×3D

off

on

on

on

on

off

on

 

E             0×79

0×4F

on

off

off

on

on

on

on

 

F             0×71

0×47

on

off

off

off

on

on

on

 

Circuit Diagram

 

7 segment Display Arduino Circuit Diagram | Alpha Electronz
7 segment Display Arduino Circuit Diagram

we will be interfacing a 7 segment display with Arduino Uno and learn to display a count down from nine with a delay of a second, on seven segment display.

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++;
  }
}
0

Leave a Reply

Your e-mail address will not be published. Required fields are marked *