7 segment display is widely used in applications such as digital clock, electronic meters and much more. 7 segment can offers display of decimal numbers and some alphabet. So 7 segment display can be used to display both decimal numbers (0-9) and hexadecimal numbers (0-F).

Usually 7 segment display is used to allow the others see more clearly on what is displayed as compared to display on LCD.

DSC06803
Front and back view of 7 Segment Display

A 7 segment display is actually made up of LED, so when we apply a voltage across the LED, it will lights up. However, one thing to take note that you must apply a current limiting resistor across LED so that you would not burn the LED. Usually LED requires only about 20mA of current, with forward voltage, 2V. Thus, the value of resistor can be determined by resistance, R = ( supply votlage – forward voltage)/(maximum current).

7seg

There are 2 types of 7 segment display available which is the Common Cathode and Common Anode. The common is the pin where all the LEDs are connected together. For a Common Anode 7 segment, you need to apply 0V (LOW) for each segment to allow the current pass through and light up the segment. The Common Cathode works in the opposite way, where you need to apply 5V (HIGH) to light up each segment.

The connection of 7 segment to Arduino is pretty simple.

7seg3

So, it is quite easy to use 7 Segment Display. Now lets look at a simple example code:


#define seg_a 2
#define seg_b 3
#define seg_c 4
#define seg_d 5
#define seg_e 6
#define seg_f 7
#define seg_g 8

void setup()
{
 pinMode(seg_a,OUTPUT);
 pinMode(seg_b,OUTPUT);
 pinMode(seg_c,OUTPUT);
 pinMode(seg_d,OUTPUT);
 pinMode(seg_e,OUTPUT);
 pinMode(seg_f,OUTPUT);
 pinMode(seg_g,OUTPUT);
 digitalWrite(seg_a,HIGH);
 digitalWrite(seg_b,HIGH);
 digitalWrite(seg_c,HIGH);
 digitalWrite(seg_d,HIGH);
 digitalWrite(seg_e,HIGH);
 digitalWrite(seg_f,HIGH);
 digitalWrite(seg_g,HIGH);
}

void loop()
{
 seg_init();
 delay(500);
 for(int i=0;i<=9;i++)
 {
 for(int j=0;j<=100;j++)
 {
 seg_disp(i);
 }
 }
}

void seg_init()
{
 digitalWrite(seg_a,LOW);
 delay(100);
 digitalWrite(seg_a,HIGH);
 digitalWrite(seg_b,LOW);
 delay(100);
 digitalWrite(seg_b,HIGH);
 digitalWrite(seg_c,LOW);
 delay(100);
 digitalWrite(seg_c,HIGH);
 digitalWrite(seg_d,LOW);
 delay(100);
 digitalWrite(seg_d,HIGH);
 digitalWrite(seg_e,LOW);
 delay(100);
 digitalWrite(seg_e,HIGH);
 digitalWrite(seg_f,LOW);
 delay(100);
 digitalWrite(seg_f,HIGH);
 digitalWrite(seg_g,LOW);
 delay(100);
 digitalWrite(seg_g,HIGH);
}

Video demonstration on 7 Segment Display. Enjoy 😀

Advertisements