Arduino Tutorials

7 Segment Display with Arduino

7 SEGMENT DISPLAY WITH ARDUINO

 

In this tutorial, we will be interfacing a 7 Segment Display with Arduino and learn to display digits from one to nine. Also display a count downs on 7 Segment Display

Read More about 7 Segment Display

COMPONENTS LIST

  7 Segment Display (Common Cathode)
  Arduino Uno
  Jumper Wires
  1 x Breadboard
   7 x 220 ohm resistors

7 SEGMENT DISPLAYS PINOUT

7 SEGMENT DISPLAYS PINOUT

7 SEGMENT DISPLAYS WORKING

7 segment displays consist of 7 LEDs, called segments, arranged in the shape of an “8”. The 8th segments with a dot on the right side of the digit that serves as a decimal point. Each segment is named with a letter A to G, and DP for the decimal point.7-SEGMENT DISPLAYS ARRANGEMENT

Pin Connection of 7 SEGMENT DISPLAYS with Arduino

7 Segment Pins Arduino Pins
COM1 GND
A 2
B 3
C 4
D 5
E 6
F 7
G 8
DP 9

CIRCUIT DIAGRAM OF 7 SEGMENT DISPLAYS WITH ARDUINO

CIRCUIT DIAGRAM OF 7 SEGMENT DISPLAYS WITH ARDUINO

CODE 1 FOR 7 SEGMENT DISPLAYS WITH ARDUINO

/* By this Code we only turn ON and OFF the 7 Segment LED's */ 


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 for turn ON 7-segment leds 
  for(int i=2;i<9;i++)
  {
    digitalWrite(i,HIGH);
    delay(500);
  }
  
  // loop for turn OFF 7-segment leds 
  for(int i=2; i<9; i++)
  {
    digitalWrite(i,LOW);
    delay(500);
  }
  
  delay(1000);
}

OUTPUT OF 7 SEGMENT DISPLAYS WITH ARDUINO CODE 1

Output of Code1 of 7 SEGMENT DISPLAY

CODE 2 FOR 7 SEGMENT DISPLAYS WITH ARDUINO

/* By This Code we display digits(numbers) from 0 to 9 on 7-Segment Display  */


// An array of 7 Segment Display pins configuration

int seg_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
                                       
void Digit_disp(int); //Function for Countdown

void setup() 
{ 
  // Define Pins
  pinMode(2, OUTPUT);   
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  
 
}

void loop() 
{ 
  // Loop for Counter
  for (int counter = 0; counter <= 9; counter++) 
  {
   delay(1000);
   Digit_disp(counter); 
  }
  delay(1000);
}

// this functions writes values to the sev seg pins  
void Digit_disp(int number) 
{
  int pin = 2;
  for (int j=0; j < 7; j++) 
  {
   digitalWrite(pin, seg_array[number][j]);
   pin++;
  }
}

OUTPUT OF 7 SEGMENT DISPLAYS WITH ARDUINO CODE 2

Output of Code2 of 7 SEGMENT DISPLAY

CODE 3 FOR 7 SEGMENT DISPLAYS WITH ARDUINO

/* By This Code we display countdown from 9 to 0 on 7 segment display */


// An array of 7 Segment Display pins configuration

int seg_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
                                       
void Digit_disp(int); //Function for Countdown

void setup() 
{ 
  // Define Pins
  pinMode(2, OUTPUT);   
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT); 
}

void loop() 
{ 
  // Loop for Counter
  for (int counter = 9; counter >= 0; counter--) 
  {
   delay(1000);
   Digit_disp(counter); 
  }
  delay(1000);
}

// this functions writes values to the sev seg pins  
void Digit_disp(int number) 
{
  int pin = 2;
  for (int j=0; j < 7; j++) 
  {
   digitalWrite(pin, seg_array[number][j]);
   pin++;
  }
}

Our Youtube Channel

Content Protection by DMCA.com