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



Showing posts with label 7 Segment Display. Show all posts
Showing posts with label 7 Segment Display. Show all posts

Monday, 15 December 2014

Button Counter using 7 segment display [ARDUINO]




Last project clearly demonstrated how easily you can program the Arduino to display the required number or character on the 7 segment display. This one, is a clever application of the concept.

What it does?
This project simply uses a push button and one 7 segment display to show the number of times the given button was pressed. After it reaches 9, it will automatically go back to 0 and cycle again.

How it works?
This works on a very simple note. The push button changes the variable in the code and assigns a value to it. The code then matches a simple condition which changes the output values and displays the required number.

Materials Required:

1. Arduino UNO
2. 1 Tactile Push Button
3. Breadboard
4. Jumper cables
5. One 10KOhm resistor
6. Seven 330 resistors



Procedure:

1. Wire up the components as shown in the picture below. (Click on it to enlarge)



2. Upload the code

3. Test the button!



Code:


//Code developed by Nitish Dash.
//More projects on www.eweekend.blogspot.com
//Initialising the pin numbers

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;
const int buttonPin = 8;    
int no = 0;
int buttonState = 0;  
int lastButtonState = 0;

void setup() {
   
pinMode(buttonPin, INPUT); 
pinMode(a, OUTPUT);
pinMode(b, OUTPUT);
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
pinMode(e, OUTPUT);
pinMode(f, OUTPUT);
pinMode(g, OUTPUT);
}
void loop(){
  buttonState = digitalRead(buttonPin);
   if (buttonState != lastButtonState)
   {
    if (buttonState == HIGH) {
     no++;
    }

    else {
    }
  }
lastButtonState = buttonState;
////////////////////////
switch(no)
  {
    case 0:
    digitalWrite(a, LOW);
    digitalWrite(b, LOW);
    digitalWrite(c, LOW);
    digitalWrite(d, LOW);
    digitalWrite(e, LOW);
    digitalWrite(f, LOW);
    digitalWrite(g, HIGH);
    break;

        case 1:
    digitalWrite(a, HIGH);
    digitalWrite(b, LOW);
    digitalWrite(c, LOW);
    digitalWrite(d, HIGH);
    digitalWrite(e, HIGH);
    digitalWrite(f, HIGH);
    digitalWrite(g, HIGH);
    break;

        case 2:
    digitalWrite(a, LOW);
    digitalWrite(b, LOW);
    digitalWrite(c, HIGH);
    digitalWrite(d, LOW);
    digitalWrite(e, LOW);
    digitalWrite(f, HIGH);
    digitalWrite(g, LOW);
    break;
        case 3:
    digitalWrite(a, LOW);
    digitalWrite(b, LOW);
    digitalWrite(c, LOW);
    digitalWrite(d, LOW);
    digitalWrite(e, HIGH);
    digitalWrite(f, HIGH);
    digitalWrite(g, LOW);
    break;
        case 4:
    digitalWrite(a, HIGH);
    digitalWrite(b, LOW);
    digitalWrite(c, LOW);
    digitalWrite(d, HIGH);
    digitalWrite(e, HIGH);
    digitalWrite(f, LOW);
    digitalWrite(g, LOW);
    break;

        case 5:
    digitalWrite(a, LOW);
    digitalWrite(b, HIGH);
    digitalWrite(c, LOW);
    digitalWrite(d, LOW);
    digitalWrite(e, HIGH);
    digitalWrite(f, LOW);
    digitalWrite(g, LOW);
    break;
        case 6:
    digitalWrite(a, LOW);
    digitalWrite(b, HIGH);
    digitalWrite(c, LOW);
    digitalWrite(d, LOW);
    digitalWrite(e, LOW);
    digitalWrite(f, LOW);
    digitalWrite(g, LOW);
    break;

       case 7:
    digitalWrite(a, LOW);
    digitalWrite(b, LOW);
    digitalWrite(c, LOW);
    digitalWrite(d, HIGH);
    digitalWrite(e, HIGH);
    digitalWrite(f, HIGH);
    digitalWrite(g, HIGH);
    break;

        case 8:
    digitalWrite(a, LOW);
    digitalWrite(b, LOW);
    digitalWrite(c, LOW);
    digitalWrite(d, LOW);
    digitalWrite(e, LOW);
    digitalWrite(f, LOW);
    digitalWrite(g, LOW);
    break;
        case 9:
    digitalWrite(a, LOW);
    digitalWrite(b, LOW);
    digitalWrite(c, LOW);
    digitalWrite(d, LOW);
    digitalWrite(e, HIGH);
    digitalWrite(f, LOW);
    digitalWrite(g, LOW);
    break;
 default: no=0; break; } } 
Video: COMING SOON!  So, here ends the simple yet important demonstration of the seven segment display which we shall use in future projects wherever needed. So, stay tuned and check out the site next weekend! Bye and comment below for any doubts.

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]

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!