Introduction: Arduino 7-Segment Click Counter

Check out how to make your own 7 segment click counter!!

Step 1: Materials You Will Need:

1x Arduino Board(does not matter which version).

1x BreadBoard.

1x 1 Digit 7 Segment display.

2x Push Buttons.

4x 220 ohm resistors(Will work up to 1K).

16x Male to male jumper wires.

Step 2: Connect the Arduino to the BreadBoard:

Connect as shown in the image above:

Arduino 5V pin to the PLUS of the breadboard.

Arduino GND to the MINUS of the breadboard.

7-Segment pin 8 & 3 to the PLUS of the breadboard through your resistors.

NOTE: if your 7 segment display is a common cathode display, connect pins 8 & 3 of the display to the GND!!

7-Segment pin 1 to Arduino pin 6.

7-Segment pin 2 to Arduino pin 5.

7-Segment pin 4 to Arduino pin 4.

7-Segment pin 5 to Arduino pin 7.

7-Segment pin 6 to Arduino pin 2.

7-Segment pin 7 to Arduino pin 3.

7-Segment pin 9 to Arduino pin 8.

7-Segment pin 10 to Arduino pin 9.

Connecting the buttons:

connect one side of the button to the PLUS of the breadboard;

connect the other side through a resistor to the GND of the breadboard, and to Arduino pin 12.

Do that for the second button and connect it to Arduino pin 13.

Step 3: The Code:

Download the code and insert it to arduino IDE, and have fun!!

Write your comments down bellow!!

Comments

author
AngelicaN12 (author)2017-07-08

How can I stop it from looping? Like If i push the buttonUp, it will go from 0-9 only even if i push the buttonUp again, it'll not change anything and still stuck up to 9 only. Same goes for the buttonDown, if I push the buttonDown, it'll go from 9-0 and nothing more. Not repeating the same cycle again. And also, I have this problem when I tried to click a few more times (after it reached the last number for both buttonDown and Up) it should not store the clicks. Example: I pushed the buttonUp and it reached to 9, after trying to click it some few more, lets say 3. If I clicked the buttonDown, it should automatically show the number from 9 to 8 without clicking 3 times before it goes to 8. Do you get what I mean? Im having a hard tme with these codes and I'm still not familiar with them. :( Help guyzzzz

author
TanveerM2 (author)2017-01-28

how can i add 2 more digits

author
Fritz GeraldO (author)TanveerM22017-06-25

I have the codes man. chat me on facebook

author
BryanV2 (author)TanveerM22017-06-23

Can you sent it to me?

author
YahavHadad (author)TanveerM22017-02-02

I sent you a private message, check it.

author
BryanV2 (author)YahavHadad2017-06-23

Can you help with it too please

author
jolos2 (author)YahavHadad2017-03-08

Please send me how to add another 1 digit and how the would be look like many thanks

author
jolos2 (author)jolos22017-03-08

How the code would be look like when added another 1 digit

author
taeyeon (author)YahavHadad2017-03-08

can you give it to me too? pleaseeee

author
TholudA (author)YahavHadad2017-02-03

please give me too, i need to add 1 more digit

author
Bverysharp (author)2017-05-10

A very helpful and educational instructable. I specially appreciated the comment from KoKoY2 to convert the code to common cathode.

author
KoKoY2 made it! (author)2017-04-27

Thank you.... it helped me.I used seven segment common cathode and i edited HIGH and LOW states.Here for common cathode...

//Initialize the 7 segment pins
int A = 3;
int B = 2;
int C = 4;
int D = 5;
int E = 6;
int F = 8;
int G = 9;

//Initialize the push buttons pins, push buttons states, and the counter
int switchUpPin = 12;
int switchDownPin = 13;
int counter = 0;
int buttonUpState = 0;
int lastButtonUpState = 0;
int buttonDownState = 0;
int lastButtonDownState = 0;

void setup()
{
Serial.begin(9600);

pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
pinMode(C, OUTPUT);
pinMode(D, OUTPUT);
pinMode(E, OUTPUT);
pinMode(F, OUTPUT);
pinMode(G, OUTPUT);

}

