Let's Make Robots!

Optointerrupters and Arduino

Ok, I have a pair of optointerrupter modules (just an IR LED and a photodiode paired together basically) and I would like to find out how to use them as distance sensor with an Arduino. Could anyone set me up with some really basic code that I could play around with just to get me on the right track?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Come on Dent, you should know to provide more info than just I have generick named part, how can I use this. What is the part number, where did you get it, was there a datasheet for it and where can it be found....

Is it something like this?  if so, they have a very short range and may not bee good for long range sensing. Ideally I think they'd be useful for edge detection to prevent you from going over a clif.



I don't have a datasheet (I got it at the local surplus, HSC) and it seems fairly simple. Actually, it is more like the type they use in mouse encoders (an IR LED firing at a IR sensor). So I would break it apart, face the receiver and LED in the same direction, and then how would I get the software to send a 38 kHz signal and count the number of microseconds until reception? Or does anyone have a better idea for a distance sensing software implementation? (no, not being sarcastic, I"m really just curious!)

not sure why you'd use the 38khz  signal to it if you don't know how the receiving end is reading.

If it's fairly simple as you say, then I'd imgine using an adc channel on the photodetector to see what the intensity of the emmiter is.

Should be pretty simple, keep the emmiter on an io pin (with a resistor), maybe attach it to a transistor to get more current though.

read the adc channel for the photodetector and see what you get.

I would use a signal frequency to let the arduino distiguish the LED's light from ambient light. I'm actually not sure exactly how my method would work, seeing as light is faster than electricity though...

Optical sensors work on light frequency and intensity, unlike sonar sensors which can be timed for ditance calcs. Sound in air travels at ~330m/s, whereas light travels more like ~300,000,000m/s - much too fast for a micro to time unless the distance is huuuuuge.

Take a look at some of the IR photodetector circuits around LMR, OddBot and others have tested quite a range of different circuits which each have their own advantages and disadvantages.

That's what I was afraid of...
It's really not as bad as you might think....  :)