Introduction: Arduino IR Sensor Timer
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
http://www.aliexpress.com/item/Free-Shipping-Nano-... 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.
We have a be nice policy.
Please be positive and constructive.