Introduction: Arduino Two-Player Fast Button-Clicking Game

This fun two player Arduino game is very entertaining to play with a friend and can also be very competitive! The game is based on fast-clicking fingers. Whoever clicks their button the fastest wins the game! This product is useful because it is able to entertain many people and it also helps in finger-eye coordination. This game is also perfect for a family night where everyone gets to bond with their siblings and parents!

Step 1: Parts You Need to Build the Game

  • 1 Green LED
  • 4 Red LEDs
  • 4 Yellow LEDs
  • 15 Male to Male 20cm Jumper Cables
  • 2 Push-Buttons
  • 9 220 Ohm Resistors
  • 2 10K Ohm Resistors
  • 1 Arduino UNO Board
  • 1 Arduino Breadboard
  • 1 USB 2.0 Cable Type A/B

Step 2: Building the Circuit

Step 3: Connect the USB 2.0 Cable Type A/B From Your Arduino UNO Board to Your Computer

Step 4: Connect a Male to Male 20cm Jumper Cable From a Ground Port (GND) to the Right End of the Negative Column

Step 5: Connect a Male to Male 20cm Jumper Cable From a Five Volt Port (5V) to the Left End of the Positive Column

Step 6: Start Placing the Colored LEDs in Order in Column 'i' As Showed Below, Where the Longer Leg of Each LED Is on the Right Side. Make Sure That the Green LED Is in the Middle.

Step 7: Connect a 220 Ohm Resistor for Each LED From Column 'j' to the Negative Column (one End of Each Resistor Should Be Located on Top of the Left Leg of Each LED As Shown Below)

Make sure that none of the resistors are touching each other to prevent your circuit from being a short circuit

Step 8: Connecting the LEDs to the Numbers on the Arduino UNO Board

Place one Male to Male 20cm Jumper Cable above each LED on column 'j'. One end of each jumper cable should be located directly on top of the right leg of each LED, colour coding is optional. The other end of each jumper cable should be located on the number on the Arduino UNO Board in order. The jumper cable that has an end located on top of the right leg of the first LED (the red LED on the right side of the breadboard) should have another end that is located on number 2 on the Arduino UNO Board. While the jumper cable that has an end located on top of the right leg of the last LED (the red LED on the left side of the breadboard) should have another end that is located on number 10 on the Arduino UNO Board. The image below will help you understand the order of the placements of the jumper cables.

Step 9: Place Two Push-Buttons on Each Side of the Arduino Breadboard (the Push-Buttons Should Be Placed on the Middle of the Columns and on Each End of the Arduino Breadboard)

Step 10: Place a 10K Ohm Resistor on Top of One of the Legs of Each Push-Button and Connect It to the Negative Column As Shown Below

Step 11: Place a ​Male to Male 20cm Jumper Cable on Top of the Other Leg of Each Push-Button and Connect It to the Positive Column As Shown Below

Step 12: Place a ​Male to Male 20cm Jumper Cable Under the Bottom Left Leg of the Right Push-Button and Connect It to Number 12 on the Arduino UNO Board As Shown Below

Step 13: Place a ​Male to Male 20cm Jumper Cable Under the Bottom Right Leg of the Left Push-Button and Connect It to Number 13 on the Arduino UNO Board As Shown Below

Step 14: This Is What Your Final Circuit Should Look Like After Completing All the Steps Correctly

Step 15: Writing the Code

Here is all the code that is required to operate the game, this is to copy and paste into the Arduino software.

<p>int rightbutton = 12;<br>int leftbutton = 13;
int leftred = 2;
int leftred1 = 3;
int leftyellow = 4;
int leftyellow1 = 5;
int green = 6;
int rightyellow1 = 7;
int rightyellow = 8;
int rightred1 = 9;
int rightred = 10;
int score = 6;</p><p>void setup() {
pinMode (rightbutton, INPUT);
pinMode (leftbutton, INPUT);
pinMode (leftred, OUTPUT);
pinMode (leftred1, OUTPUT);
pinMode (leftyellow, OUTPUT);
pinMode (leftyellow1, OUTPUT);
pinMode (green, OUTPUT);
pinMode (rightyellow1, OUTPUT);
pinMode (rightyellow, OUTPUT);
pinMode (rightred1, OUTPUT);
pinMode (rightred, OUTPUT);
digitalWrite (rightred, LOW);
digitalWrite (rightred1, LOW);
digitalWrite (leftred, LOW);
digitalWrite (leftred1, LOW);
digitalWrite (leftyellow, LOW);
digitalWrite (leftyellow1, LOW);
digitalWrite (green, HIGH);
digitalWrite (rightyellow, LOW);
digitalWrite (rightyellow1, LOW);
}
void loop() {</p><p>while (digitalRead(rightbutton) == 0 and digitalRead(leftbutton) == 0){}
if (digitalRead(rightbutton) == 1){
  while (digitalRead(rightbutton) == 1){}
  delay (50);
  score = score-1;
  if (score == 1){
    score=2;
    }</p><p>}</p><p>else{
 while (digitalRead(leftbutton) == 1){}
 delay (50);
  score = score+1;
   if (score == 11){
    score=10;
    }
}
digitalWrite (score, HIGH);
digitalWrite (score+1, LOW);
digitalWrite (score-1, LOW);</p><p>}</p>

