The CheapBot Line Follower is a plug-in single-board sensor for almost any programmable robot brain. With it, a robot can detect the presence of a black or white zone beneath its two sensors. In its simplest use, the board lets a robot navigate a black line on a white surface. However, it can also let a robot detect the boundary of a robotic playing field. The line follower is a great first sensor for a CheapBot robot. Onwards and Upwards, Your near space guide Figure 1. CheapBot Line Follower Tools Needed to Assemble a NearSys Line Follower While there are literally one hundred tools for soldering, testing, and fixing electronic circuits, you only need these few tools to make the line follower. Safety Glasses Wire Cutters Wire Strippers Soldering Iron Hot Air Gun Pictorial List of Line Follower Components Figure 2. Printed Circuit Board 1
Figure 3. Resistors (four of them) Figure 4. IR LEDs (two of them) Figure 5. Phototransistor (two of them) Figure 6. Heat Shrink Tubing (two inches long) Figure 7. Double Header (2 by 3 pins) Figure 8. Foam Spacer (one inch square block) Figure 9. Aluminum Foil Duct Tape (two inch square) 2
Figure 10. Wire (four pieces, two feet total) Figure 11. Plastic Tube (two pieces, ½ inch long) Theory of Operation Figure 12. Schematic of the CheapBot Line Follower. The infrared LEDs (IREDs) in the line follower emit two infrared beams at a wavelength of 950 nanometers (just within the infrared portion of the spectrum). If there is a white surface beneath the IR beams, the beams reflect back up to one of the phototransistors. The phototransistors, with a peak sensitivity of 850 nanometers (nm) have enough bandwidth to detect the 950 nm IRED radiation. Dark surfaces on the other hand, like 3
black electricians tape, do not reflect the IR beams back up to the phototransistors. With phototransistor/ired pairs on the left and the right side of the line follower, black and white regions can be detected on the left, right, or on both sides of the robot. Two 330 ohm resistors control the brightness of the IREDs. Since each 330 ohm resistor and IRED series circuit is supplied with +5 volts and each IRED has a forward voltage of 1.5 volts, only 3.5 volts is dropped across each resistor. According to Ohm s Law, the current flowing through the resistors and therefore the IREDs is 3.5 volts/330 ohms or 0.011 amps (11 milliamps). The sensitivity of the phototransistors is sufficient to detect the reflected beam of an IRED from several inches. Notice each phototransistor has a 47k ohm resistor connecting its collector to five volts. The resistor limits the maximum current flowing through the phototransistor when it conducts and it also acts like a voltage divider in conjunction with the conducting phototransistor. When no reflected IR shines on the phototransistor, current from the line follower s +5V cannot flow though the phototransistor to ground. Instead, the current flows into the phototransistor s output wire producing a +5V signal for the robot controller. Therefore, the presence of +5V indicates that phototransistor is sensing a black surface. When reflected IR shines on the phototransistor, most of the current from line follower s +5V flows through the phototransistor to ground producing less than 1.4V on the phototransistor s output wire. The presence of low voltage indicates that the phototransistor is detecting a white surface. Assembly Directions The following components are polarized and must be inserted in the proper orientation. Q1 and Q2 Align the flat side of the plastic case with the A on the top silk D1 and D2 Align the long lead with the A in the top silk Note: D1 and D2 can also be aligned with flat of LED lens on pad opposite the A in the top silk Mount the resistors and wires flush with the PCB surface. The phototransistors and IREDs stand approximately ¼ inches about the PCB so they can be bent into proper alignment. Figure 13. Placement of Components on the line follower PCB 4
Suggested Oder of Assembly R1-330 ohm resistor (orange,orange,brown,gold) R2-47k ohm resistor (yellow,violet,orange,gold) R3-330 ohm resistor (orange,orange,brown,gold) R4-47k ohm resistor (yellow,violet,orange,gold) D1 IRED (anode lead in pad closest to A) D2 IRED (anode lead in pad closest to A) Q1 Phototransistor (collector lead in pad closest to A) Q2 Phototransistor (collector lead in pad closest to A) Figure 14. Identity of IRED leads Figure 15. Identity of phototransistor leads Cabling Steps Strip ¼ of insulation from one end of all four 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 Right (use the red wire for +5V and the green wire for GND). Bend the wires over and insert them into the neighboring smaller pads as illustrated below. Figure 16. A strain relieved wire ready for soldering 5
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 2 by 3 header into a socket (this keeps the pins in the proper orientation while wires are soldered to them if the plastic body softens due to the heat of soldering). Tin both of the headers I/O pin and one ground and one +5V pin. Figure 17. Header plugged into a socket in preparation for soldering Solder the green wire to any one of the GND header pins Figure 18. The function of the pins in a 2 by 3 header Figure 19. Close up of a wire soldered to a header pin (only solder to the short side of the pins) 6
Solder the red wire to any one of the +5V header pins Solder the blue wire to an I/O header pin Solder the yellow wire to the other I/O header pin Slide the heat shrink tubing over the soldered pins and shrink Figure 20. 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 and both phototransistors Cut a strip of aluminum duct tape and wrap it around all the plastic tubes Gently bend the phototransistor and IRED leads so each pair points to an imaginary point between them and roughly one inch away Figure 21. An example of the proper alignment of the IRED and phototransistor pairs Test Procedure Before inserting the CheapBot Line Follower 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 the header into Inputs 0 and 1 of a CheapBot robot controller and plug a programming cable into the controller and start the PICAXE program Editor Start the robot Prop the robot up so the line follower 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 Test: B0 = 0 BIT0 = PIN0 BIT1 = PIN1 DEBUG GOTO Test 7
The Debug terminal will pop up so you can observe the value of byte B0. * B0 will have a value of 3 when nothing reflective is in front of the line follower * B0 will have a value of 0 when a white index card passes in front of both phototransistor/ired pairs * B0 will have a value of either 1 or 2 when a white index card passes in front of either one of the phototransistor/ired pairs. If you do not observe B0 changing between values 0 and 3, then bend the leads of the phototransistor/ired pairs until they line up properly. Otherwise, verify they are soldered to the PCB in the proper orientation. Add a stripe of electrician s tape to the index card and pass the line in front of the phototransistor/ired pairs and observe that B0 changes values to correspond to the position of the black stripe. After aligning the phototransistor/ired pairs, hot glue pieces of the foam spacer between the pairs to protect them from being bent out of proper alignment Figure 22. Foam blocks glued against each IRED/Phototransistor pair Using the CheapBot Line Follower The next step is to mount your CheapBot Line Follower to the robot body and plug in its cable. Figure 23. Side view of the line follower mounted beneath the nose of a robot. 8
The cables from the line follower PCB plug into two channels of an input port. Be sure the blue and yellow wires plug into I/O pins of the input port and that 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 line follower requires that the robot be moving. So set of the H-Bridge control pins high and the other low to drive the robot forward. Then while the robot drives, monitor the voltage from the left and right phototransistors. While they are both high, the phototransistors are detecting a white surface. When one or both voltages go low, the IRED/phototransistors are passing over a black surface. Therefore, stop the robot and determine the direction the robot must steer in order to realign on the black line. Then drive the robot forward again while monitoring the line follower outputs. Here s some sample code for the PICAXE. SYMBOL Detectors = B0 SYMBOL RightDetect = BIT0 SYMBOL LeftDetect = BIT1 Line_Follower: GOSUB Forwards Check_Line_Follower: GOSUB Line_Finder_Check IF Detectors = 1 THEN Line_Right IF Detectors = 2 THEN Line_Left IF Detectors = 3 THEN Line_in_Front GOTO Check_Line_Follower Line_in_Front: GOSUB Freeze GOSUB Right PAUSE 600 GOSUB Freeze GOSUB Forward GOTO Line_Follower Line_Right: GOSUB Left PAUSE 120 GOTO Line_Follower Line_Left: GOSUB Right PAUSE 120 GOTO Line_Follower Line_Finder_Check: Detectors = 0 RightDetect = PIN0 LeftDetect = PIN1 Right: 9
HIGH 2 LOW 3 LOW 4 HIGH 5 Left: LOW 2 HIGH 3 HIGH 4 LOW 5 Backwards: HIGH 2 LOW 3 HIGH 4 LOW 5 Forwards: LOW 2 HIGH 3 LOW 4 HIGH 5 Freeze: LOW 2 LOW 3 LOW 4 LOW 5 PAUSE 500 7 May 2009 10