void loop()
{
//Getting the reads from the buttons
buttonUpState = digitalRead(switchUpPin);
buttonDownState = digitalRead(switchDownPin);

//Detecting button press and getting the button status
//Do this for the button up
if (buttonUpState != lastButtonUpState)
{
if (buttonUpState == HIGH)
{
//Reset the counter to -1
if(counter == 9)
{
counter = -1;
}
//Increase the counter by 1
counter++;
//Print the counter to the console and calling the function
Serial.println(counter);
changeNumber(counter);
//Delaying by 250 ms
delay(250);
}
else
{
Serial.println("OFF");
}
//Delay to avoid button bouncing
delay(50);
}

//Do this for the button down
if (buttonDownState != lastButtonDownState)
{
if (buttonDownState == HIGH)
{
//Set the counter to 10
if(counter == 0)
{
counter = 10;
}
//Decreases the counter by 1
counter--;
////Print the counter to the console and calling the function
Serial.println(counter);
changeNumber(counter);
//Delaying by 250 ms
delay(250);
}
else
{
Serial.println("OFF");
}
//Delay to avoid button bouncing
delay(50);
}
//Calling the function changeNumber with the arg counter
changeNumber(counter);
}

//The function to display the numbers
void changeNumber(int buttonPress)
{
switch (buttonPress)
{
//number 0
case 0:
digitalWrite(A, HIGH);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, HIGH);
digitalWrite(E, HIGH);
digitalWrite(F, HIGH);
digitalWrite(G, LOW);
break;
//number 1
case 1:
digitalWrite(A, LOW);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
break;
//number 2
case 2:
digitalWrite(A, HIGH);
digitalWrite(B, HIGH);
digitalWrite(C, LOW);
digitalWrite(D, HIGH);
digitalWrite(E, HIGH);
digitalWrite(F, LOW);
digitalWrite(G, HIGH);
break;
//number 3
case 3:
digitalWrite(A, HIGH);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, HIGH);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, HIGH);
break;
//number 4
case 4:
digitalWrite(A, LOW);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, HIGH);
digitalWrite(G, HIGH);
break;
//number 5
case 5:
digitalWrite(A, HIGH);
digitalWrite(B, LOW);
digitalWrite(C, HIGH);
digitalWrite(D, HIGH);
digitalWrite(E, LOW);
digitalWrite(F, HIGH);
digitalWrite(G, HIGH);
break;
//number 6
case 6:
digitalWrite(A, HIGH);
digitalWrite(B, LOW);
digitalWrite(C, HIGH);
digitalWrite(D, HIGH);
digitalWrite(E, HIGH);
digitalWrite(F, HIGH);
digitalWrite(G, HIGH);
break;
//number 7
case 7:
digitalWrite(A, HIGH);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, HIGH);
digitalWrite(G, LOW);
break;
//number 8
case 8:
digitalWrite(A, HIGH);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, HIGH);
digitalWrite(E, HIGH);
digitalWrite(F, HIGH);
digitalWrite(G, HIGH);
break;
//number 9
case 9:
digitalWrite(A, HIGH);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, HIGH);
digitalWrite(E, LOW);
digitalWrite(F, HIGH);
digitalWrite(G, HIGH);
break;
}
}

IMG_20170427_143010.jpg
author
Adityan57 (author)2017-04-14

GOOD IT HELPED ME A LOT

author
ReymarB1 (author)2016-12-10

i have a problem in my seven segment, if use the common anode, the seven segment isn't displaying anything, if use the the common cathode, some of the segments are not working. help pls

author
Funnyguy123p -P (author)ReymarB12017-04-02

after fooling around i found a solution. flip around the code for the leds in the segment display i.e. if it says digitalWrite (A,HIGH); switch it to digitalWrite(A,LOW);

author
JanD33 (author)2017-02-21

how to make two digit one pls :) text me. Thanks a lot

author
seamster (author)2016-05-04

Great instructions. Thank you for sharing how you made this little counter! :)

author
YahavHadad (author)seamster2016-05-05

Thanks, appreciate that :)

About This Instructable

8,650views

9favorites

More by YahavHadad:Arduino 7-Segment Click Counter
Add instructable to: