Arduino IR Sensor Timer




Introduction: Arduino IR Sensor Timer

About: Degrees in EE, specializing in Digital Signal Processing. Working as a software engineer for 20+ years.

Make a high accuracy timing circuit using two low-cost IR sensors and an Arduino microcontroller.

This device can time the passing of an object past two checkpoints with high accuracy. Its intended use is for high school or middle school physics experiments. The speed of an object can be computed by timing how long it takes to cross the two sensors.

Your total cost can be less than $5 US if you have some basic materials available, such as a soldering station.

Bill of Materials:

  • Arduino Microcontroller, I recommend an UNO, or Nano clone like WARNING: They may have trouble communicating with a MAC. You may want to use official Branded Nano on Apple.

  • (2) IR proximity sensors, like

  • If you use a Nano, I like these screw terminal breakout boards:

  • You may want to wire your IR sensors with headers, like

  • If your Arduino board did not come with a USB cable, you may want a USB-mini like this one for Nano:

Step 1: Wire IR Sensors

Wire the Vcc pin on two of these sensors to the 5V output from your Arduino Uno, Nano, or similar.

Wire the GND pin on each of these sensors to a GND pin on the Arduino.

Wire the OUT pin on one sensor to Arduino pin D2.

Wire the OUT pin from the other sensor to Arduino pin D3.

Step 2: Load Sketch

Load the attached sketch into the Arduino.

You will note that it uses the interrupts 0 and 1, which correspond to pins D2 and D3 respectively.

When the sensor attached to D2 senses a nearby object, the time is recorded.

When the sensor attached to D3 senses an object, this time is recorded.

The difference between the two times are reported on the USB/Serial port in microseconds.

Step 3: Monitor Time on Serial Port

If you just used the Arduino IDE to upload your sketch to the device, the easiest way to use the system is through the Arduino Serial Monitor feature. The IDE should already have the port set from the sketch upload, so just make sure that the serial monitor is set to the correct Baud rate, 115200 in the attached sketch.

Pass an object over the first sensor, and the on-board LED should light up.

Pass an object by the second sensor, and the on-board LED should turn off, and the elapsed time, in microseconds, should be printed to the serial monitor.

If you do not wish to monitor the output using the Arduino IDE Serial Monitor, there are many ways to communicate with a serial port. On Windows the putty program has the ability to communicate to the serial port. The Arduino serial port uses typical defaults, like 8-N-1, so the only setting necessary is the Baud rate of 115200. On LINUX I prefer:

screen /dev/ttyUSB0 115200

Use Ctrl-a k to kill when done.

Another common program for serial communication is cu,

cu -l /dev/ttyUSB0 -s 115200

type "~." to exit.

It can also be convenient to read the device directly after establishing proper settings:

stty -F /dev/ttyUSB0 115200

tail -f /dev/ttyUSB0

Substitute your serial device name for ttyUSB0 if your Arduino does not attach with this name. If your account is not in a group that allows access to the serial devices, often (dialout), try these commands with the sudo prefix.

Be the First to Share


    • Mason Jar Speed Challenge

      Mason Jar Speed Challenge
    • Bikes Challenge

      Bikes Challenge
    • Remix Contest

      Remix Contest

    5 Discussions


    7 months ago

    Hello! Is it possible to only use one IR sensor?


    Question 2 years ago

    Can we use same setup for measuring time lapse of vehicle from one point to other by using high range (5 meter) sensor.


    Question 2 years ago on Step 1

    I have completely constructed this project and installed the Sketch EXCEPT for this instruction: "Wire the Vcc pin on two of these sensors to the 5V output from your Arduino Uno, Nano, or similar." My Arduino Uno has only one 5V output pin. I have no idea how to wire BOTH of the Vcc wires to ONE 5V output. Please explain further. Thank you.


    Answer 2 years ago

    You could use a small breadboard. Run the 5v from you Arduino to a column of the breadboard, then your Vcc wires to that same column.


    Question 2 years ago

    Thanks for this article. Would the ir emitter/sensors used here work fast enough to act as a chronometer (with proper construction of course)? I'm looking to measure the velocity of a pellet from an air gun pistol. The pellet is 5 mm long and travels at approximately 360 fps. (Covers its own length in about 45 microseconds).