Infrared Sensor Notes
After a year of trying different IR sensors, the nice subscribers at the Homebrew
Robotics Club mailing list
helped me achieve my goal of a reliable, cheap IR sensor.
At first, I tried using the Sharp GP1U52X type IR detector. I used a regular 555 timer to generate a 40KHz
pulse to the IR LED, and connected the output if the detector directly to the Basic Stamp. But the detector
didn't put out a TTL signal, or logic low or high. Instead, it sent out pulses of about 40KHz. I tried to measure
this pulse AND drive the servos with the Stamp. But to measure the pulses using "pulsin", it took at least 100 ms
of processor time, and this was interfering with the servo movement. So I gave up and tried a different IR approach.
I found a schematic for an IR sensor using a IR phototransistor and LED, a 741 op amp to compare signal levels,
and two NPN transistors to convert the output signal to TTL. This worked reliably in low light situations, but the
sensor would always false trigger in normal light. So I turn to the HBRC for help.
It turns out the Sharp GP1U52X detector is the best way to go for any lighting conditions. But there are a few
tricks:
the 40KHz frequency needs to be carried by a 100 to 1000Hz frequency to keep the detector from saturating, and
the output of the detector needs to be connected to a tone decoder set to the same carrier frequency. On the Radio
Shack website, the datasheet for their IR detector module shows how this is done. The tone decoder will take the
signal from the IR detector and convert it to a TTL signal. Actually, it is logic low. When wired exactly like the
schematic shows, this gives a range of detection between 6 and 12 inches. I couldn't find a 567 tone decoder at
Fry's Electronics, so I bought a NTE832 tone decoder instead. This seems to work just as well, and my robot
can finally see in front of it. But remember, the carrier frequency of the 556 timer needs to be the same as the
tone decoders frequency. I recommend wiring the IR sensor exactly as the datasheet shows, and hooking pin 8
of the tone decoder directly to the Basic Stamp. Between pulses to the servos, I inserted this line of code:
IF IN0 = 0 THEN TURN_RIGHT
This will check the status of pin 0 to see if it is at zero volts, or logic low. If it is low, then it goes into
the turn right
loop. If it is high, it continues on. Checking the status of pin 0 is much faster than counting a number of pulses
coming into the pin. If you have any questions, e-mail me.
Again, I'd like to thank the Homebrew Robotics Club of Silicon Valley for their help.
|