It always concerned me that when we implement IR detectors using constant oscillators and loose timing, we are really flying in the face of the spec sheet, which says that you should excite these puppies with a 600 us signal that is modulated at the carrier frequency and then give it a rest for at least 600 us. It seemed to me that a PIC could generate its own code for the signal and you could bypass the extra oscillator chip while taking the IR housekeeping load off the main CPU. I developed my own IR TxRx code that would take advantage (at least a little bit) of the 600 us spec. You can see the Everlight specification at: Jameco Gif Gallery. The result was a pretty good success. It is relatively immune to transient IR signals (works in sunlight) and has just about the right sensitivity for my needs. (UPDATE: A new version that is even more immune to transients is available - see below)
The above picture is of the output (lower trace) of the left IR transmitter LED. It is modulated by the PIC chip. The upper trace is the subsequent return signal coming from an Everlight IR Detector module. As you can see, the detector takes a while to detect the transmitted signal - and then (important part coming up) IT ALSO TAKES AT LEAST 50 us TO GO BACK TO ITS 'NO DETECT' STATE AFTER THE SIGNAL STOPS BEING TRANSMITTED! Cool! That makes it easier to use a single chip to modulate the signal and to detect the return.
I used a PIC 16F84 to develop the code (all assembler - yuch) and then ported it to the much cheaper (but very permanent) 12C509 chip - which is a one time programmable (OTP) chip. I used the 12C509 because it was readily available but a 12C508 should work also. The OTP 12C509 cost me $1.36 and the whole shebang cost about $6.00 - $7.00. This makes for a cheap, kewl, and reliable configuration.
One thing I learned when making this - if you modulate right on frequency, the detector is WAY too sensitive. You must detune the modulation frequency so that you get fewer false lock ons. Also, if you make the circuit too small, the stability suffers. I've found that a Radio Shack protoboard works just fine and it is cheap. Finally, if the IRPD is going to be used close to the ground (like in a small robot), then be SURE to shield the LEDs with some tape and aluminum foil. The normal 20ma IR LED is very powerful and you will get false readings from floor and equipment reflection unless you aim the LEDs - you can also put larger current limiting resistors onto the board (330 ohm are shown, but you can use much higher - 1K or more - I have been doing this for a while and Larry Barello reminded me that this web page was a bit out of date - thanks, Larry!). The following is the basic diagram and assembler code for the 12C509:
If you have a PIC burner, then just copy the code over. Compile it, and burn your chip. Read the code comments for how it is all done.
2. Using a bit of flux on your finger, smooth it over the copper traces so that it has a very thin, invisible coating.
3. Solder in all the inactive components first (resistors, headers, capacitors, wiring)
b. Position the 8 pin IC socket across the two center traces of the board and about six rows in from the left. Note that one side of the center strip has two rows of unconnected pins and the other has three rows. It is easier if you use the three row side as the detector side. However, when I gave these instructions to my students, several assembled the board upside down - it still works, but the component layout is a bit squished. See the picture.
c. Solder the 3 pin header in starting on the 6th pin from the left in the bottom row.
d. Solder a 2 pin header in (for power) on the left side of the two strips.
e. Connect the wiring together per the picture below. Be sure to note that the +5V goes to pin 1 of the chip. That is different than many designs. The ground for the chip is pin 8. The LED wiring requires you to solder bridge the copper traces on the third from last row to the second from last row where the header connects to the LEDs. Pin 2 crosses over to the third header pin.
f. Solder the two resisters in. Look at the completed picture to see a way to make them fit in nicely.
4. Solder the Active Components in (careful - follow polarity or it won't work!)
b. The Everlight case has two crimp pins on the sides. They are too thick to go through the proto board holes, so drill the holes out a bit (or snip off the crimp pins). Solder in the Everlight IR Detector.
5. Double check the connections. Look at the block diagram (above) and make sure all the connections you've made make sense. Hook up +5V (don't hook a 9V battery directly to the detector!) and check out your work. Be sure nothing is heating up. Check that +5V is at pin 1 of the socket and ground is at pin 8. Take off the power and plug in the 12C509. Put power on, and start playing.
6. The three header pins at the bottom of the board will be true according to the following:
' 'BOBIRD.BS2 ' x var word leftM var word rightM var word halfsec var word dirs=%1111111100011111 ' pins 5, 6, and 7 are input from BOBIRD start: leftM=600 ' left motor rightM=900 ' right motor for x=1 to halfsec pulsout 1, leftM pulsout 2, rightM pause 17 if (in5) then rightAvoid if (in6) then leftAvoid if (in7) then hitwall next high 0 ' turn Stamp LED on for x=1 to halfsec pulsout 1, leftM pulsout 2, rightM pause 17 if (in5) then rightAvoid if (in6) then leftAvoid if (in7) then hitwall next low 0 ' turn Stamp LED off goto start leftAvoid: ' turn left for a few revolutions leftM=900 rightM=900 for x=1 to 10 pulsout 1, leftM pulsout 2, rightM pause 20 next goto start rightAvoid: ' turn right for a few revolutions leftM=600 rightM=600 for x=1 to 10 pulsout 1, leftM pulsout 2, rightM pause 20 next goto start hitwall: ' backup, spin about 180 degrees and take off leftM=900 rightM=600 for x=1 to 20 pulsout 1, leftM pulsout 2, rightM pause 20 next leftM=600 rightM=600 for x=1 to 40 pulsout 1, leftM pulsout 2, rightM pause 20 next goto start