Find fresh tutorials related to Arduino, Raspberry Pi, 555 Timer and many more microcontrollers. Learn something new everyday!



Monday, 15 December 2014

Driving a 7 segment display (Common Anode) [ARDUINO]


So, here's my first arduino project and a very useful one. Many people had asked me to demonstrate the usage of the common anode seven segment display. So, here it is.

DISCLAIMER: THE AUTHOR IS NOT RESPONSIBLE FOR ANY DAMAGES CAUSED DUE TO THE PROJECT.

Let's get started.


What this project is all about? Well, the market is full of common cathode displays. Yesterday, I received the common anode one . I played with it a bit and finally came to this project. You may use any modifications necessary for your own innovations.

Today I'll show you how to use the common anode display to display digits from 0 to 9 and keep on looping it forever. In the next project, I'll show you how to make a button counter, which will display the number of times a push button was pressed.

NOTE: THIS GUIDE IS MEANT ONLY FOR COMMON ANODE 7 SEGMENT DISPLAY. PLEASE REFER YOUR PRODUCT DATASHEET FOR MORE INFORMATION.


Materials Required:

  1. Breadboard
  2. Arduino UNO (or any other will work)
  3. 7 330Ω resistors 
  4. A 1 Digit seven segment LED
  5. Jumpers (Connector Cables)

Procedure:

  1. I'll assume from this point onwards that you know the basics of electricity and how to use Arduino or a breadboard.

    Please keep in mind that I used 330Ω resistor because I used a display which needs 0.02 A current to glow properly since I was using the 3.3V port. Please check your datasheet for optimal current information and use Ohm's Law (V=IR).
  2. Make the connections as shown:

  3. Upload the sketch and you're done!

    Select the following code and paste it in a new sketch window on your Arduino IDE. There won't be any need of explaining each line of code because I've already added the comments wherever necessary.

    CODE:
     //CODE DEVELOPED BY NITISH DASH
    const int a=7;
    const int b=6;
    const int c=4;
    const int d=2;
    const int e=3;
    const int f=9;
    const int g=10;
    void setup()
    {
    pinMode(a, OUTPUT);
    pinMode(b, OUTPUT);
    pinMode(c, OUTPUT);
    pinMode(d, OUTPUT);
    pinMode(e, OUTPUT);
    pinMode(f, OUTPUT);
    pinMode(g, OUTPUT);
    }
    void loop()
    {
        //Display 0
        digitalWrite(a, LOW);
        digitalWrite(b, LOW);
        digitalWrite(c, LOW);
        digitalWrite(d, LOW);
        digitalWrite(e, LOW);
        digitalWrite(f, LOW);
        digitalWrite(g, HIGH);
        delay(1000);
    
        //Display 1
        digitalWrite(a, HIGH);
        digitalWrite(b, LOW);
        digitalWrite(c, LOW);
        digitalWrite(d, HIGH);
        digitalWrite(e, HIGH);
        digitalWrite(f, HIGH);
        digitalWrite(g, HIGH);
        delay(1000);
    
        //Display 2
        digitalWrite(a, LOW);
        digitalWrite(b, LOW);
        digitalWrite(c, HIGH);
        digitalWrite(d, LOW);
        digitalWrite(e, LOW);
        digitalWrite(f, HIGH);
        digitalWrite(g, LOW);
    delay(1000);
           
        //Display 3
        digitalWrite(a, LOW);
        digitalWrite(b, LOW);
        digitalWrite(c, LOW);
        digitalWrite(d, LOW);
        digitalWrite(e, HIGH);
        digitalWrite(f, HIGH);
        digitalWrite(g, LOW);
        delay(1000);
    
        //Display 4   
        digitalWrite(a, HIGH);
        digitalWrite(b, LOW);
        digitalWrite(c, LOW);
        digitalWrite(d, HIGH);
        digitalWrite(e, HIGH);
        digitalWrite(f, LOW);
        digitalWrite(g, LOW);
        delay(1000);
    
        //Display 5   
        digitalWrite(a, LOW);
        digitalWrite(b, HIGH);
        digitalWrite(c, LOW);
        digitalWrite(d, LOW);
        digitalWrite(e, HIGH);
        digitalWrite(f, LOW);
        digitalWrite(g, LOW);
        delay(1000);
        
        //Display 6
        digitalWrite(a, LOW);
        digitalWrite(b, HIGH);
        digitalWrite(c, LOW);
        digitalWrite(d, LOW);
        digitalWrite(e, LOW);
        digitalWrite(f, LOW);
        digitalWrite(g, LOW);
        delay(1000);
    
        //Display 7
        digitalWrite(a, LOW);
        digitalWrite(b, LOW);
        digitalWrite(c, LOW);
        digitalWrite(d, HIGH);
        digitalWrite(e, HIGH);
        digitalWrite(f, HIGH);
        digitalWrite(g, HIGH);
        delay(1000);
       
        //Display 8  
        digitalWrite(a, LOW);
        digitalWrite(b, LOW);
        digitalWrite(c, LOW);
        digitalWrite(d, LOW);
        digitalWrite(e, LOW);
        digitalWrite(f, LOW);
        digitalWrite(g, LOW);
        delay(1000);
    
        //Display 9  
        digitalWrite(a, LOW);
        digitalWrite(b, LOW);
        digitalWrite(c, LOW);
        digitalWrite(d, LOW);
        digitalWrite(e, HIGH);
        digitalWrite(f, LOW);
        digitalWrite(g, LOW);
        delay(1000);
      } 
    
    
    
  4. Feel free to experiment and share your ideas with us! Thank you. Ask me your doubts in the comments section!

    I'll also add a project using common cathode and believe me, that would be a lot more easier and economical than this.

    Also, this was my first project for this site, all your suggestions and valuable comments will help me change my way of writing and expressions.


VIDEO:


COMING SOON!


Downloads:


1. Common Cathode code
2. Schematics [Breadboard view]

0 comments:

Post a Comment

Leave your valuable feedback and suggestions.

Upcoming projects!

1. Programming ESP8266 using NodeMCU and LUA Scripts

2. IoT Applications

3. NRF42L01 2.4 GhZ module interfacing with arduino

4. ESP8266 - Everything cool about it!

Language ain't any barrier!

Get Updates!

Enter your email address:


Get the latest projects delivered into your inbox, hot!