Arduino with 7 segment display
Arduino based projects Electronics tutorial

Seven Segment Display with Arduino Interfacing 0 to 99 counter

Hey folks, in this article we will see what is a seven-segment display with Arduino Interfacing. How to connect a seven-segment display directly to the Arduino without any decoder IC. Also, we will code Arduino to count Arduino from 0 to 99 on seven segment display. Let’s get started.

What is a seven-segment display?

A seven segment display is an electronic display device. It is used to display decimal numerical and alphabets from A to F. It is an alternative and cheap display as compared to other dot matrix displays and LCD displays.

2 seven segment display arduino

 

7 segment display is widely used in various electronic devices like a digital clock, timer, counter, basic calculators, electronic meters, currency notes counter, and many more than display decimal output.

Why it is called a 7 segment display?

A seven segment display contains 7 different LED lights which are arranged in the form of number 8. As shown in the figure you can see that this structure requires 7 individual LEDs. They are arranged in such a manner that they can make the show any number from 0 to 9 and some alphabets.

Each segment contains one LED. All the LEDs are either commonly connected to the ground or supply. Also, there is a small dot LED it is used to show decimals. In some 7 segment displays, it is not present and they don’t show decimals.

common anode Seven Segment Displays

Types of seven segment display:

There are two types of seven segment displays.

Common Anode 7 segment display:

The anodes of all the LEDs are commonly connected together to +Vcc. And their -Ve terminal is used to control them.

Common cathode 7 segment display:

The cathodes of all the LEDs are commonly connected together to -Vcc. And their +Ve terminal is used to control them.

A common Anode 7 segment display is as shown in the figure.

Seven Segment Display

Now we will see how to interface 7 segment display with the Arduino Uno board.

Seven Segment Display with Arduino

In the above image two, seven segment displays are interfaced with Arduino. They are configured as 0 to 99 up counter. A program is running on Arduino to count from 0 to 99. In the first 7 segment display when the first counter completes count from 0 to 9, the count of the next counter gets incremented by one.

Arduino with 7 segment display

Here is the code for Arduino:

void setup()
{
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(A0,OUTPUT);
pinMode(A1,OUTPUT);
pinMode(A2,OUTPUT);
pinMode(A3,OUTPUT);
pinMode(A4,OUTPUT);
pinMode(A5,OUTPUT);
pinMode(9,OUTPUT);
}
void loop()
{
for(int i=0;i<10;i++) 
{
switch(i)
{
case 0:
digitalWrite(A0,LOW);
digitalWrite(A1,LOW);
digitalWrite(A2,LOW);
digitalWrite(A3,LOW); //0
digitalWrite(A4,LOW);
digitalWrite(A5,LOW);
digitalWrite(9,HIGH);

break;

case 1: 
digitalWrite(A0,HIGH);
digitalWrite(A1,LOW);
digitalWrite(A2,LOW);
digitalWrite(A3,HIGH); //1
digitalWrite(A4,HIGH);
digitalWrite(A5,HIGH);
digitalWrite(9,HIGH); 

break;

case 2: 
digitalWrite(A0,LOW);
digitalWrite(A1,LOW);
digitalWrite(A2,HIGH); 
digitalWrite(A3,LOW); //2
digitalWrite(A4,LOW);
digitalWrite(A5,HIGH);
digitalWrite(9,LOW); 

break;

case 3: 
digitalWrite(A0,LOW);
digitalWrite(A1,LOW);
digitalWrite(A2,LOW); 
digitalWrite(A3,LOW); //3
digitalWrite(A4,HIGH);
digitalWrite(A5,HIGH);
digitalWrite(9,LOW); 

break; 

case 4: 
digitalWrite(A0,HIGH);
digitalWrite(A1,LOW);
digitalWrite(A2,LOW); 
digitalWrite(A3,HIGH); //4
digitalWrite(A4,HIGH);
digitalWrite(A5,LOW);
digitalWrite(9,LOW); 

break;

case 5: 
digitalWrite(A0,LOW);
digitalWrite(A1,HIGH);
digitalWrite(A2,LOW); 
digitalWrite(A3,LOW); //5
digitalWrite(A4,HIGH);
digitalWrite(A5,LOW);
digitalWrite(9,LOW); 

break; 

case 6: 
digitalWrite(A0,LOW);
digitalWrite(A1,HIGH);
digitalWrite(A2,LOW); 
digitalWrite(A3,LOW); //6
digitalWrite(A4,LOW);
digitalWrite(A5,LOW);
digitalWrite(9,LOW); 

break;

case 7: 
digitalWrite(A0,LOW);
digitalWrite(A1,LOW);
digitalWrite(A2,LOW); 
digitalWrite(A3,HIGH); //7
digitalWrite(A4,HIGH);
digitalWrite(A5,HIGH);
digitalWrite(9,HIGH); 

break;

case 8: 
digitalWrite(A0,LOW);
digitalWrite(A1,LOW);
digitalWrite(A2,LOW); 
digitalWrite(A3,LOW); //8
digitalWrite(A4,LOW);
digitalWrite(A5,LOW);
digitalWrite(9,LOW); 

break;

case 9: 
digitalWrite(A0,LOW);
digitalWrite(A1,LOW);
digitalWrite(A2,LOW); 
digitalWrite(A3,LOW); //9
digitalWrite(A4,HIGH);
digitalWrite(A5,LOW);
digitalWrite(9,LOW); 

break; 
}
for(int j=0;j<10;j++) 
{
switch(j)
{
case 0:
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW); //0
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,HIGH);
delay(700); 
break;

case 1: 
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,HIGH); //1
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
digitalWrite(8,HIGH); 
delay(700); 
break;

case 2: 
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,HIGH); 
digitalWrite(5,LOW); //2
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
digitalWrite(8,LOW); 
delay(700); 
break;

