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



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.

2 comments:

  1. hi.. how can make the buttons to work with gnd not +5volt..??
    i mean gnd+pin 8 up count gnd +9 down count
    thanks allot

    ReplyDelete
  2. Are you looking for the best Sweets and Bakery Display Counter in cheapest price? We are providing Display Counter for food, Sweets and Bakery.

    For more information visit here : Display Counter

    ReplyDelete

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!