Arduino Push Button Counter With LED Indication

Introduction: Arduino Push Button Counter With LED Indication

In this tutorial I am going to to explain you how to make push button counter with LED indicator
using arduino UNO.
Clear we will control for LED with single push button, but if you want to control more LED then you need to add more case.

Step 1: Required Components

Arduino UNO - X1
Breadboard - X1
LED- X1
150ohm Resistor- X4
10K ohm Resistor -X1
Push - X1
Jumper cables
(You can use 100 Ohm to 1K ohm Resistor to connect with LED , here i connect 150ohm resistor with LED)

And arduino IDE for programming arduino Uno board

Step 2: Circuit Connection

arduino (5V) -- push button(A1)

arduino (D5) -- push button(B1)

arduino (D6, D7, D8, D9) -- Resistor(150ohm) -- LED's (positive terminal)

arduino(GND) -- LED(negative terminal)

arduino(GND) -- Resistor(10K) -- push button(B2)

Step 3: Program

This is the code for our project you can copy from here or you can download the file given below

int count=0;
int newcount;
void setup()
{
Serial.begin(9600);
pinMode(5,INPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
}
void loop()
{

if(digitalRead(5)==HIGH)
{
newcount=count+1;
if(newcount!=count)
{
Serial.println(newcount);
switch (newcount)
{
case 1: digitalWrite(6,HIGH);
break;
case 2: digitalWrite(7,HIGH);
break;
case 3: digitalWrite(8,HIGH);
break;
case 4: digitalWrite(9,HIGH);
break;
default: digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
newcount=0;
break;
}
count=newcount;
}
}
delay(100);
}

---------------------------------------------------------------------------------------------------------------------------

Downloading .ino file :-

(1.) download .ino file given below

(2.) go to >> documents > arduino > now make here folder having same name as file name

(make folder having name - "switch_case_with_mult_leds" )

(3.) Now add the downloaded file in this folder.

Step 4: Troubleshoot

  1. After uploading this post when i use this circuit again then i found an issue :- when i pressed the button only one time then our board will performs instructions of case2 and case3 along with case1 as well, which means when i pressed the button 1st time then along with 1st LED ,my 2nd and 3rd LED also turned on
  2. But i want that when i press button then LED will turned on ONE BY ONE .
  3. Thats why i use remove delay(100) from last line ,and i write delay(500), before switch statement
  4. So now whenever i pressed the push button then after 500millisecond our single LED will turn ON
  • you can copy the code from below

int count=0;

int newcount; void setup()

{ Serial.begin(9600); pinMode(5,INPUT);

pinMode(6,OUTPUT);

pinMode(7,OUTPUT);

pinMode(8,OUTPUT);

pinMode(9,OUTPUT);

}

void loop()

{

if(digitalRead(5)==HIGH)

{

newcount=count+1;

if(newcount!=count)

{

delay(500);

switch (newcount)

{

case 1: digitalWrite(6,HIGH);

break;

case 2: digitalWrite(7,HIGH);

break;

case 3: digitalWrite(8,HIGH);

break;

case 4: digitalWrite(9,HIGH);

break;

default: digitalWrite(6,LOW);

digitalWrite(7,LOW);

digitalWrite(8,LOW);

digitalWrite(9,LOW);

newcount=0;

break;

}

Serial.println(newcount);

count=newcount;

}

}

}

Download the updated counter code's .ino file from below

Be the First to Share

    Recommendations

    • Knitting and Crochet Speed Challenge

      Knitting and Crochet Speed Challenge
    • Anything Goes Contest 2021

      Anything Goes Contest 2021
    • Photography Challenge

      Photography Challenge

    Comments