Introduction: Seven Segment Display Using LEDs

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 !

Comments

author
charlie.harris.376 (author)2015-08-10

Hi

Thanks for the project. Have learnt a lot from this re getting info from monitor and processing.Where in the code does it say how often to check with monitor to see if something there to process. In my case I want to have the led go only momentary, say 200ms, with the code do I then need to use the LOW part to turn off? I will change your code to see if I can get to go. Also I will have 20 leds but individually controlled so I will need to use a multiplexer of some sort. Your comments would be appreciated. Thanks Charles

author

If you could elaborate your viewpoint a bit more clearly, it would be easy for me to answer it.

Anyways, if you want the LED to go momentary then you can use the delay function after the HIGH statement, followed by the LOW statement. Maybe i did not get you right ; you could just attach some images/diagrams to explain your viewpoint/project.

Would be happy to help ! & Thanks for your appreciations !

author

Hi HckmstrRahul
Thanks for your post.
Thiis is what I want to do.
There will be 20 leds or more each to be able to be turned on and off , will use the delay as you suggest. Only1 led will be turned on each time, then followed by another one.
In the monitor a number between 1 and 20 will be entered and that led with that number will turn momentarily on.
Another number will be entered in monitor and that let with the number will momentarily turn on.
This is similar to your code but only 1 led at a time, in yours you turn
2 or more leds on each time.
Because of the higher number of leds it seems I have to use a shift register and therefore only need 4 pins in Arduino.(Nano)

My project is for activating a 20 key pad which is in parallel wired to Arduino to run a model train controller. The leds will be replaced with opto couplers (isolators)

Thankyou for your help.
Charles (retired and new to Arduino)

author

Okayy...now i get you. But frankly i have no idea how to achieve this using multiplexers or shift registers. I am new to Arduino and as far as i knw you cannot control 20 LEDs individually via Arduino Uno, because of the limited number of pins.

Hope the Arduino Forum, Instructables, & YouTube etc helps.. :)

author

HI

Thanks for your comments. I will follow up on your ideas.

Thanks

author
DIY Hacks and How Tos (author)2015-08-09

Cool display. For the video, the best way to post it is to upload it to YouTube and then use the Embed Video tool in the step. That will allow people to watch the video on the page without having to download it.

author

Thanks a lot..I will do that. I was actually wondering how to do that. Just before moving to the FAQ section, i got your comment. :)

About This Instructable

4,245views

123favorites

License:

Bio: Product Designer obsessed with Science, Technology and Athletics.
More by HckmstrRahul:Temp & Humidity Sensor with LCD Disp & LED IndicatorSeven Segment Display using LEDs
Add instructable to: