SEVEN SEGMENT DISPLAY COUNTDOWN USING ARDUINO UNO. (Code Explained)

The main advantage of light emitting diodes is that because of their small die size, several of them can be connected together within one small and compact package producing what is generally called a 7-segment Display.

The 7-segment display, also written as “seven segment display”, consists of seven LEDs (hence its name) arranged in a rectangular fashion as shown. Each of the seven LEDs is called a segment because when illuminated the segment forms part of a numerical digit (both Decimal and Hex) to be displayed. An additional 8th LED is sometimes used within the same package thus allowing the indication of a decimal point, (DP) when two or more 7-segment displays are connected together to display numbers greater than ten.

Two types of SSD’s are available.

  1. Common cathode Seven segment display

32

2. Common anode Seven segment display.

231.JPG

For now we will use a common anode seven segment display.

ASSEMBLING THE CIRCUIT.

  • Firstly we will start by connecting the first pin on the seven segment display to the 2nd pin in the arduino. In likewise fashion we will jconnect the second to the third pin slot in arduino.11111.JPG
  • Now comes the tricky part, we have to connect the third pin on the seven segment display to the pin on the opposite side of it. And then connect them both to the ground slot in the arduino.2222.JPG
  • Now in like wise fashion we will keep joining the pin in the seven segment display to the arduino till pin 9 of the arduino.
  • 333.JPG

We are all done with assembling the circuit.

CODE :-

int A = 7; //Defines all pins on the Arduino Uno board in order of connection.
int B = 6;
int C = 4; // DOT is pin 5, not used in this example.
int D = 3;
int E = 2;
int F = 8;
int G = 9;
byte num0 = 0x3F; //Hexadecimal format based upon the A-G, 0-9 Chart in excel and the wiring // of the segment (refer to the on/off table image below).
byte num1 = 0x6;
byte num2 = 0x5B;
byte num3 = 0x4F;
byte num4 = 0x66;
byte num5 = 0x6D;
byte num6 = 0x7C;
byte num7 = 0x7;
byte num8 = 0x7F;
byte num9 = 0x6F;
void on(byte num) // This function turns on the correct pins to display numbers passed to it // through the variable “num”.
{
int result = bitRead(num, 0); // Read the first binary entry in num and stores it in result.
if (result == 1) // Check to see if this segment should be on.
{digitalWrite(A, HIGH);} // Turns on the segment.
else // Otherwise, it turns it off.
{digitalWrite(A, LOW);} // Turns segment off.
result = bitRead( num, 1); // Same thing for the 6 remaining segments.
if (result == 1)
{digitalWrite(B, HIGH);}
else
{digitalWrite(B, LOW);}
result = bitRead( num, 2);
if (result == 1)
{digitalWrite(C, HIGH);}
else
{digitalWrite(C, LOW);}
result = bitRead( num, 3);
if (result == 1)
{digitalWrite(D, HIGH);}
else
{digitalWrite(D, LOW);}
result = bitRead( num, 4);
if (result == 1)
{digitalWrite(E, HIGH);}
else
{digitalWrite(E, LOW);}

result = bitRead( num, 5);
if (result == 1)
{digitalWrite(F, HIGH);}
else
{digitalWrite(F, LOW);}

result = bitRead( num, 6);
if (result == 1)
{digitalWrite(G, HIGH);}
else
{digitalWrite(G, LOW);}
}
void setup() { // Our setup routine
pinMode(A, OUTPUT); // Making all pins outputs
pinMode(B, OUTPUT);
pinMode(C, OUTPUT);
pinMode(D, OUTPUT);
pinMode(E, OUTPUT);
pinMode(F, OUTPUT);
pinMode(G, OUTPUT);
pinMode(10,OUTPUT);
}
void loop() { // Loops forever
on(num0); // Passing “num0” to the function “on()” defined above to display “0”
delay(500); // Delay for 1 second to see the “0”
on(num1); // Change to “1”
delay(500);
on(num2);
delay(500);
on(num3);
delay(500);
on(num4);
delay(500);
on(num5);
delay(500);
on(num6);
delay(500);
on(num7);
delay(500);
on(num8);
delay(500);
on(num9);
delay(500);
}

Now there is an interesting breadboarding technique that can be used in this particular project. Using the same code mentioned above we can use two and up to four, Seven segment display countdown. Only con is that we will require an inexplicable amout of jumper wires.

I will show you how i did it for two SSD’s you can try on for as many as you like if you have those many jumper wires and breadboard!

 

Snapchat-339135551.jpg

What i did here was to connect the pin wire of the arduino to a slot in the breadboard and then join that slot to the two SSD’s simultaneously so that both of the SSD’s get the same comman from the code and perform the same function.

Snapchat-1286427010.jpg

Here you can clearly see what I did. But this was just to brush up your basic breadboarding skills and to be honest becomes very tiring and messy with so many wires.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s