Introduction: Arduino Fastest Reaction Time Game for 1-4 Players
The official Arduino starter kit with tutorials is a fantastic way to learn the basics and all the of the various things you can do and I can't recommend it highly enough. But once I had gone through making LEDs blink, buzzers buzz, and motors turn I thought about how I could turn that into something my kids and I could enjoy playing with, and this is the result: a fun, fully featured and functioning 4 person fastest reaction time game. This game can be built using nothing but parts from the Arduino starter kit. This tutorial includes an optional 74HC595 chip (a very common and inexpensive integrated circuit available in almost any expansion pack or on their own) that can be omitted without much impact on the final result. This will be explained in more detail in the steps.
- 1-4 players
- A random delay with pulsing yellow light after the start button is pushed.
- After the random delay a white light, piezo sound, or both signal time to go; the fastest player to press their button wins!
- The winning time is shown, as well has how long behind the winner each player is.
- One player can play on their own to try and best their time.
- Players are disqualified if they press their button too early :)
- Full instructions are shown on the LCD at each step, but players don't need to be of reading age. My 3 year old loves to play.
Arduino Uno or Nano (Or compatible clone). I used a Nano clone for my build.
Jumper Wires (Various colours and lengths)
3x small breadboards (or a couple larger ones)
8x 220 Ohm Resistors
6x 10K Ohm Resistors
2x - Standard pushbuttons. I used a green and red one.
4x - Arcade style push buttons with built in LEDs.
1x LCD alphanumeric (16x2 characters or larger)
1x piezo or equivalent small speaker
1x 10K potentiometer
1x White LED
1x Yellow LED
1x Nine Volt Battery holder clip
1x simple two position switch.
Materials for your case (I used plexiglass, screws, and some wood scraps)
1x 74HC595 chip
4x coloured LEDs (blue, green, yellow, red)
Step 1: Download the Code for the Game and Compile / Upload It to Your Arduino
If you've never sent any code to your Arduino before, please read up and try a simple tutorial from the Arduino website before continuing. https://www.arduino.cc/en/Guide/HomePage - read on once you've successfully got a simple program working on your board or have done so before.
Why the code before the circuit?
It may seem like putting the code on first before you've built the circuit is doing things backwards, but this will allow you to build parts of the circuit and to test as you go. If you build the whole circuit, then put the code on and test, it is harder to isolate circuit problems, and not wiring things correctly the first time is an inevitable part of the fun :) . I've added a routine to the code that always executes right after boot that cycles through lighting all the LEDs, sounding the piezo, and displaying text on the LCD so you'll know if you have most things wired correctly.
Compatibilityand IDE suggestion
I have tested that this code works on the Arduino UNO and NANO. It may work on others but this is untested. For IDEs, the code provided is compatible as is with the Arduino IDE at https://www.arduino.cc/en/main/software and also PlatformIO http://platformio.org/platformio-ide - if you have another IDE that you use it will most likely work but is untested.
If you just want to get the code on your Arduino and don't know or care to know about the programming aspect, the Arduino IDE works just fine and is nice and simple. If you want to do any serious development or tinkering, I'd suggest PlatformIO or another more advanced IDE as the Arduino IDE lacks some pretty standard features like code complete and is really only designed for single file projects which this is not.
Getting the code on your Arduino
I have published the code in a public github repository. If you are a coder, feel free to improve the game by making pull requests. https://github.com/plocke/arduino-fastest
If you just want to get going, follow these steps:
- Download the latest version of the stable code at https://github.com/plocke/arduino-fastest/archive/...
- Unzip the archive. Then:
- If you are using the Arduino IDE, put the just 'fastest' directory alongside your other projects and open the fastest.ino file.
- If you are using PlatformIO, just take the whole unzipped archive as your project.
A note on drivers for Arduino clones
If you're not using a branded Arduino (meaning you're using a cheap clone, nothing wrong with that, they work great in my experience) you may need to install a driver as they use a different chipset to communicate with your computer. I found a driver for my nano clones (linked from the parts list) here http://kig.re/2014/12/31/how-to-use-arduino-nano-m...
Step 2: Build a Full Prototype Circuit. Test As You Go.
The next step is to build the circuit; see the attached schematic images or follow the links below. I have fully built out the circuit virtually at circuits.io for you to follow. Note these pages load very slowly. Give them some time.
Breadboard view: https://circuits.io/circuits/3000931-arduino-four-...
Schematic view: https://circuits.io/circuits/3000931-arduino-four-...
Test each part as you go, and don't get frustrated - it is very easy to make wiring mistakes. You do not need a battery during this phase, as you can power the prototype with your USB connection. (Actually you don't need a battery at all if you're willing to power the game via a USB cable all the time, but it makes it less portable and means you always need a USB power source or laptop to plug into)
As mentioned in the introduction if you don't have a 74HC595 chip, you can leave out that portion of the circuit with the 4 'winning' LEDs. The only thing you won't get is the winner's button lighting up (if you're using arcade style buttons with built in LEDs) and it really isn't a big deal at all.
Replacing the arcade button LEDs
The arcade buttons I link to in the parts list are designed for 12V. This doesn't matter for the switc part, but it does mean the lights will be very dim as the arduino will only send 5V to them. Luckily they are easily replaced with your own LEDs: Simply twist the bottom, open them up, and pull out the 12V LEDs and replace them with your own
Step 3: Think Through Your Case, and Harden Your Circuit With Hot Glue
If you like to solder, you can certainly solder your circuit or parts of it. However, given the inexpensiveness of small breadboards and how much time it saves, I prefer to simply hot glue everything in place once I've thoroughly tested the circuit. It is fast, stable, and means you don't have to unbuild your circuit once it is working.
I did solder a few things in my build where jumper wires were connected to things not by breadboard to ensure a good connection, such as the wires to the power switch and the arcade switch terminals. If you don't have a soldering kit or are not comfortable soldering, just ensure the wire is tightly wrapped to the metal terminals of the switches before adding a drop of hot glue.
A couple tips from my experience: Before you glue anything, decide how you want things laid out in your final case. I ended up using three breadboards:
- One is attached to the inside top of the case, and holds the LCD and wait/go lights so they are central and visible to all the players
- One just has the Arduino Nano with lots of outgoing jumper wires and is mounted at the edge on the bottome so its USB port is available.
- One is mounted in the middle bottom and holds all connections to the Arcade buttons and the winning lights and the 74HC595 chip.
You can see my final build from a few angles in the next step.
Step 4: Put It All in a Case, and Enjoy!
This step took me much longer than I thought it would. Take your time. There are number of things to consider when putting your circuit in your case:
- This is a game for up to four people. Don't make it too small
- You'll want to leave ability to open your case up and inspect/fix your circuit if anything comes loose and stops working correctly.
- Look at the annotations on my pictures on this step for additional tips
Extending the game through code
I have a few feature ideas that I have not had time to implement - if you implement any of these please be sure to submit your code back to the project through a pull request:
- Keeping track and displaying the fastest time since boot when no game is happening
- Keeping track of the top 3 times persistently and displaying those as part of a no-game loop (through EEPROM reads/writes)
- Giving each colour their own winning sound as in addition to just a light
Thanks for reading, and I always appreciate comments seeing others' completed builds, and also feedback on if anything is confusing, missing, or how anything could be easier to follow.