Projects

Kids' Basics: Reaction Timer

Daniel Koch

Issue 37, August 2020

This article includes additional downloadable resources.
Please log in to access.

Log in

Test your skills against yourself and your friends with this Arduino-based reaction timer.

BUILD TIME: AN HOUR OR TWO
DIFFICULTY RATING: BEGINNER

This Arduino-based reaction timer is designed to be simple yet engaging. You will be able to spend as long as you like trying to improve your times or increase the difficulty level. While we have provided a fairly basic design, many makers will be able to take this building block and add to it to make things harder or more interesting.

The basic idea is to use buttons to start and stop a timer. We’ve added a random feature to make it a genuine reaction timer. We have designed two configurations here. One requires you to hold down a button and wait for a light, before letting go and then pressing another button. This means you can’t just hover over the trigger button.

The second version presents three buttons and three lights. After a random time delay, started by pressing any button, one light will activate and you need to hit the corresponding button to get a time. Both versions use Serial Print to display the results on a computer. We’ll discuss expansions and modifications toward the end of the article.

SOFTWARE PREREQUISITES

You will need to have an Arduino Uno or compatible board, and the Arduino IDE application installed on your computer. The Arduino IDE is where we will load code, and compile it onto your Arduino Uno board. You can download the application for free from www.arduino.cc/en/Main/Software. Follow the prompts to install it on your Windows, Mac, or Linux based computer.

With your Arduino connected to your computer via USB, go to Tools › Board and ensure Arduino / Genuino UNO is selected, or the appropriate board for what you are using.

Then also select Tools › Port and click on the one that shows USB. The precise wording will depend on your operating system.

In order to load code onto your Arduino board, open the Arduino IDE.

Go to File › Open and select the file noted in the article (Each file is within a folder of the same name).

THE CODE

We have already written the code you need for this project and made it available on our website for you to download. Go to our website and find this project. At the bottom of the page, there will be a link to download the file.

Note: You will need to log in to the website to download the file. Registering is free.

Instead of describing the code in detail here, we have decided to use comments within the code itself to describe what is happening. This means the explanation cannot be as detailed as if it were described in the article. It also means a lot of grey text messing up your code. However, it gives a big advantage. We can constantly update the code as bugs or better ways of doing things are found. You might be used to seeing the code explained in the article. That means we cannot change it after writing, because the code part of the article won't make sense anymore. Using comments means you can read the article with any code version and it is still relevant.

USING BREADBOARDS

We have built our prototypes on a long solderless breadboard but you can use two short ones if you like. Just remember you will have to link the power rails and make sure both small boards are aligned so the power rails meet correctly.

If one board is the opposite way up to the other, you’ll be connecting the negative (-) to the positive (+) and causing a short circuit. Though most small breadboards have interlocking tabs, and if you can interlock them, you generally know they're the right way around.

If you have not used a breadboard before and want to learn more about them, see our Breadboarding Basics article from Issue 015.

You will also need a USB cable compatible with your Arduino Uno, which may or may not be supplied with the Arduino Uno itself. Power for these projects is provided from your computer. No additional power is required.

Build 1:

Two Button

ELECTRONICS Parts Required:JaycarAltronicsCore Electronics
Solderless BreadboardPB8820P1002CE05102
Wire LinksPB8850P1014ACE05631
Plug to Plug Jumper LeadsWC6024P1022PRT-12795
3 x 150Ω Resistors*RR0552R7538CE05092
3 x 10kΩ Resistors*RR0596R7582CE05092
3 x LEDsZD0152Z0980COM-09856
3 x Pushbutton SwitchesSP0609S1135COM-09190
3 x 100nF CapacitorsRM7125R3025BCE05188
1 x Arduino Uno or Compatible BoardXC4410Z6240CE05629

ELECTRONICS Parts Required:

* Quantity required, may only be sold in packs.

This build has two just two buttons to operate the reaction timer game. This one requires you to hold down a button and wait for a light, before letting go and then pressing the other button. This means you can’t just hover over the trigger button.

Step 1:

Place the breadboard so that the outer red (+) rail faces away from you and the outer blue (-) rail is closest to you. Insert two switches into the breadboard, one at each end. Ours only fit one way, as the legs are not spaced widely enough to cross the span in the middle of the board if they are rotated 90°.

Note: Refer below for details on switches.

Step 2:

