Ad Code

Responsive Advertisement

Ticker

6/recent/ticker-posts

7 - Segment Display with Arduino

7 - Segment Display with Arduino





Fig: Seven Segment Display


 In this tutorial i will discuss how to interface a seven segment display with Arduino UNO. You can also check out my previous post on Interfacing Arduino with Relay.


A 7 Segment LED Display is a electronic device that contains an array of 8 individual LEDs. Each of the 8 segments that make up the display can be either be on the ON state or the OFF state. Depending on which LEDs are lit determines the character which is displayed on the LED. The LED can be made to show  numerical digits from 0-9 and some characters. The versatility of a 7 segment display lies in the fact that it can be a numerical value indicator. LED displays are used in all types of products, including alarm clocks, scoreboards, and all other signs showing character outputs.

Types of 7 - Segment Displays:

Based on wiring and connection, there are two types of 7 - Segment display which are:

  • Common - Cathode Display
  • Common - Anode  Display
LEDs have two terminals one is referred to as the Anode and the other is the Cathode. The Anode is the terminal that is usually connected to the positive voltage terminal  while the Cathode is connected to the negative terminal of the supply. When the Cathodes of the array of eight (8) LEDs are connected together, such is referred to as a Common -Cathode Display but when the Anode terminals are all connected together we have the Common Anode Display.

Fig a: Common - Cathode Display



Fig b: Common - Anode Display


In this tutorial we will be considering the common cathode display.

The way the 7-Segment display works with the Arduino is that every segment's terminal is connected to a unique I/O pin and once a logic "1" or an "HIGH" is sent out of that pin, that segment is lit. If we want to display the digit "7", all we have to do is to turn ON segments a, b  and c of the 7 - segment display. In the code below we would be connecting segments (a, b, c, d, e, f, g) to pins (13,12,11,10,9,8,7) respectively and we use a switch-case statement to form the pattern by turning appropriate segment ON and others OFF.

CODE:

/*
    Name:     7 - Segment display with Arduino
    Author   : Daniel Oluwole
                       (C) 2020 Danitronics
                       danieloluwole51@gmail.com, danieloluwole51@yahoo.com
    Mobile:    +234 8188508765.
 
    Notes    :   Our aim is to display numbers 0 -9 on a 7 - segment display
  
*/

#define segment_A 13  //connecting segment A to PIN13

#define segment_B 12  // connecting segment B to PIN12

#define segment_C 11  // connecting segment C to PIN11

#define segment_D 10  // connecting segment D to PIN10

#define segment_E 9  // connecting segment E to PIN9

#define segment_F 8 // connecting segment F to PIN8

#define segment_G 7  // connecting segment G to PIN7

                int DIGIT = 0; //count integer for 0-9 increment

void setup()
      //make pin 7 to 13 output pins using a for loop
        
 for (int i=7;i<14;i++)
                 {
                                 
                       pinMode(i, OUTPUT);// taking all pins from 7 - 13 as output
                }
              delay(1000);
}

void loop()
{
switch (DIGIT)
 {
                case 0: 
   
                       //when count value is zero show”0” on disp
                digitalWrite(segment_A, HIGH);

                digitalWrite(segment_B, HIGH);

                digitalWrite(segment_C, HIGH);

                digitalWrite(segment_D, HIGH);

                digitalWrite(segment_E, HIGH);

                digitalWrite(segment_F, HIGH);

                digitalWrite(segment_G, LOW);

                break;

                case 1:// when count value is 1 show”1” on disp

                digitalWrite(segment_A, LOW);

                digitalWrite(segment_B, HIGH);

                digitalWrite(segment_C, HIGH);

                digitalWrite(segment_D, LOW);

                digitalWrite(segment_E, LOW);

                digitalWrite(segment_F, LOW);

                digitalWrite(segment_G, LOW);

                break;

                case 2:// when count value is 2 show”2” on disp

                digitalWrite(segment_A, HIGH);

                digitalWrite(segment_B, HIGH);

                digitalWrite(segment_C, LOW);

                digitalWrite(segment_D, HIGH);

                digitalWrite(segment_E, HIGH);

                digitalWrite(segment_F, LOW);

                digitalWrite(segment_G, HIGH);

                break;

                case 3:// when count value is 3 show”3” on disp

                digitalWrite(segment_A, HIGH);

                digitalWrite(segment_B, HIGH);

                digitalWrite(segment_C, HIGH);

                digitalWrite(segment_D, HIGH);

                digitalWrite(segment_E, LOW);

                digitalWrite(segment_F, LOW);

                digitalWrite(segment_G, HIGH);

                break;

                case 4:// when count value is 4 show”4” on disp

                digitalWrite(segment_A, LOW);

                digitalWrite(segment_B, HIGH);

                digitalWrite(segment_C, HIGH);

                digitalWrite(segment_D, LOW);

                digitalWrite(segment_E, LOW);

                digitalWrite(segment_F, HIGH);

                digitalWrite(segment_G, HIGH);

                break;

                case 5:// when count value is 5 show”5” on disp

                digitalWrite(segment_A, HIGH);

                digitalWrite(segment_B, LOW);

                digitalWrite(segment_C, HIGH);

                digitalWrite(segment_D, HIGH);

                digitalWrite(segment_E, LOW);

                digitalWrite(segment_F, HIGH);

                digitalWrite(segment_G, HIGH);

                break;

                case 6:// when count value is 6 show”6” on disp

                digitalWrite(segment_A, HIGH);

                digitalWrite(segment_B, LOW);

                digitalWrite(segment_C, HIGH);

                digitalWrite(segment_D, HIGH);

                digitalWrite(segment_E, HIGH);

                digitalWrite(segment_F, HIGH);

                digitalWrite(segment_G, HIGH);

                break;

                case 7:// when count value is 7 show”7” on disp

                digitalWrite(segment_A, HIGH);

                digitalWrite(segment_B, HIGH);

                digitalWrite(segment_C, HIGH);

                digitalWrite(segment_D, LOW);

                digitalWrite(segment_E, LOW);

                digitalWrite(segment_F, LOW);

                digitalWrite(segment_G, LOW);

                break;

                case 8:// when count value is 8 show”8” on disp

                digitalWrite(segment_A, HIGH);

                digitalWrite(segment_B, HIGH);

                digitalWrite(segment_C, HIGH);

                digitalWrite(segment_D,HIGH);
                digitalWrite(segment_E, HIGH);

                digitalWrite(segment_F, HIGH);

                digitalWrite(segment_G, HIGH);

                break;

                case 9:// when count value is 9 show”9” on disp

                digitalWrite(segment_A, HIGH);

                digitalWrite(segment_B, HIGH);

                digitalWrite(segment_C, HIGH);

                digitalWrite(segment_D, HIGH);

                digitalWrite(segment_E, LOW);

                digitalWrite(segment_F, HIGH);

                digitalWrite(segment_G, HIGH);

                break;

                break;

                }

                if (DIGIT<10)

                {

                                DIGIT++;

                                delay(1000);///increment count integer for every second

                }

                if (DIGIT==10)

                {

                                DIGIT=0;// if count integer value is equal to 10, reset it to zero.

                                delay(1000);

                }

}
Next  Post

Post a Comment

0 Comments

Ad Code

Responsive Advertisement