Step 16: Code Explanation

This is where the code will be explained and annotated. This part is not to be copied and pasted into the Arduino software.

<p>int rightbutton = 12;<br>int leftbutton = 13;
int leftred = 2;
int leftred1 = 3;
int leftyellow = 4;
int leftyellow1 = 5;
int green = 6;
int rightyellow1 = 7;
int rightyellow = 8;
int rightred1 = 9;
int rightred = 10;
int score = 6;</p><p>
Before the void setup, we use int to give each part of our circuit a name. So instead of calling the green LED</p><p>number 6, I am able to call it green. This can option can help us understand code and write it more easily</p><p>without any confusion.</p><p>void setup() {
pinMode (rightbutton, INPUT);
pinMode (leftbutton, INPUT);
pinMode (leftred, OUTPUT);
pinMode (leftred1, OUTPUT);
pinMode (leftyellow, OUTPUT);
pinMode (leftyellow1, OUTPUT);
pinMode (green, OUTPUT);
pinMode (rightyellow1, OUTPUT);
pinMode (rightyellow, OUTPUT);
pinMode (rightred1, OUTPUT);
pinMode (rightred, OUTPUT);
digitalWrite (rightred, LOW);
digitalWrite (rightred1, LOW);
digitalWrite (leftred, LOW);
digitalWrite (leftred1, LOW);
digitalWrite (leftyellow, LOW);
digitalWrite (leftyellow1, LOW);
digitalWrite (green, HIGH);
digitalWrite (rightyellow, LOW);
digitalWrite (rightyellow1, LOW);
}</p><p>In void setup, we setup the input and output parts of our circuit by using the command 'pinMode'. If we do not </p><p>do that, we would not be able to control our parts that are in our circuit. Then, you can see that there is a</p><p>command called 'digitalWrite' that is being used instead of 'pinMode'. This is so that we would be able to tell the </p><p>Arduino software which LEDs we want to have turned on and which LEDs we want to have turned off at the</p><p>start.</p><p>
void loop() {</p><p>while (digitalRead(rightbutton) == 0 and digitalRead(leftbutton) == 0){}
if (digitalRead(rightbutton) == 1){
  while (digitalRead(rightbutton) == 1){}
  delay (50);
  score = score-1;
  if (score == 1){
    score=2;
    }</p><p>

Here, what I am saying is that while both the right button and left buttons are not being pressed, if the right</p><p>button is being pressed, then the light should move one step to the left. This is because when the score = score-1</p><p>It means that the number of the score is reduced by one and therefore the LED that is connected to that number</p><p>is the one that lights up. There is a delay of 50 milliseconds so that the button-pressing is consistent. Also, at the</p><p>end where it says 'if (score == 1) score=2;', this means that I am creating a barrier. So if the score becomes 1, </p><p>then it should go back to 2. This is important so that the light does not disappear into a non existant LED.</p><p>}</p><p>else{
 while (digitalRead(leftbutton) == 1){}
 delay (50);
  score = score+1;
   if (score == 11){
    score=10;
    }
}
digitalWrite (score, HIGH);
digitalWrite (score+1, LOW);
digitalWrite (score-1, LOW);</p><p>}</p><p>
Where it says 'digitalWrite (score, HIGH); digitalWrite (score+1, LOW); digitalWrite (score-1, LOW);', I am telling</p><p>the software to only turn on the LED that has the same number as the score. Anything that is 1 under or 1 above</p><p>the score must be turned off.</p>

Step 17: How the Game Works

To play the game, both players need to be holding down their buttons before starting. Next, one of the players will start counting down. Once that player has finished counting down, both players proceed to click their buttons as fast as they can until the light reaches one end of the line of LEDs. The goal of this game is to push the light far away from until it reaches the opponent's side. That is when you win the game!

Step 18: Improvement Ideas

There are many ways that you can use to improve the game. However, I only covered the basics in this tutorial to allow you to explore and discover new ways of playing this game!

Here is a list of all the improvements that could be made to this creation:

  1. Add a buzzer to make countdown sound before starting to click the buttons. This will allow both players to get ready before starting to click the buttons and the countdowns can be more consistent.
  2. Add a small screen to keep a track of scores of the number of wins each player has.
  3. Add an RGB LED to display different colours before starting the game to make a countdown. For example, you can code the RGB LED to display the colour red, then yellow and finally green. Which is when the players start clicking their buttons as fast as they can.

Step 19: Thank You for Viewing My Tutorial, I Hope You Found It Useful and That You Have Learnt Something New!

█▀██▀█─▀██▀─▀█▀────█─────▀██▄─▀█▀─▀██▀▄█▀

──██────██▄▄▄█────▄██─────██▀▄─█───███▀ ──██────██───█───▄█▄██────██─▀▄█───██▀█ ─▄██▄──▄██▄─▄█▄─▄█▄─▄██▄─▄██▄─▀█──▄██▄▀█▄

───────▀█▄──▄█▀──▄█▀█▄──██───██────────── ────────▀█▄▄█▀──██───██─██───██────────── ──────────██────██───██─██───██────────── ─────────▄██▄────▀█▄█▀───▀█▄█▀───────────