case 3: 
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW); 
digitalWrite(5,LOW); //3
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
digitalWrite(8,LOW); 
delay(700); 
break; 

case 4: 
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
digitalWrite(4,LOW); 
digitalWrite(5,HIGH); //4
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
digitalWrite(8,LOW); 
delay(700); 
break;

case 5: 
digitalWrite(2,LOW);
digitalWrite(3,HIGH);
digitalWrite(4,LOW); 
digitalWrite(5,LOW); //5
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
digitalWrite(8,LOW); 
delay(700); 
break; 

case 6: 
digitalWrite(2,LOW);
digitalWrite(3,HIGH);
digitalWrite(4,LOW); 
digitalWrite(5,LOW); //6
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW); 
delay(700); 
break;

case 7: 
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW); 
digitalWrite(5,HIGH); //7
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
digitalWrite(8,HIGH); 
delay(700); 
break;

case 8: 
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW); 
digitalWrite(5,LOW); //8
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW); 
delay(700); 
break;

case 9: 
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW); 
digitalWrite(5,LOW); //9
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
digitalWrite(8,LOW); 
delay(700); 
break; 


}
} 

} 
}

LED Chaser Circuit using 555 Timer and CD4017 IC

common anode and common cathode 7 segment display_

Binary value for the common anode and common cathode 7 segment display binary and hex value.

7 segment display with Arduino

Explanation of the above code:

The right side counter is the LSB of count and the left side one is the MSB of the count.

In the above code, there is a void setup{ } and a void loop{ }. The setup code runs only one time and loop code runs multiple times.

Pin numbers A0, A1, A2, A3, A4, A5 and pin 9 are connected to the LSB of the Mod 100 counter. Whereas pin 2, 3, 4, 5, 6, 7, and 8 are connected to the MSB of the counter circuit. All the above pins are initialized as output pins in void setup{ }.

In the void loop{ } there are two for loop nested together. Inside both for loop we have used switch statement. In the switch case statement, we set corresponding LEDs of 7 segment display to on or off to show a particular number.

If we want to show number 7 we need to set LEDs A, B, C, and D to low then we can see number 7 on display.

Here is how it works:

First for loop counts from 0 to 9 and depending on the current value of corresponding case is selected. After execution of case statement control goes to the next for loop.

In this for loop again the same code is executed but with a visible delay so that we can see the counters output. After execution of this loop again control goes to main for loop.

When the main for loop gets executed, due to looping action the same code runs infinitely.

This is how the Mod 100 or 0 to 99 counter works with Arduino.

Comment down your queries and also subscribe to our newsletter.

 

One Reply to “Seven Segment Display with Arduino Interfacing 0 to 99 counter

  1. Good job pls where is the circuit diagram is another ic’s involved or just the code. Pls just want to no the circuit diagram

Leave a Reply

Your email address will not be published. Required fields are marked *