Reaction Timer


Today’s goal is to create a simple reaction timer using the Arduino. You will learn how to use a button as an input, how to use while loops, how to declare and use variables and how to use the Serial Monitor.

Screen Shot 2017-09-02 at 11.01.40 AM


For the reaction timer you will build 2 separate circuits: one circuit with a button and one circuit with an LED. Both circuits can be seen in the picture. You know how the LED circuit works be we are going to have a closer look at the button circuit.

The two left legs of the button are connected together internally and the two right legs of the button are connected together internally. This means that when the button isn’t pressed pin 3 is connect to GND through a 10K resistor. The resistor is important because it prevents a short-circuit when you press the button. When the button is pressed pin 3 gets connected to 5V and you can use the Arduino software to detect this.

Screen Shot 2017-09-03 at 10.52.19 AM


When declaring a variable you have to include 2 things: the type and the name of the variable, all of our variables are integers.

Serial.begin(9600) allows us to use the serial monitor to display messages on the computer screen. Serial.println(” …”) is used to actually print messages on the screen.

All the while statements are used to wait for something to happen with the button. The empty curly braces {} after the while statement tell the Arduino to do nothing as long as the condition in the while statement is true.

The millis() command gives the time since the Arduino was turned on. We record this time when the LED turns off and again when the button is pressed. The difference between those 2 times gives us the reaction time.



Controlling 2 LEDs


The goal is to build a circuit with 2 LEDs. Each LED has to be able to be controlled independently using the Arduino.


For this to work you have to build 2 independent circuits, one for each LED. Notice how both LEDs share the same ground (GND) but the plus side of each LED is connected to a different digital port on the Arduino. It’s important that each LED is connected to its own digital port on the plus side, this is the only way to control each LED individually. When pin 7 is set to HIGH current will flow through the LED and the resistor to ground and it won’t have any effect on the LED connected to pin 8.

Screen Shot 2018-09-11 at 10.30.47

CodeScreen Shot 2018-09-11 at 10.58.53

Setup is used to declare pin 7 and pin 8 as outputs so we can use them to control the LEDs.

The loop is used to make the LEDs blink, when the first LED is on, the second LED is off and vice versa. LEDs are on for half a second before switching. There is no delay between turning off pin 7 and turning on pin 8, this makes it seem like it’s happening at the same time.

Have a good look at the code and make sure you understand what happens when the code ends the loop and starts over again.


  • Make both LEDs blink at the same time
  • Add more LEDs and make patterns
  • Add more LEDs and make them go on and off randomly
  • Make a set of (safe) traffic lights



Your first Arduino program

Programs in Arduino are know as “sketches”, to create a new sketch go to File –> New. You should now have a blank sketch that looks like the picture on the left. The first part of a sketch is setup. The setup code runs only once at the start, this is where you set up variables, ports, sensors, … The second part of a sketch is loop, the loop code runs continuously.

Screen Shot 2017-08-23 at 8.16.41 AM.pngOn the left you can see an example of a simple sketch, let’s look at all the code … Let’s start with the setup, in setup we are telling Arduino that we are going to use pin 10 as an output, that means that we can tell the Arduino to send information to pin 10. Whenever you want to use a port you have to tell Arduino which ports you want to use and if they will be inputs or outputs.

The first command in loop tells Arduino to turn on port 10 (digitalWrite), what this means is that the port will go from 0V to 5V (HIGH) and if you have an LED connected to this port it will light up. The next command (delay) tells the Arduino to do nothing for 1000 milliseconds or 1 second. Then we turn port 10 off, it will go back to 0V (LOW) and the LED will turn off as well. Lastly we have another wait command. After the wait command the program will go back to the start of loop and the program will start again. The result is an LED that will blink with a 1 second interval.

Things to try:

  • Change the delays and see what happens
  • Connect an LED to port 7 and change the code accordingly
  • Connect 2 LEDs to 2 different ports and make both blink at the same time
  • Create different blinking patterns for both LEDs

Install the Arduino software

arduinoGo to the Arduino website to download the software, look for “Download the Arduino IDE”. Make sure you download the correct version for your Operating System.

Run the installer and open the program. You have to go through the following steps the first time you use your Arduino:

  • Connect the Arduino using a USB cable
  • Select the correct Arduino in the software: Tools –> Board –> Arduino/Genuino Uno
  • Select the correct port: Tools –> Port –> select the USB (Mac) or COM (PC) port

You might have to select the port again if you connect a different Arduino.


Some basic Electronics

You should have a basic idea of the different components in your bag and what they do. If you’re still looking for information use these websites:

Now you’re ready to start building your own circuits …

Breadboard Connections

You need to know how a breadboard works. This image shows how all the holes in the breadboard are connected. Breadboards provide an easy way to build circuits without having to do any soldering.


Basic Circuit

This is an example of a basic electronic circuit. On the left you see the power source, the long line represents + and the short line represents -. If you would connect the + directly to the – you would create a short-circuit and could damage your power source. The resistor “resists” current flowing through the circuit and prevents a short-circuit. More resistance = less current.

In any circuit you need to have an uninterrupted path from + to – before any current can flow.

LED Circu

Above is an example of a circuit with an LED. You can see a power source, an LED and a resistor in the circuit. You can also see that there is an uninterrupted path for the current to flow, the current will pass through the LED and through the resistor. You should be able to build this circuit using a breadboard and components.



  • What will happen if you change the value of the resistor?
  • What will happen if you put the resistor in front of the LED?
  • What will happen if you turn around your LED (switch + and -)?
  • What will happen if you add a second LED after the first one?