Arduino-based Photogate Timer

By | October 19, 2012

Mostly for the Science Olympiad – Division C – Maglev event, but also just to learn more about Arduino in general, I tried to build a photogate setup on the cheap;-) I expect the Maglev event’s timed part to be somewhere in between two and three seconds. So even for test runs, a hand based stop watch is not really an option.  Some high schools apparently have photogate timers for their Physics education (we had them even at the middle school level in Germany around 1982), but our charter school does not. So those are basically the reasons why I set out to build something to use.

After looking at the commercially available setups and finding that they are somewhat out of what I wanted to spend, I found Liudr’s Photopage which gave  me hope. He used rather small gates which would not work for me. So the first step was to find some gates which could handle >= 8cm distance. I found that the Honeywell HOA 6299 gates should be able to do that and that it should be really easy to interface them to the Arduino ports;-) I got two pairs @ newark.com for $63, not exactly cheap but cheaper than one complete commercial gate.  They work very well with my Mega ADK;-) I currently use a breadboard, but it is not really needed. The 5V pin works well as power supply for the gates, and the outputs go straight to pin 2  and 3 respectively.  Any 5V based Arduino should be able to handle the gates, the ADK is kind of overkill for this, but that’s what I have;-)

For the software, there are two parts. The Arduino sketch gets interrupts from the two gates and basically takes it’s internal time and sends lines over the USB/serial connection to the computer which acts as display and interim time source. The Arduino does not care what will be done with the events, it just sends one line with three parts separated by colons. The gate number ( 1 or 2), the time in milliseconds since the start of the board and the microseconds within the current millisecond. Lines look something like

1:123324:003
2:134456:345

That makes it really easy to do different things depending on what you want to do. My little sketch PhotoGates.ino is here, if somebody wants to play with similar things;-)

For the stopwatch/display on the computer (I prefer Linux;-), I Frankenstein’ed the dclock sources, to do what I want;-) That was the best source which would work well in different sizes, I updated it to show three digits for the milliseconds 😉  Right now that piece is really raw!! But it takes the lines from the USB/Serial port (Watch out, I don’t think the option to change the port actually works yet!!) and handles them correctly. When it sees a line from gate one, it stores the time values  and starts a clock from null  on the computer to show a moving time until a line from gate two arrives. When the line from gate two is handled, the difference between that and the save time from gate one is pushed to the display.  So no matter how long the events take to get to the destination or how busy the computer is, the time should be correct in the end;-) My sources are here dclock-2.2.2-mw.tar, but they might still need some improvements. For other OSs, I don’t know but something similar should be possible as well. But I prefer Linux;-)

Right now, I have the two gates right behind each other, something like 7 cm apart. That’s just for now for easy testing;-) The fastest I could cover that distance with a pencil or a kebab stick (1/8″ dowel;-) in my hand, was 0.014 seonds;-) That’s about 18kph/11 mph.  But that just my slow hand;-)

So far, I’m pretty happy with the setup. It should definitely be able to do what I wanted it for. If somebody wants to play with similar stuff of has a question about it, real comments are always welcome;-)

As always, have fun playing with things in new ways;-)

Update: The Complete Track and Timer is here;-)

8 thoughts on “Arduino-based Photogate Timer

  1. Darby Lytle

    Hello I’m curious about the photogates you used. I was hoping to use three photogates to detect the presence/length of a can for an engineering project. I’m using a Basys2 Digilent FPGA and wanted to know how easy exactly it was to hook the photogates into the I/O pins. sorry I’m not the most knowledgeable and any help would be greatly appreciated.

  2. admin Post author

    For my Arduino setup, this was easy. Just feed 5V into the emitter & detector and I got TTL level outputs from it. So I simply could use them to feed into the digital inputs.

    But depending on your needs, you might need to supply higher input voltages. Read the spec link above, the working distance is depending on the input voltage.

  3. AJ

    Thanks so much! Lol I am also doing this for the maglev event in science Olympiad

  4. Pingback: Gates and Maglev Track - Marco's Corner

  5. Pingback: Student project ideas for freshman design seminar | Gas station without pumps

  6. sarthak

    Hello
    What is the approximate accuracy for this photogate?
    Thank You

  7. admin Post author

    That really depends on your `Arduino’ oscillator/clock. At the time, I let it run for 15 minutes and I did not see a difference compared to the base laptop time, other than my reaction time (diff +/- 0.1s). I was interested in in <<30 seconds times and more in comparing different runs than absolute run times. So it worked well for what it was.

  8. Pingback: Laser Photogate – Preparations for Science Olympiad - Marco's Corner

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.