Introduction: Arduino Two Player Reaction Timer Game
Find how fast your reflexes are using this fun game called 'Reaction Timer' that can be made easily using arduino. The main aim of this game is to press a button as soon as possible when you're asked to do so. This is a two player game so two players compete against each other and the one who presses the button in lesser time wins. But both of the players don't have to play simultaneously. Each player has a separate chance when he is asked to press the button in a random time.
Well, this instructable not only tells you how to play the game but also how to make the game. The main setup of this game is an arduino connected to a liquid crystal display (LCD), a button, three LEDs and a microbuzzer. The leds and the buzzer just help you to press the button more early. First the game asks player 1 to get ready then a countdown from 3 is displayed and the leds lit one by one. When the countdown reaches 1, the arduino pauses for sometime confusing the player. Then between a random delay of 5 to 10 seconds it switches on the green led and prints 'go!!!' on LCD. At this time you have to press the button. But you just can't immediately press it as it takes some time for the message to reach the brain and to co-ordinate your hands to press the button. On your pressing the button, it displays the time taken by you to press it in milliseconds or your reaction time, in plain words. If you don't press it at all, it waits for two seconds then displays your reaction time as 2000 milliseconds. The same is repeated for player 2. After all that it finally displays the result that which player won the game or if it is a tie.
The project can be made easily in two hours so this can be a good weekend project. Making it breadboard would save time. It can also be a good project for beginners who are new to arduino. They would learn a lot about printing something on liquid crystal display.
Rules: The rules of the game are simple-
- Each player will get a separate turn.
- Player 1's turn will come first.
- He has to press the button on fourth beep, when the green led glows or the LCD prints 'Go!!'. All these things happen simultaneously.
- Each player can press the button only once.
- The player with lower reaction time wins.
Step 1: Parts and Tools
The following parts are needed to make this project. The total cost of all the parts is about $25 or INR 1500 but the value is not exact as it hardly depends upon the website or store you buy the parts from. All of them can be easily obtained from an electronics hobby store except for the enclosure.
- 1x Arduino nano (UNO or any other compatible board would work) Amazon
- 1x Liquid Crystal Display (LCD) (16x2) Amazon
- 1x Tactile switch
- 1x Toggle switch
- 1x 3.5mm male jack
- 1x 3.5mm female jack
- 1x 10k preset
- 1x Microbuzzer
- 1x 10k resistor
- 1x 100 ohm resistor
- 3x LEDs (color as per your choice)
- Project Enclosure (I'm using a plastic box)
- Male headers
- Female headers
- Rainbow cable
- Soldering iron
- Soldering wire
- Fume extractor
- Hot glue gun with glue stick
- Mini drill
- Wire cutter/stripper
- Helping hands
- Double sided tape
Step 2: Making a Shield for Arduino
The first step for making this project is to make a shield for arduino. The advantage of these kind of shields is that you can easily take off your arduino when you need it for other projects or you want to make changes to the code. I bet you don't want your arduino to be permanently soldered to a single project. In this case you would face real difficulties desoldering it you're bored of the project and really want your arduino back.
Cut a small part of perfboard using a pair of scissors and solder two parts of female headers each of 15 holes to the board. Check if you're arduino fits in easily.
Step 3: Prepare the Enclosure
Using the liquid crystal display, mark on the upper part of enclosure which should be the size of the LCD. Then mark three holes each for an led just below the LCD. Mark two more holes each for the toggle switch and female jack. The holes should be a little smaller than the original size so that all the parts fit in tightly. Use the images above for reference.
Step 4: Start Connecting: the Power Supply
Add the toggle switch and the female jack in the holes that were made earlier. Now connect the positive (red wire) of the jack to one terminal of the switch and the negative (black wire) to the GND pin of arduino. Then connect the other terminal of switch to the Vin pin of arduino. This makes the setup that would power the arduino when the switch is closed (ON).
Step 5: Connect the Tactile Switch
Add the tactile switch to the hole that was made in the lower part of box. Instead of making a large hole, I made four small holes so that the wires can pass through and the switch remains completely outside the box.
Now solder two wires to the upper terminals of the switch. Solder a third wire through a 10k resistor to the upper right terminal. Now connect the first wire to arduino 5v pin, the second wire to arduino digital pin 10 (d10) and finally the third to arduino GND. See the schematic above for reference.
Step 6: Connect the LEDs
Leds are are just added here to make it look good. They also help a lot in playing the game as when you see the green led lit, you immediately press the button. I used red, green and yellow leds but the color of the leds is completely your choice. To give even a better look and to prevent the light shining on your eyes, I diffused the leds using a piece of sandpaper.
Fix the red led in the first hole, yellow in the second hole and green in the third one. Now connect all the negative terminals together and solder a piece of wire to it. Solder three more wires to the positive terminals of all the leds. The reason why I didn't add current limiting resistors as the brightness greatly reduces. You may add it but it still works without it. See schematic above for connections.
Following are the connections of the leds-
- Positive of red led ---- Arduino digital 7
- Positive of yellow led ---- Arduino digital 8
- Positive of green led ---- Arduino digital 9
- Negative of all the leds ---- Arduino GND
Step 7: Prepare and Stick the LCD
Fix the LCD in place using double sided tape. Using some male headers, prepare a socket that would fit in the LCD. Then connect pins 1,5,16 together. Also add a 100 ohm resistor between pins 2 and 15. This is used to power the led present inside LCD which acts as a backlight. Then add a preset with its upper pin connected to pin 3 of LCD, lower left pin connected to pin 16 and lower right pin connected to pin 2. See schematic in step 8 for reference.
Step 8: Connect the LCD
Connect the LCD to arduino according the schematic given above. Following are the connections of LCD-
- LCD pin 2 ---- Arduino 5v
- LCD pin 1 ---- Arduino GND
- LCD pin 4 ---- Arduino digital 12
- LCD pin 6 ---- Arduino digital 11
- LCD pin 11 ---- Arduino digital 2
- LCD pin 12 ---- Arduino digital 3
- LCD pin 13 ---- Arduino digital 4
- LCD pin 14 ---- Arduino digital 5
Step 9: Connect the Microbuzzer
Microbuzzer is simply a buzzer that is smaller in size than a normal buzzer and produces a beep as loud as a normal buzzer. Here it is just added to add sound to the game. I don't have much information about the tone and melody functions so I was not able to add tones to the game so I decided to add simple beeps to it.
Connect the positive terminal of the buzzer to arduino digital 6 and negative to arduino GND.
Step 10: Upload the Code
Copy the code given in the .txt file given below and paste it to your arduino IDE screen. Connect your arduino and upload the code. I didn't add the comments in the code as I was short of time.
Step 11: Prepare the Power Supply
I'm using a 12v adapter to power the project. A 9v battery can also be used here but I would recommend an a adapter as 9v battery would drain away very fast. But if you're using an adapter it would have a jack that would not fit in a 3.5mm female jack. In this case cut away the adapter jack and add a 3.5mm male jack. This would also help with other projects.
Step 12: Finishing Touch
The last step for completing this project is to add a piece of white paper at the top of the box. Cut a required amount of white paper then make holes in it. Finally stick it to the box.
Step 13: You're Done!
After completing everything, put your arduino inside the socket in the correct way. Connect it to a battery or a power supply and switch it on. If the LCD switches on and prints '***Welcome***' it means that you have done it alright. If only the backlight is on but nothing is displayed, turn the preset slowly using a flat head screwdriver. If it still does not work, re-check all the connections and try again.
That's it! Just switch it on and challenge your friends. Feel free to modify and give it a better look. Do post your pictures if you've made it and leave suggestions to make it better.
That' the end of this intructable. Hope you enjoyed it and got some good information. Don't hesitate to ask any questions and tell me if I have done any errors. THANK YOU :)
Participated in the
How to Play ____