How to connect seven(7) segment display on Arduino?

How many times did you see a clock displaying minutes, hours and seconds and start wondering how it can be possible to display a clock with such a large display?

How many times did you see a movie where someone needs to deactivate a bomb? The hero watches the display as time ticks by, each second more precious than the previous one.

Well, if you notice, all those bombs in movies have seven-segment displays.

It has to be! Otherwise, how could a hero possibly know how much time he has left?

The seven segments displays are the oldest yet one of the efficient types of display used in embedded applications.

This display has nothing more than 8 LEDs inside it.

These 8 LEDs are separated into each segment which can be named as a, b, c, d, e, f, g, GND. These entire 8 segment LEDs have one end of their pins pulled out of the module as shown below and the other ends are connected together and pulled out as the Common pin.

So to make an LED of a particular segment glow we just have to power a common pin along with the segment pin.

This way we can power more than one segment at a time to represent the numeric number 0-9 and also few Alphabets as well.

The numerical digits 0 to 9 are the most common characters displayed on seven-segment displays. The most common patterns used for each of these is:

The numerals 6 and 9 may be represented by two different glyphs on seven-segment displays, with or without a 'tail', and the numeral 7 also has two versions, with or without segment F:

Seven-segment displays are widely used in:

  • Digital clocks
  • Electronic meters
  • Basic calculators
  • Other electronic devices that display numerical


    This circuit will display numbers from 0 to 9 and vice-versa And it will be done in loops means it will continue until you can stop the whole system to shut down.

    Sketch for Control of 7-Segment Display

    It will display numbers upward and downward. This sketch is used to test your 7 segment.

        int a = 2;  //For displaying segment "a"
        int b = 3;  //For displaying segment "b"
        int c = 4;  //For displaying segment "c"
        int d = 5;  //For displaying segment "d"
        int e = 6;  //For displaying segment "e"
        int f = 7;  //For displaying segment "f"
        int g = 8;  //For displaying segment "g"
        void setup() {               
          pinMode(a, OUTPUT);  //A
          pinMode(b, OUTPUT);  //B
          pinMode(c, OUTPUT);  //C
          pinMode(d, OUTPUT);  //D
          pinMode(e, OUTPUT);  //E
          pinMode(f, OUTPUT);  //F
          pinMode(g, OUTPUT);  //G
        void displayDigit(int digit)
         //Conditions for displaying segment a
         if(digit!=1 && digit != 4)
         //Conditions for displaying segment b
         if(digit != 5 && digit != 6)
         //Conditions for displaying segment c
         if(digit !=2)
         //Conditions for displaying segment d
         if(digit != 1 && digit !=4 && digit !=7)
         //Conditions for displaying segment e 
         if(digit == 2 || digit ==6 || digit == 8 || digit==0)
         //Conditions for displaying segment f
         if(digit != 1 && digit !=2 && digit!=3 && digit !=7)
         if (digit!=0 && digit!=1 && digit !=7)
        void turnOff()
        void loop() {
         for(int i=0;i<10;i++)

    LED based 7-segment displays are very popular amongst Electronics hobbyists as they are easy to use and easy to understand.

    Demonstration Photos

    And has many applications as we discussed above.

    As putting the end of our tutorial, I would like to give a simple exercise you remember we said in the introduction that we can also display alphabets, how about we display some alphabets?