Tuesday, May 1, 2012

Reaction timer using arduino

A reaction timer is the one that measures the time we take to react in response to an external event.

In this post we will design a basic reaction timer using arduino board.

The external event is the glowing of an led, upon which the user has to press the pushbutton. The time difference between the lighting of the led and the user pressing the button is the reaction time of the user.

We will need

  • An led 
  • A push button or switch 
  • 2 Resistors 220 ohm or higher ( value taken randomly) 
  • An Arduino uno board


  • Connect the anode of led to digital I/O pin2 and cathode to the ground through the resistor
  • Connect one end of the pushbutton to 5V of the arudino and the other end to digital I/O pin 7 and to ground through the resistor.
  • The bread board as well as the schematic connections are shown in the figures below.

Working :

  • Digital I/O pin2 acts as output and digital I/O pin7 acts as input.
  • The led connected to digital I/O pin2 should be turned on after some random interval .
  • As soon as the led is turned on the user should press the push button, which is connected to digital i/o pin 7
  • The Push button sends a high to pin 7.
  • While waiting for the press of the push button the program calculates the delay in miliseconds.
  • Once the high on pin 7 is recieved it the delay value is printed to the serial window.

Program :

The random function returns a random number between 0 and the number passed as argument to it, using this we can make sure that the on each iteration the led lights up at random intervals.

The while loop keeps waits for 10 milliseconds before checking the state of the pushbutton, a variable,timer, is incremented on each iteration.

After recieving the high on pin 7,the delay value in milliseconds is written to the serial window.

No comments:

Post a Comment

Follow by Email