Dan Creagan: email@example.com
'BOBIRD' is detecting an obstacle on the right (the middle LED is lit).
Click on the image to get a bigger picture.
The following is a general description of how to build the Brains On Board IR Detector. BOBIRD uses a Microchip PIC that must be programmed using a PIC programmer. These are readily available, but if you don't want to get into PIC programming but still want to try the kit out then I will program your chip for you (free) if you send it to me. Email me for details.
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. Dennis Clark's page convinced me that it was possible. So, 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.
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. The following is the basic diagram and assembler code for the 12C509:
Download IRPD2.ASM (assembler code with comments) by clicking here.
At burn time, select Internal RC Osc, Internal Master Clear, No WDT, No Power Up Timer The visible LEDs are optional and not needed for a normal robotics application - they're just pretty 8) You should take the outputs from pins 2, 4 and 5 to your microcontroller for obstacle avoidance. Pin 2 is meant to be left detect, pin 4 is right detect, and pin 5 is both detect.
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.
The kit to put all this together runs about $6.00 - $7.00 if you buy mail order. I do not sell kits or anything else to the general public - just go down to Radio Shack or open a Jameco/Digikey catalog and create this kit.
1. Radio Shack protoboard (PN 276-150A)
2. Everlight IR Detector Module (PN 2760137)
3. 2 IR LEDs (PN 2760143)
4. Three standard T 1 3/4 LEDs with resistance (from www.digikey.com PN MR3350QT-ND)
5. Microchip 12C509 OTP pre-programmed. You can get blank 12C509s from www.phanderson.com. You can then program them using the code above or I will program your chip and check it out for free if you send me the 12C509 OTP and return postage. Email me at firstname.lastname@example.org for details.
6. 8 pin IC socket (A9308-D from www.digikey.com)
7. Snappable Header pins (PN S1032-36-ND from www.digikey.com)
8. Two 330 ohm resistors.
9. One 22 ufd electrolytic capacitor (nominal - not needed if power leads are short)
10. Hookup wire
You will need to provide +5V, soldering iron, solder and flux.
1. Clean off the copper side of the protoboard with a rough, clean cloth (just buff it)
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)
a. The center traces on the protoboard will be the power and ground busses. Make +5V the upper trace and ground the bottom trace. See the picture.
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!)
a. Solder in the LEDs - don't overheat the connections or the traces will lift.
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:
a. Obstacle on left of board: Left pin is high.
b. Obstacle on right of board: Middle pin is high.
c. Obstacle directly in front: Right pin is high.
7. You did shield the IR LEDs didn't you? I used some foil backed plastic from a potato chip bag. I covered both sides with black tape and made a little tube which I slid over the IR LEDs. Works great.
This code assumes you are controlling the servos with pins 1 and 2; you are receiving input from the BOBIRD on pins 5, 6 and 7; and you have an LED on the Stamp tied from pin 0 to ground (an LED with resistance). The code assumes servos have not had their motor pins reversed, so one has to run opposite the other. This is simple code that has not been tweaked (you should do that!). It can be made much smoother by adjusting the turn and backup values. You should aim for an effect that looks like the robot is doing graceful avoidance - not sudden and jerky moves. To make it a little nicer, the LED on pin 0 is blinked - it lets you know everything is trying to work.
' '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