The CheapBot Smart Proximity Detector is a plug-in single-board sensor for almost any programmable robotic brain. With it, robots can detect the presence of a wall extending across the robot s path or one that just obstructs one side or the other. In its simplest use, the board lets a robot avoid walls. However, it can also approximate the distance to a wall and determine if that distance is different on the left or right side of the robot. The detector is smart because of the onboard PICAXE-08M is performing the obstacle detection and data analysis. The Smart Proximity Detector makes a great follow-on sensor to the CheapBot Line Follower. Onwards and Upwards, Your near space guide Figure 1. CheapBot Smart Proximity Detector Tools Needed to Assemble a NearSys Line Follower Safety Glasses Wire Cutters Wire Strippers Soldering Iron Hot Air Gun 1
Pictorial List of Components Unique to the Smart Proximity Detector Figure 2. Printed Circuit Board Figure 2. PICAXE-08M (The microcontroller will have a red dot on it if is already programmed) Figure 3. 38 khz IR Detector Theory of Operation Figure 4. Schematic of the CheapBot Smart Proximity Detector. 2
The Smart Proximity Detector s PICAXE-08M takes turns flashing the left and right infrared light-emitting diodes (IREDs) D1 and D2. The IREDs emit infrared beams at a wavelength of 950 nanometers (just within the infrared portion of the spectrum) and their brightness is controlled by the resistors R1 and R2. The PICAXE-08M has a single pulse width modulated output (I/O pin 5) and therefore this pin is connect to the anodes of both IREDs. So that only a single IRED pulses at a time, the cathodes of both IREDs are connect to a separate PICAXE I/O pins. Only when the cathode of a particular IRED is grounded (with the LOW command), does that IRED blink at 38 khz, even though both IREDs are connected to the PWM I/O pin of the PICAXE-08M. After each 38 khz pulse, the PICAXE-08M checks the output from the IR detector. The 38 khz detector produces a five volt output when it does not detect infrared radiation pulsing at 38,000 times per second (38 khz). When it does detect such an infrared signal, it produces a zero volt output. I/O pin 4 of the PICAXE monitors the voltage on this pin every time it pulses one of the IREDs. Since the PICAXE is controlling which IRED is pulsing at the time, it knows which side of the PCB the IR pulse came from. Actually, the detector is most sensitive to 38 khz IR. It can detect other frequencies with diminished sensitivity if they are close to 38 khz and bright enough. This means a reflection from an IRED pulsed as 32 khz cannot be detected from as far away as a 38 khz pulse. The PICAXE-08M uses this fact to determine a pseudo-range to an obstacle. So by pulsing the IREDs at a variety of frequencies and determining which produces an output from the IR detector, the PICAXE-08M determines the relative distance to an obstacle and if it is across the robot or just on one side. Resistor R5 is a pull up pin for the IR detector s output (pull up resistors ensure outputs are held to +5 volts in the absence of a signal). Capacitor C1 filters removes stray AC on the detector s power line and it improves the detector s ability to detect 38 khz signals. Resistor R4 limits the current of the IR detector s power. The I/O port, soldered to the end of the three wire cable, provides power and ground for the proximity detector. The proximity detector transits distance information over the third wire as a continuous message at 1200 baud. The message has the following format. 255, L, LeftDistance, R, RightDistance The LeftDistance and RightDistance are variables with values ranging from 1 to 7. A value of 7 indicates no reflected IR was detected at any frequency. From the way the Smart Proximity Detector is constructed, this means an obstacle is at least a foot away. A LeftDistance or RightDistance value of 1 occurs if reflected IR is detected at every frequency. And for this to occur, the distance to the obstacle is on the order of two inches. The distance for every value depends on the IREDs, their current limiting resistors, and the ability of the IR detector. NearSys developed the following table to give you an idea of the meaning of values, but your mileage will vary. 3
Value Distance 1 2 2 3 3 5 4 6 5 9 6 10 7 14 Table 1. The approximate range (in inches) for variable values. Assembly Directions The following components are polarized and must be inserted with the proper orientation. D1 and D2 Align the long lead with the A in the top silk U1 Place the notch of the IC socket at the top as illustrated in the top silk C1 Align the + mark printed on the capacitor s body with the + mark in the top silk Mount the resistors and wires flush with the PCB surface. Use the red wire for the cable s 5V connection, black (or green) wire to indicate the GND connection, and the remaining color for the message line. All parts, except for the capacitor C1, mount flush to the surface of the PCB. The capacitor will probably want to stand a little above the PCB, so don t force it. Figure 5. Placement of components on the Smart Proximity Detector PCB Suggested Order of Assembly R1 1k ohm resistor (brown, black, red, gold) R2-1k ohm resistor (brown, black, red, gold) R3 22k ohm resistor (red, red, orange, gold) R4 330 ohm resistor (orange, orange, red, gold) R5 4.7k ohm resistor (yellow, violet, red, gold) R6 10k ohm resistor (brown, black, orange, gold) R7 1k ohm resistor (brown, black, red, gold) U1 8-pin IC socket (align the notch to the top) Detector the leads can be bent closer to the body of the detector J1 Three pin male header D1 IRED (anode lead in pad closest to A) 4
D2 IRED (anode lead in pad closest to A) C1 4.7 uf tantalum capacitor Figure 6. Identity of IRED leads Cabling Steps Strip ¼ of insulation from one end of all three wires From the bottom of the PCB, insert the bare ends of wires through the large pads (strain relief pads) marked Left, GND, +5V, and OUT. Bend the wires over and insert them into the neighboring smaller pads as illustrated below. Figure 7. A strain relieved wire ready for soldering Solder the wire ends and clip any excess length Strip ¼ inch of insulation from the other ends of the four wires Slide a ½ inch long length of heat shrink tubing over each wire and push the heat shrink down to the PCB so it won t get hot during soldering Tin each wire Insert the 1 by 3 header into a socket (this keeps the pins in the proper orientation while wires are soldered to them. Tin all three of the short pins of the header. 5
Figure 8. Header plugged into a socket in preparation for soldering. Figure 9. The function of the pins in a 1 by 3 header Solder the green (or black) wire to the GND header pin Figure 10. Close up of a wire soldered to a header pin (only solder to the short side of the pins) Solder the red wire to the +5V header pin Solder the remaining wire to an I/O header pin Slide the heat shrink tubing over the soldered pins and shrink Figure 11. Heat shrink covering the soldered wires on a header Clean up the edges of the cut plastic tubes Apply a drop of hot glue to the side of an IRED Slide a plastic tube over the IRED before the glue cools Repeat for the other IRED Cut a piece of heat shrink and slide it over the plastic tubes Carefully heat the tubing so you don t melt the plastic tube Cut aluminum tape strips and cover the edges of the 38 khz detector as illustrated below 6
Figure 12. The 38 khz IR detector appears to work better if its edges are taped to the PCB with aluminum duct tape. Test Procedure Before inserting the CheapBot Smart Proximity Detector into a robot controller I/O port, make the following measurements to verify the PCB is assembled properly. Inspect the bottom of the PCB and verify there are no soldered connections overflowing their pads to neighboring pads Measure continuity between the +5V and GND pins in the header and make sure there is no continuity between the positive and negative terminals in the header Plug in the pre-programmed PICAXE-08M (the red dot indicates it has been programmed) Plug the header into an input of a CheapBot robot controller Plug a programming cable into the robot controller and start the PICAXE program Editor Power up just the logic circuit of the robot Prop the robot up so the proximity detector points off into space Set the Editor to the PICAXE used in the robot controller and the proper Com Port Type and download the following program symbol LeftDetect = B0 symbol RightDetect = B1 Test: SERIN 2,T1200_4,("L"),LeftDetect,RightDetect,RightDetect DEBUG GOTO Test Note: This code is assuming the Smart Proximity Detector is connected to I/O pin 2. Change this number in the SERIN command if it is not the case. The Debug terminal will pop up so you can observe the value of bytes B0 (LeftDetect) and B1 (RightDetect). * LeftDetect and RightDetect will both have a value of 7 when an obstacle is too far away to be detected. * The variables will have smaller values the closer an obstacle appears. Using the CheapBot Smart Proximity Detector The next step is to mount your CheapBot Smart Proximity Detector to the nose of the robot body with the #2-56 hardware and the short nylon spacers. 7
Figure 13. Side view of the proximity detector mounted to the nose of a robot. The cables from the proximity detector PCB plug into a single channel of an input port. Be sure the green wire plugs into a ground pin of the I/O port and the red wire plugs into a +5V pin of the I/O port. Using the proximity detector requires that the robot be moving. So set of the H-Bridge control pins high and low to drive the robot forward. Then, while the robot drives, monitor the text messages from the Smart Proximity Detector with this code. SYMBOL LeftDetect = B0 SYMBOL RightDetect = B1 SERIN 2,T1200_4, ("L"),LeftDetect,RightDetect,RightDetect The next lines of code should determine if any of the values are less than 7 (an obstacle is present) and which side has the smallest value. Based on that information, the robot then takes evasive action. Fine Tuning the Smart Proximity Detector No two IREDs are alike, just as no two 1k resistors are alike. Therefore, there is naturally a difference in the proximity detector s left and right distance reports. A simple demonstration of this difference is to aim your robot straight for a wall and programming the robot to turn away from the closest distance and to stop if the left and right distances are equal. Invariably, the robot will swerve either left or right. The proximity code below can be modified by subtracting an offset value from the side with the greatest distance value. Or the robot can be programmed to subtract the distance from the proximity detector s messages. The IREDs are bright in order to give the detector maximum sensitivity. If this is a problem for your robot s maze, then either have the robot ignore the more distant values or cover the IREDs hood openings with a small piece of masking tape. Smart Proximity Detector Code The code below is the current version stored in the proximity detector s PICAXE-08M. Feel free to modify the code to your purposes and download it into your proximity detector. The programming header for the Smart Proximity Detector is to the left of the PICAXE-08M 8
symbol RightDetect = B0 symbol LeftDetect = B1 symbol distance = B2 symbol counter = B3 symbol RightDistance = B4 symbol LeftDistance = B5 symbol left = 1 symbol right = 4 Proximity_Detect: RightDistance = 7 LeftDistance = 7 for counter = 1 to 6 CheckRight: if RightDistance < 7 then CheckLeft low right high left gosub Flash RightDetect = pin3 '0 = detect, 1 = no detect pwmout 2 off pause 2 if RightDetect = 1 then CheckLeft RightDistance = counter CheckLeft: if LeftDistance < 7 then FinishCheck low left high right gosub Flash LeftDetect = pin3 '0 = detect, 1 = no detect pwmout 2 off pause 2 if LeftDetect = 1 then FinishCheck LeftDistance = counter FinishCheck: if LeftDistance < 7 then IsRight7 goto Repeat_Flash IsRight7: if RightDistance < 7 then Report Repeat_Flash: next Report: serout 0,T1200_4,(255,"L",LeftDistance,"R",RightDistance) goto Proximity_Detect Flash: if counter > 1 then Check33 gosub khz32 Check33: 9
if counter > 2 then Check34 gosub khz33 Check34: if counter > 3 then Check35 gosub khz34 Check35: if counter > 4 then Check36 gosub khz35 Check36: if counter > 5 then Check37 gosub khz36 Check37: if counter > 6 then Check38 gosub khz37 Check38: gosub khz38 End_Flash: khz38: pwmout 2,25,53 khz37: pwmout 2,26,54 khz36: pwmout 2,27,56 khz35: pwmout 2,28,57 khz34: pwmout 2,28,59 khz33: pwmout 2,29,61 khz32: pwmout 2,30,63 ' 14 inches ' 10 inches ' 9 inches ' 6 inches ' 5 inches ' 3 inches ' 2 inches 10
30 October 2009 11