Introduction: Seven Segment Display Using LEDs

About: Product Designer obsessed with Science, Technology and Athletics.

Hello People !

This is my very first Instructable as well as my first Arduino project that i tried. I started out with the very basic LED blinking sketch/code and thought it would be great to control a number of LEDs together. The very first thing that came to my mind was simulating a 7 Segment Display using Arduino. There are many projects based on this already done before (that i came to know later on), but I hope this one shall be a different approach.

The setup consists of only 20 LEDs, a breadboard, few wires and off course an Arduino ( i used the Uno here). I have attached relevant images and videos and you can find the sketch/code also attached written by me. If you find any errors or methods to shorten it, please let me know in the comments. It would be great to learn from the flaws !

EDIT 1 : Thanks for featuring this in the Technology Category.

EDIT 2 : I have now embedded the Demo Video via YouTube for easy viewing. The video can be found it in the last Step.

Thanks DIY Hacks & How-Tos for pointing out this.

Step 1: What You Need

1) An Arduino (preferably Uno in this case)

2) Few connecting wires (i used male-2-male pins)

3) 20 LEDs (any color of your choice)

4) Breadboard

Thats it !! Now lets move to the next step.

Step 2: Setting Up the LEDs on the Breadboard

I assume you have the basic knowledge on what a 7 Segment display is and how it works. If not, then just head over to the link here before starting this step.

I have attached images of how i have connected the LEDs in the form of a 7 Segment display. The seven different segments have been marked a, b, c, d, e, f, g (as usual). Please have a look at all the closeup images of LEDs if you face any difficulties. I suggest starting from one side of the Breadboard bridge. Once you complete the side, it is very easy to mimic the other side of the bridge.

Step 3: Connecting the Wires to the Arduino

This is probably the hectic part you will have to face. I have attached a schematic of the connection setup made using 123d circuits. The basic thing is you have to connect all the different LEDs of each segments a, b, c, d..., ... , ..g together. Doing this, you will get seven + seven total common/base points (7 cathodes & 7 anodes). The connection of each segment's LEDs are shown by green and red wires in the schematic image attached. The orange and black wires (7+7=14 in total ) represent the cathode & anode respectively. The black wires connect all the LEDs to a common Ground point. The orange wires shall go direct to the Arduino Digital pins (from 7 to 13 as per the image shown). These seven points shall be utilised in the Arduino Sketch to represent various digits 0~9 using segment combination.

Example :

To represent the digit 2, we need to set segment a, b, d, e, g to HIGH and segments c, f to LOW. So that means pins 9 and 12 (on the Arduino) should be set to LOW and pins 7, 8, 10, 11, 13 should be set to HIGH. This way only the HIGH input segment LEDs shall glow and represent the digit 2.

Step 4: The Arduino Sketch/Code

Here is the code below, I prepared for this project. Before compiling this, i hope you have a knowledge of Arduino IDE & Serial Monitor stuffs of the IDE. Basically the code needs to be compiled and uploaded to the Arduino. Then in the Serial Monitor, you will just have to input any number (single digit off-course) to display it in the breadboard 7 Segment setup. Any wrong input (characters other than numbers) will turn all the LEDs off and give an error message in the Serial Monitor screen (as seen in the image attached).

I have even attached the code in the default Arduino Sketch format (for those who hate copy-paste).

