Introduction: Easy Arduino Pushbutton Scoring for Two Teams

Picture of Easy Arduino Pushbutton Scoring for Two Teams

Here is a simple pushbutton scoring setup for two teams. It has an up and a down button for each team and a reset button to set the scores back to 0. It displays the scores in the Serial Monitor. I'm sure with minimal changes you can make it work for whatever application you need it for.

Step 1: Materials

Step 2: Wire the Buttons

Picture of Wire the Buttons

The buttons on the left are the micro switches out of the bottom of the arcade buttons.

Cut one end off of 5 of the wires, strip the end, and crimp the terminal connectors on. The terminal connectors slide onto the micro switch terminals.

Use the breadboard and wires to hook up the system.

Step 3: Upload the Program

Copy and paste the program into the Arduino IDE and upload to the Arduino

Program:

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

/*
Two team up and down pushbutton scoring with reset
What it does:
Senses when the buttons change state and adds or subtracts
one from the appropriate teams total
Reset button sets both teams scores back to zero
Prints results in Serial Monitor
Feel free to use and modify this for any purpose
Enjoy!
*/
const byte Button = A0;
const byte Button1 = A1;
const byte Reset = A2;
const byte Button2 = A3;
const byte Button3 = A4;
byte ButtonState;
byte ButtonState1;
byte ResetState;
byte ButtonState2;
byte ButtonState3;
byte lastState = LOW;
byte count = 0;
byte count1 = 0;
void setup() {
Serial.begin(9600);
pinMode(Button, INPUT);
pinMode(Button1, INPUT);
pinMode(Reset, INPUT);
pinMode(Button2, INPUT);
pinMode(Button3, INPUT);
}
void loop() {
//Buttons
ButtonState = digitalRead(Button);
ButtonState1 = digitalRead(Button1);
ResetState = digitalRead(Reset);
ButtonState2 = digitalRead(Button2);
ButtonState3 = digitalRead(Button3);
//Buttons End
//Button Count and Display
if(ButtonState && ButtonState != lastState) // button latch, no debounce needed.
{
if(count < 255) // This will check to see if the count is within a range of 0 - 255, and anything over that, it will reset count back to 0. Of course, this will happen anyways because count is a BYTE, and not an int or any other type.
count += 1; // same as count = count + 5;
else
count = 0;
delay(250);
Serial.print("Red Team score: ");
Serial.println(count);
}
if(ButtonState1 && ButtonState1 != lastState) // button latch, no debounce needed.
{
if(count < 255) // This will check to see if the count is within a range of 0 - 255, and anything over that, it will reset count back to 0. Of course, this will happen anyways because count is a BYTE, and not an int or any other type.
count -= 1; // same as count = count + 5;
else
count = 0;
delay(250);
Serial.print("Red Team score: ");
Serial.println(count);
}
if(ResetState && ResetState != lastState) // button latch, no debounce needed.
{
if(count < 255) // This will check to see if the count is within a range of 0 - 255, and anything over that, it will reset count back to 0. Of course, this will happen anyways because count is a BYTE, and not an int or any other type.
count = 0;
else
count = 0;
count1 = 0;
delay(250);
Serial.print("Red Team score: ");
Serial.println(count);
Serial.print("Blue Team score: ");
Serial.println(count1);
}
if(ButtonState2 && ButtonState2 != lastState) // button latch, no debounce needed.
{
if(count1 < 255) // This will check to see if the count is within a range of 0 - 255, and anything over that, it will reset count back to 0. Of course, this will happen anyways because count is a BYTE, and not an int or any other type.
count1 += 1; // same as count = count + 5;
else
count1 = 0;
delay(250);
Serial.print("Blue Team score: ");
Serial.println(count1);
}
if(ButtonState3 && ButtonState3 != lastState) // button latch, no debounce needed.
{
if(count1 < 255) // This will check to see if the count is within a range of 0 - 255, and anything over that, it will reset count back to 0. Of course, this will happen anyways because count is a BYTE, and not an int or any other type.
count1 -= 1; // same as count = count + 5;
else
count1 = 0;
delay(250);
Serial.print("Blue Team score: ");
Serial.println(count1);
}

lastState = ButtonState;
//Button Count and Display End
}//Void loop end

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

Step 4: Use the System

Picture of Use the System

The values will display in the Serial Monitor.

Comments

TexasMan15 made it! (author)2016-01-03

Thank you,

I have found this very useful. I am new to programming and Ardiuno. With this code and adding in LCD. I left the serial monitor in because so I could use it for debugging. I was able to come up with portable game counter for two teams. As of yet it has not failed me. The only small issue i am having is that i think it may need debounce. But if the person pushing the buttons is paying attention its not a problem. In the picture with this post understand that this is a prototype. I added a pot for the LCD-LED just for fun.

As games of cornhole can easily become quite competitive I know this will help people stay on track. So again thanks you for allowing me to complete my project with your code.

amberrayh (author)2015-04-10

This is great! Very useful for trivia game nights. Thanks for sharing!

About This Instructable

1,698views

20favorites

More by waylon meurs:Wireless Infra Red Perimeter Detection DeviceEasy Arduino Pushbutton Scoring For Two Teams
Add instructable to: