Already done it...
The best way to do it and get some range is with an infrared led and a REGULAR phototransistor (No dark/vis coating), and it's really cheap. (Sorry I'm not a fan of $10usd sensors + 30$ shipping)
On the detector part:
Drive the phototransistor between ground and with a 4K7 resistor to 5V and "tap" in the middle to get your ADC readings
On the emmiter part:
Pulse modulate the led to 1%-10% duty and calculate your current resistor to about 100ma (can be even more current, but stop torturing the poor thing), Don't forget a transistor driver for it.
On Software:
At the beginning of your code:
-Turn off the IR led, wait 500us, get an ADC capture
-Turn on the IR led and wait about 500us
-Get a second ADC capture, then turn off the IR led
-Store the differential as a "Initial calibration"
At the main loop:
-Turn off the IR led, wait 500us, get an ADC capture
-Turn on the IR led and wait about 500us
-Get a second ADC capture and then turn off the IR led
-Store the differential as a "Captured value"
-Get the differential between "initial calibration" and "captured value"
*Congratulations you got a value proportional to the distance of the reflected IR light
It needs some other filtering and maybe a linearization (because reflected light to the sensor is not lineal), but works really well in interior ambient light conditions (not daylight, too much IR) with a range of about 30-40cm even more if you don't need an extreme resolution.
Last edited by El_AMPo; - 7th October 2010 at 21:05.
"If at first doesn't work, kicking it wont help either"
Bookmarks