Reaction Timer

Goal

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

Circuits

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

Programming

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.

 

Advertisements

One thought on “Reaction Timer

  1. Alex 20 Jan 2018 / 7:15 pm

    I’m no longer sure the place you are getting your information, however great topic. I needs to spend a while studying more or understanding more. Thank you for great info I used to be looking for this info for my mission.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s