Insert an LED in the middle of the board. The short leg (cathode, or - ) goes to the upper blue (-) rail. Add a 150Ω resistor ( brown-green-black-black, or brown-green-brown) between the long (anode, + ) leg of the LED and another row to the side.

Note: Refer below for details on LED polarity.

Step 3:

Use a multimeter to determine which pins of each switch are connected, and which are separate. Add a wire link to connect one side of each to the (+) rail.

Note: Refer below for details on these tactile switches.

Step 4:

Add jumper leads to the other side of each switch, and use a 10kΩ resistor ( brown-black-black-red, or brown-black-red) to connect the same side to ground. Add a 100nF capacitor across the pins of each switch.

Step 5:

Connect the jumper lead of one switch (we chose the left hand switch) to pin 2 of the Arduino. Connect the jumper lead from the other switch pin 3. Also, connect a jumper wire from pin 8 of the Arduino to the end of the 150Ω resistor.

Step 6:

Use two jumper leads to connect the power rails to the Arduino, being careful that the ‘GND’ terminal connects to the blue (-) rail, and the ‘5V’ terminal connects to the red (+) rail.

Also add two wire links, one to join the upper and lower blue (-) rails and one to join the red (+) rails. You may not have used the lower rails depending on your switch design. We didn’t need to.

Now all that remains is to plug in the USB cable and upload the code. Because the circuit draws next to no current, we’ll power it from the USB connection via the Arduino.

It needs to stay connected to display the results anyway, so having it powered via the USB is not a penalty in this case. You will also need to open the serial monitor in the Arduino IDE to get your results.

Note: To access the serial monitor, go to Tools › Serial Monitor in your Arduino IDE application.

Build 2:

Three Button

This build uses three buttons to add more difficulty to the reaction timer game. After a random time delay, one light will activate and you need to hit the corresponding button to record a reaction time.

Step 1:

Place the breadboard so that the outer red (+) rail faces away from you and the outer blue (-) rail is closest to you. Insert three switches into the breadboard, one at each end and one in the middle.

Ours only fit one way, as the legs are not spaced widely enough to cross the span in the middle of the board if they are rotated 90°.

Step 2:

Insert three LEDs, one next to each switch. The short leg (cathode, or - ) goes to the upper blue (-) rail. Add a 150Ω resistor ( brown-green-black-black, or brown-green-brown) between the long (anode, + ) leg of each LED and another row to the side.

Note: Refer below for details on LED polarity.

Step 3:

Use a multimeter to determine which pins of each switch are connected, and which are separate. Add a wire link to connect one side of each switch to the (+) rail.

Note: Refer below for details on these tactile switches.

Step 4:

Add jumper leads to the other side of each switch, and use a 10kΩ resistor ( brown-black-black-red, or brown-black-red) to connect the same side to ground. Add a 100nF capacitor across the pins of each switch.

Step 5:

Connect the jumper lead of one switch (we chose the left hand switch) to pin 2 of the Arduino, the lead from the next switch to pin 3, and the last switch to pin 4. Also, connect a jumper wire from pin 8 of the Arduino to the remaining end of the first 150Ω resistor, pin 9 to the second and pin 10 to the third.

Step 6:

Use two jumper leads to connect the power rails to the Arduino, being careful that the ‘GND’ terminal connects to the blue (-) rail, and the ‘5V’ terminal connects to the red (+) rail.

Also add two wire links, one to join the upper and lower blue (-) rails and one for the red (+) rails. You may not have used the lower rails depending on your switch design. We did this time around.

Before applying power, check that the switch connected to pin 2 corresponds to the LED connected to pin 8, the switch for pin 3 matches with the LED from pin 9, and pin 4's switch has pin 10's LED close by. If any LED is near a different switch, change the Arduino pin it connects to.

Now you can plug in a USB cable, open serial monitor, and load the code. To play, start the Serial Monitor in the Arduino IDE, press any button on your breadboard, then wait for an LED to illuminate. Press the corresponding button as quickly as you can. The results display in Serial Monitor.

Note: To access the serial monitor, go to Tools › Serial Monitor in your Arduino IDE application.

What's Happening?

In terms of hardware, both versions have little going on. The 10k resistor connecting the switch to ground stops spurious signals false-triggering the input, something that can happen when the input ‘floats’. It is standard practice when using switches, or indeed most digital inputs. These signals are usually very small currents but can have voltages big enough to be recognised by the Arduino. So little current flows through the 10kΩ resistor that when a real signal does come along, it is not affected.