<pre>void setup()<br>{
Serial.begin(9600); // begin serial communication
Serial.println("Digit Displayed in 7 Segment Setup : "); // debug string
 
 for (int DigitalPin = 7; DigitalPin <= 13; DigitalPin++) 
 {
  pinMode(DigitalPin, OUTPUT);
 }
}   //end setup method
int x; // integer x decalaraion for taking input from user
void loop() //begin main loop
{
 
if(Serial.available()>0)  //check if there is charecter in the serial buffer
{
  x=Serial.read();
switch (x) {
    case '1':   //display 1 in 7 Segment Setup
      Serial.println();
      Serial.write(x);
      digitalWrite(7, LOW);
      digitalWrite(8, HIGH);
      digitalWrite(9, HIGH);
      digitalWrite(10, LOW);
      digitalWrite(11, LOW);
      digitalWrite(12, LOW);
      digitalWrite(13, LOW);
      break;
      
    case '2':   //display 2 in 7 Segment Setup
      Serial.println();
      Serial.write(x); 
      digitalWrite(7, HIGH);
      digitalWrite(8, HIGH);
      digitalWrite(9, LOW);
      digitalWrite(10, HIGH);
      digitalWrite(11, HIGH);
      digitalWrite(12, LOW);
      digitalWrite(13, HIGH);
      break;
    case '3':   //display 3 in 7 Segment Setup
      Serial.println();
      Serial.write(x);  
      digitalWrite(7, HIGH);
      digitalWrite(8, HIGH);
      digitalWrite(9, HIGH);
      digitalWrite(10, HIGH);
      digitalWrite(11, LOW);
      digitalWrite(12, LOW);
      digitalWrite(13, HIGH);
      break;
      
    case '4':   //display 4 in 7 Segment Setup
      Serial.println();
      Serial.write(x);
      digitalWrite(7, LOW);
      digitalWrite(8, HIGH);
      digitalWrite(9, HIGH);
      digitalWrite(10, LOW);
      digitalWrite(11, LOW);
      digitalWrite(12, HIGH);
      digitalWrite(13, HIGH);
      break;
      
    case '5':    //display 5 in 7 Segment Setup
      Serial.println();
      Serial.write(x);
      digitalWrite(7, HIGH);
      digitalWrite(8, LOW);
      digitalWrite(9, HIGH);
      digitalWrite(10, HIGH);
      digitalWrite(11, LOW);
      digitalWrite(12, HIGH);
      digitalWrite(13, HIGH);
      break;
      
      case '6':   //display 6 in 7 Segment Setup
      Serial.println();
      Serial.write(x);
      digitalWrite(7, HIGH);
      digitalWrite(8, LOW);
      digitalWrite(9, HIGH);
      digitalWrite(10, HIGH);
      digitalWrite(11, HIGH);
      digitalWrite(12, HIGH);
      digitalWrite(13, HIGH);
      break;
      
    case '7':   //display 7 in 7 Segment Setup
      Serial.println();
      Serial.write(x);
      digitalWrite(7, HIGH);
      digitalWrite(8, HIGH);
      digitalWrite(9, HIGH);
      digitalWrite(10, LOW);
      digitalWrite(11, LOW);
      digitalWrite(12, LOW);
      digitalWrite(13, LOW);
      break;
      
    case '8':   //display 8 in 7 Segment Setup
      Serial.println();
      Serial.write(x);
      digitalWrite(7, HIGH);
      digitalWrite(8, HIGH);
      digitalWrite(9, HIGH);
      digitalWrite(10, HIGH);
      digitalWrite(11, HIGH);
      digitalWrite(12, HIGH);
      digitalWrite(13, HIGH);
      break;
      
      case '9':   //display 9 in 7 Segment Setup
      Serial.println();
      Serial.write(x);
      digitalWrite(7, HIGH);
      digitalWrite(8, HIGH);
      digitalWrite(9, HIGH);
      digitalWrite(10, HIGH);
      digitalWrite(11, LOW);
      digitalWrite(12, HIGH);
      digitalWrite(13, HIGH);
      break;
      
      case '0':   //display 0 in 7 Segment Setup
      Serial.println();
      Serial.write(x);
      digitalWrite(7, HIGH);
      digitalWrite(8, HIGH);
      digitalWrite(9, HIGH);
      digitalWrite(10, HIGH);
      digitalWrite(11, HIGH);
      digitalWrite(12, HIGH);
      digitalWrite(13, LOW);
      break;
      
    default:
      Serial.println();
      Serial.println("No Digit is Displayed ! Please enter a valid digit from 0-9 !!");
      for (int DigitalPin = 7; DigitalPin <= 13; DigitalPin++)
      {
        digitalWrite(DigitalPin, LOW); // turn all the LEDs off
      }
            }   //end switch case
}   //end if
}   //end main loop

Step 5: And You Are Done !

If you have connected all wires properly, you can see your display simulation perfectly without any errors. I have also shown a video where you can see all the number being displayed smoothly.

Hope this helped all the beginners out there. Any suggestions/feedbacks/doubts are most welcome.
Thanks for watching !

P.S : Instructables is an amazing place to maintain a collection of all your DIY stuffs !