Ir photo interrupter

I am looking to make a device that uses two of these IR photo interrupter's to measure how fast something is going.

Basically what happens is they would be spaced about 2 inches apart. The first one would get broken and then start a time to count how long it takes to reach the second one. This would be multiplied by 6 to get the feet per second that the object was traveling.

I'm starting it off simple though. Does anyone have code that could be used with one of these to say, turn on a LED (probably the built in one)?

I did manage to find this, which I am currently messing around with:

Thanks!

One way of implementing your speed counter is to connect the two phototransistor outputs from the interrupters to two arduino pins configured as inputs. Loop till the first interrupter changes state (or attach an external interrupt ) and store the millisecond count (this will be the start time). Then wait for the second interrupter to change state and this will be the end time. feet per second is the difference between the two, times 6, divided by 1000.

I'd use a external interrupt for the first one and then a tight loop in it waiting for the second.
Not too difficult.

true, not difficult; but there are some potential bugs lurking. Like not using longs in the time calculation (which if implemented with 16 bit math would overflow if the speed was faster than 10 feet per second).

true, not difficult; but there are some potential bugs lurking. Like not using longs in the time calculation (which if implemented with 16 bit math would overflow if the speed was faster than 10 feet per second).

Thanks for the recommendations. The speed is defiantly going to be faster then 10 f/s.

true, not difficult; but there are some potential bugs lurking. Like not using longs in the time calculation (which if implemented with 16 bit math would overflow if the speed was faster than 10 feet per second).

Why would it overflow by going too fast? :-?

Also a long is 32bits.

true, not difficult; but there are some potential bugs lurking. Like not using longs in the time calculation (which if implemented with 16 bit math would overflow if the speed was faster than 10 feet per second).

Why would it overflow by going too fast? :-?

Also a long is 32bits.

integer math such as the following will overflow after about 10 seconds:
unsigned result = ((end - start) * 6 )/ 1000;

math using longs such as the following will not overflow for any realistic speed.
unsigned long lresult = ((end - start) * 6L )/ 1000;

p.s. my previous post said 10 feet per second, I meant 10 seconds. which is 60 feet per second (or 30 feet per second if the ints are not declared as unsigned ).

I am hoping to measure an object that would be moving as fast as 500f/s (from what I can tell). Is the Arduino even capable of doing this?

Yes, the arduino is more than capable of doing that. But you would need to use a timer that responds faster than a millisecond. This thread http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1201890734 discusses the use of timer1 that you may want to adapt for application.