The 100nF capacitor stops the switch ‘bouncing’. Any switch does not make immediate contact, but rather the metal contacts physically bounce slightly. This effect is very short and not noticeable to humans, but the Arduino is fast enough to read it as several separate signals. The effect is compounded by human muscles which are also not as smooth as we would like to think sometimes.

When a button is pressed, the 5V connected to one side is now in contact with the side connected to the Arduino, and is read by the microcontroller as a HIGH signal. At all other times, the input is held LOW by the 10kΩ resistor mentioned previously.

In terms of code, most of the details are listed as comments, but the basic structure is this:

After the code's initial setup, it waits for a button push from the button connected to pin 2. When this is read, a random timer starts. We have set the upper and lower limits of that timer so that it can be anywhere from one to fifteen seconds. If the button is released during this time, the timer is stopped and the LED blinks to tell you that you have failed (or were trying to cheat).

When the timer expires, the LED is immediately lit with constant light. A counter starts recording the number of milliseconds between when the ‘go’ signal is given by the LED, and then the other button on the opposite side of the board is pressed. When that button is pressed, the counter stops, the number is displayed still in milliseconds on the Serial Monitor via the Serial Print function.

In version 2, the random timer starts when any button is pressed then released. After the time expires, one of the three outputs is chosen randomly and its LED illuminated. At this point, the counter starts counting the number of milliseconds until the corresponding button is pressed. The result is displayed via the Serial Print function.

WHERE TO FROM HERE?

To expand version 1, you could mount the switches on separate boards much further apart. You could also fiddle with the random timer values to make the wait even longer.

The main candidate for modification is version 2, where the switches could be replaced by another sensor, such as an infrared sensor used in conjunction with a laser tag gun, or a paddle switch that you need to throw a ball at. The LED would still indicate which target to aim for.

If you feel like really changing the code, you could use the three-switch hardware to have a fastest-finger-first device. You would code it so that all three LEDs light at the same time, then the code searches for which switch is triggered first by measuring all three. You could have the code display the results in the serial monitor, or perform the maths and light the appropriate LED, or both.

The same applies to the two-switch version but you will only have one LED and will need to rely on the serial monitor to display the results.

Other options include changing out the switches for panel-mount or arcade switches and mounting the entire thing in a box, with switches and LEDs in the lid and the board and Arduino inside. You will still need a computer of some sort no matter what you do.

The Quirks of LEDs & Switches

LEDs

Once upon a time, there were firm conventions for the manufacture of LEDs. The Cathode, or negative terminal, was always the leg connected to the anvil. The Anode, or positive, was always connected to the post. The anode leg was longer than the cathode leg, and the cathode was represented by a flat spot on the rim.

Today, such conventions are no longer universal. This is in part, but not entirely, due to Chinese manufacturers ignoring such standards in the pursuit of cheaper products. This is not to say some very good quality LEDs cannot be bought from China, because they can. It’s just that even in some of the better brands, the standards are no longer consistent.

The flat spot on the rim usually still indicates the cathode, but there are plenty of LED examples around with no rim, and some without a flat spot on the rim. There is also a fairly even split between those that follow the anvil/post connection above, and those that are the opposite. We even have a batch on the workbench from a reputable brand which is a mix of both.

We have not yet seen an example where the short leg is not an indicator of the cathode. So far, this is the one convention that seems to have held, but there are cases where the legs are the same length.

We even had one batch of LEDs arrive which had no rim, a mixture of both anvil/post configurations, and legs the same length. Our only option was to use a multimeter to verify them one by one.

SWITCHES

Tactile switches are usually made with a membrane or flexible contact which, when the button is pressed, connects two sides of the switch. That is simple enough, but what is not so simple is how these switches are sometimes physically constructed. Take, for example, the tactile switches used in this project. It would be easy to assume that, looking at the switch from above, pins A and B are connected, C and D are connected, and the contact or membrane bridges A/B to C/D. In fact, the switch is constructed as you can see in the dismantled version. The round flexible contact is slightly curved (whether it is convex or concave depends on where you are viewing it from). It sits in contact with the two small outer pads, which are connected to contacts A and C. The pad in the centre of the switch is connected to contacts B and D. This is why the switch contacts used are across the shorter gap, not across the larger gap formed by the body of the switch. Some people find this counter-intuitive, and this is why we recommend always checking your switch contacts, what ever switch you have, with a multimeter before using it.