Chapter 4. Linus the Line-Bot

Let's begin with a small robot for our first project that introduces the basic concepts of automated control. This robot decides where to go based on its surroundings and can change its path if the environment is changed. Linus' purpose is to follow a black line on a white surface (see Figure 4-1). His aspirations are quite low, but he is still fun to experiment with and easy (and cheap) to build.

The mostly finished Linus sitting on his track

Figure 4.1. The mostly finished Linus sitting on his track

The cost of this project as shown is around $80. This includes a commercial motor-driver board, two hobby servo motors, a homemade IR sensor board, and several other items that might be used for multiple robots (Figure 4-2).

You also have the option to substitute your old usable parts like previously used servo motors (or gear-motors), or maybe you already have a motor-controller, at which point the price for this bot will drop quite a bit. If you want to save some money, you can also skip ahead to Chapter 6 to find out how to make your own PCBs on your PC with free software. You can also build these circuits on prototyping board from Radio Shack.

We start by making an infrared sensor board so that Linus can detect the color of the surface beneath him, and then go through the process of modifying a hobby servo motor for continuous rotation. Next we fit the rear wheels onto the motor output shafts and make a bracket for the front caster wheel. We then modify a tin container for use as our frame, and install the motors, infrared sensor board, Arduino with motor-controller shield, and batteries. After everything is wired up, we load the code onto the Arduino, make a track for Linus to follow, and start testing to see how fast we can get him to go around the track without losing his path. With Linus complete, you can then add LED interior lighting, a speed adjustment potentiometer, or paint his frame to add some style. Let's look at the parts required to build Linus.

Parts List for Linus

For every project in this book, you are expected to have an Arduino ($35), so we won't include that in each project price. In Chapter 6, we build a "poor-man's Arduino" that is intended to replace your main Arduino when a project is completed so you don't have to keep buying new Arduinos-unless you are rich. The price per board to build yourself is around $8-$15 each, but they can be programmed only with an FTDI cable ($15 from Sparkfun.com), because there is no USB interface built onto the homemade boards.

I also do not include tools or other standard materials (like wire) into each project price, because these will last for several projects. A roll of solid 22AWG wire should get you through most of the book, as should a roll of rosin-core solder. It is also handy to have a few pieces of scrap metal or aluminum on hand. A 36-inch long piece of flat aluminum stock enables you to make several brackets, supports, or motor mounts, so I keep a few different sized pieces in my parts bin.

This project uses some basic robotic components: sensors, motors, wheels, a frame, batteries, a motor-controller, and your Arduino micro-controller (Figure 4-2). If you already have a robot base with several of these components, you might complete this project for as little as $15 to build the infrared sensor board.

Here you can see the unassembled parts used to build Linus.

Figure 4.2. Here you can see the unassembled parts used to build Linus.

You can also substitute parts to save money as you please: a set of gear-motors you might have for the servo motors I used, a homemade H-bridge for the AF motor-controller, or pre-built IR sensors from Sparkfun.com (item: ROB-09453) instead of building your own. With a little tweaking, any of these alternatives should work. You can also save money by ordering some parts from Digikey.com, because you will get far more in quantity for nearly the same price as buying from Radio Shack. See Table 4-1 for a complete list of parts. This chapter presents one way to build a line-following robot.

Table 4.1. The Parts List

Part

Description

Price

AF motor-shield

AdaFruit.com (part# 81)–This Arduino shield is capable of driving up to four DC motors.

$19.95

(2) hobby servo motors

HobbyPartz.com (part# EXI-Servo-B1222) –Standard sized EXI hobby servo motors

$6.45 ea.

(5) IR emitter/detectors

Digikey (part# TCRT5000L)–These are standard infrared emitter/detecter pairs.

$1.06 ea.

Perforated prototyping board

Radio Shack (part# 276-158)–Or similar, any piece of 0.1-inch perforated copper clad prototyping board will work.

$2.99

(5) 10k ohm resistors

Digikey (part# P10KBACT)–50 pack of resistors

$1.78

(7) 150 ohm resistors

Digikey (part# P150BACT) –50 pack of resistors

$1.78

Frame

Thrift store–I used a tin keepsake box from a children's card game; cookie tins work, too.

$0.39

(25) nuts and bolts

Hardware store–#6 bolts with nuts, 1/2 inch to 2 inch in length

$3.00

(2) drive wheels

Thrift store–Salvaged from toy motorcycle

$1.99

Caster wheel

Hardware store–Used for rolling cabinets, and so on.

$1.99

Battery

Clearance rack–6v, 1000AH or equivalent. Can be NiMh, NiCd, or non-rechargeable.

$1.00

Power switch

Radio Shack (part# 275-612)–Standard SPST switch to toggle power

$2.99

(2) LEDs

Digikey (part # C503B-BAN-CY0C046) –I used two Blue LEDs connected to the motor output terminals. Use any color you like.

$1.08

5k Potentiometer

Radio Shack (part # 271-1715) –This is used to adjust the speed of Linus without reprogramming.

$2.99

Spray paint

Hardware store–Used to add some color, not required.

$5.00

Grand total

As tested

$67.12

This, of course, includes the AdaFruit motor-shield, the batteries that can be removed to use in other projects, and the spray paint that will last for several bots. These parts should be used for easy prototyping, whereas handmade circuits should replace the Arduino and AF motor-shield after the Line-bot is fixed for permanent use (after testing is complete). After you finish the projects in this book, you will easily be able to build an Arduino and motor-controller replacement at home and for far less than buying a new Arduino and AF motor-shield.

How Linus Works

The infrared emitter sends a continuous beam of infrared light that is reflected from the ground back to the infrared detector. Depending on the reflectiveness of the ground color, the detector receives varying amounts of reflected infrared light. The detector is actually an infrared photo-transistor that uses infrared light to activate the transistor base. The more infrared light that gets to the detector, the more the transistor conducts. We use five IR sensors in a straight line to determine the exact position of the non-reflective line beneath the robot. By adjusting the two drive motors based on the line sensor readings, we can keep the bot centered on the line as it drives around the track.

The Track

The track must be a solid color with no variations. A few pieces of white poster-board work best with black electrician's tape for the line (see Figure 4-3). The line provides a contrast of color that the sensors can differentiate. You can make whatever line shape you want for your bot to follow: it can be twisty, have intersections and loops, or be a simple circle. The neat thing about Linus is that he responds differently each time around the track. Because he responds to his sensors, if there is a split in the track, he might go left the first time around and right the next! It is interesting to watch the decision-making processes of this little machine.

This is the first track I designed to test Linus, which worked very well.

Figure 4.3. This is the first track I designed to test Linus, which worked very well.

Now that you know how Linus maneuvers around the track, let's get started building the infrared sensor board.

Building the IR Sensor Board

The IR sensor board consists of five infrared emitter and detector pairs. You can make your own IR emitter/detector pairs using individual IR LEDs and IR phototransistors from Radio Shack (part # 276-142), but they are over $3 per pair, which is about $15 for the all five sensors! Digikey.com has several different IR emitter/detector pairs for about $1 each-that cuts the cost down to $5 for the infrared sensors (see Figure 4-4).

The parts needed to build the IR sensor board: (5) IR sensors from Digikey.com, (5) 150 ohm resistors, (5) 10k ohm resistors, some wire, and a piece of prototyping board from Radio Shack

Figure 4.4. The parts needed to build the IR sensor board: (5) IR sensors from Digikey.com, (5) 150 ohm resistors, (5) 10k ohm resistors, some wire, and a piece of prototyping board from Radio Shack

The infrared emitter LED (the blue or clear one) sits next to an infrared phototransistor detector (that looks like a black LED) with a small divider between them. The small divider makes sure no IR light is read by the detector that is not first reflected from the surface (in our case, the floor or track). The sensors should not be placed directly beside each other (without a gap) in order to avoid interference from the next sensor. They should also not be placed so far apart that there are "dead spots" in between that are not read by any sensor. See Figure 4-5 for a view of the completed infrared sensor board.

The IR sensor board with all five sensors installed

Figure 4.5. The IR sensor board with all five sensors installed

I chose to place my sensors about 0.5 inch apart, which works well. If you place the black line between sensor 2 and sensor 3, you will see both outputs affected (the output value of those sensors will be lower than the rest). If you, however, place the black line directly under sensor 3, only sensor 3 will show an altered value-sensors 2 and 4 are just far enough away from sensor 3 to not detect any of the black line. If the sensors were closer together, both sensor 2 and sensor 4 would pick up on the black line, even if it was centered directly beneath sensor 3. Determining the spacing of each sensor is a matter of testing-if you don't feel like testing it, start by spacing the sensors 0.5 inch apart.

To make things easier, I chose to use a piece of Radio Shack perforated copper clad prototyping board that is wide enough to enable proper spacing between each IR sensor. This board is approximately 2 ¾ inch by 3 inch and most of it is unused except the top and bottom few rows. To get started building this circuit, you first need to see the schematic diagram (see Figure 4-6) that shows how each sensor should be connected in the circuit as well as a pinout of the actual IR sensor, shown in Figure 4-7.

This is the schematic of the IR sensor board.

Figure 4.6. This is the schematic of the IR sensor board.

IR sensor schematic (detector or photo-transistor = Left, Emitter = Right)

Figure 4.7. IR sensor schematic (detector or photo-transistor = Left, Emitter = Right)

The following nine steps will walk you through building the IR sensor board:

  1. Place IR sensors on prototyping board. Each IR pair has two LEDs with four total leads. The top of the pair is the Emitter (the blue-colored LED), and the bottom is the Detector or photo-transistor (the black-colored LED). The indented end of the sensor package should be closest to the edge of the board. as shown in Figure 4-8.

    Placing the sensors

    Figure 4.8. Placing the sensors

    The Anode of each Emitter diode (marked "A" in Figure 4-7) and the collector of each photo-transistor (marked "C" in Figure 4-7 on left) should both be tied directly to +5v. The cathode of each IR Emitter (marked "C" in Figure 4-7 on right) should be connected to Ground through a 150 ohm resistor, and the emitter pin of each photo-transistor (marked "E" in Figure 4-7) should be connected to Ground through a 10k ohm resistor-the output for each IR pair is also tied to this pin.

  2. After placed, solder each lead to the PCB to secure it down as shown in Figure 4-9. To avoid overheating any one sensor, it is recommended to solder the first leg of each sensor, then go back to the beginning and solder the second leg of each sensor, and so on. This gives each sensor some time to cool down between soldering each leg to the prototyping board.

    Soldering each sensor into place on the prototyping board

    Figure 4.9. Soldering each sensor into place on the prototyping board

  3. After securing each sensor, solder the two pins together on the right side of each sensor pair, the anode of the emitter and collector of the photo-transistor (see Figure 4-10). You can bend the right-side leads until they are touching each other flat against the board-then solder them together, clipping off the extra with a set of plier snips.

    Make a "solder-bridge" between the anode of the emitter and the collector of the photo-transistor

    Figure 4.10. Make a "solder-bridge" between the anode of the emitter and the collector of the photo-transistor

  4. Next add 10k pull-down resistors from the photo-transistor (Detector) output pin to Ground (see Figure 4-11). By placing the pull-down resistors on each sensor output pin, we are ensuring that the Analog inputs of the Arduino will be defaulted to a value of 0, unless there is IR light activating the photo-transistor. We do this because the IR photo-transistor acts as a simple switch, enabling +5v to pass through it when turned on. When the switch is in the off state, we need to use a pull-down resistor to give the Arduino analog Input a default value (GND) so it is not left "floating."

    Install the (5) 10k ohm resistors from the emitter pin of each photo-transistor to a common Ground.

    Figure 4.11. Install the (5) 10k ohm resistors from the emitter pin of each photo-transistor to a common Ground.

  5. Add 150 ohm current-limiting resistors for the IR Emitter LEDs. Supplying 5v through the 150-ohm resistor enalbes 33mA to go to each IR Emitter, which is just below the maximum current rating. Place each 150-ohm current limiting resistor from the cathode pin of each IR emitter to Ground as shown in Figure 4-12.

    Install the (5) 150 ohm resistors from the Emitter's Cathode pin to Ground.

    Figure 4.12. Install the (5) 150 ohm resistors from the Emitter's Cathode pin to Ground.

  6. Connect all +5v pads together. You must use some jumper wires to connect each +5v pad to the next, and finally to the power wire (white wire) soldered to the bottom-right of the board (see Figure 4-13). Looks are not important because this board will be hidden in the frame, but make sure each connection is secure.

    Run red wire to each +5v pad, down to the white +5v supply wire. On the other side of the board, connect all of the Ground pads together, down to the black Ground supply wire.

    Figure 4.13. Run red wire to each +5v pad, down to the white +5v supply wire. On the other side of the board, connect all of the Ground pads together, down to the black Ground supply wire.

  7. Connect Ground wires together. I connected the Ground wires together on the other side of the board, but you can place them on the same side as the other wires if you prefer. The ground wires should likewise connect each Ground pad together and then finally the Ground supply wire at the bottom-right of the board (black wire), as shown in Figure 4-14.

    The top-side Ground supply wires can be routed on the bottom side if you like, as long as each Ground pad is connected.

    Figure 4.14. The top-side Ground supply wires can be routed on the bottom side if you like, as long as each Ground pad is connected.

  8. Connect signal Input wires. I found a five-wire plug from an old VCR that easily plugs in all five sensors at once. You can also use plain solid wire, each wire should be about 8 inches long to give enough length to reach the Analog ports on the Arduino. These signal wires should be soldered to the top of each 10k resistor (between the resistor and the photo-transistor output) in order, as shown in Figure 4-13.

  9. Lastly, I put some black electrical tape over the exposed wires on the front of the board to keep from shorting anything out when face down in the metal tin frame (see Figure 4-15).

    Electrical tape is an excellent insulator and can easily cover nearly any electrical connection. I always keep several rolls of this tape on hand.

    Electrical tape to cover the Ground and signal wires from shorting out on the tin frame

    Figure 4.15. Electrical tape to cover the Ground and signal wires from shorting out on the tin frame

The IR sensor board is now ready to be tested and then installed into Linus. To test the IR board, simply plug the power wire into the Arduino +5v and the Ground wire to Arduino Ground. Now point your digital camera at the sensors and look through the viewfinder. You should see the infrared LED's showing a pale blue color, which means they are working.

All that is left to do is connect the sensor output wires into the Arduino analog inputs. I programmed Linus such that when the IR board is facing down (as it does when installed), the far left IR sensor is 1 and the far right sensor is 5–the center is 3 and so on. Sensor 1 goes to Arduino analog input 0, and go in order from there (i.e., Sensor 3 goes in analog input 2, and 5 goes in analog input 4).

Modifying a Servo for Continuous Rotation

Servo motors are intended to operate with a range of about 180 degrees. This means that they will not spin in a complete circle without modification. By modifying these motors, you will not be able to use them as they were intended, because this procedure is mostly non-reversible. I chose to do this because you end up with small, reliable gear motors that cost around $6 each and is available at most hobby shops.

Note

If you have some other gear motors that you want to use, that is fine. You might have to adjust the speed of the motors or battery voltage of the circuit, but it should work the same.

There are two methods that you can use to modify a servo motor. Both methods involve physically removing the plastic "stops" that keep the servo shaft from rotating beyond 180 degrees. These are here because the shaft is attached to a potentiometer and if rotated beyond 180 degrees, the potentiometer shaft would break. Both methods also involve removing the potentiometer from operation, either by physically removing it altogether and soldering two resistors in its place, or by pushing it down so it is not moved by the rotating of the servo output shaft.

Method 1: Direct DC Drive with External Speed Controller

The first method (the one I used) involves removing all electronics inside the servo motor, leaving only the DC motor and the gearing. The three-wire pigtail is soldered directly to the motor terminals (red and white wires soldered to one terminal, black wire soldered to the other terminal). This is straightforward and easy to do, but requires using an external motor-driver to power the motors. These motors consume little current, so even an L293D dual motor controller IC will work (under $3 from Sparkfun.com-sku: COM-00315).

If you want to modify your servo motors to be standard gear motors, the following six steps guide you through this process.

  1. Remove four screws from the rear of the servo motor housing as shown in Figure 4-16. You need a small Phillips head screwdriver. Be careful when pulling the motor housing apart because the gears tend to fall out.

    Remove servo motors rear screws and cover using a small Phillips head screwdriver.

    Figure 4.16. Remove servo motors rear screws and cover using a small Phillips head screwdriver.

  2. Remove motor with PCB and potentiometer as shown in Figure 4-17. This might take some finesse to keep from breaking any plastic pieces on the housing, but be gentle and you should have no problems.

    Remove circuitry, and de-solder motor from PCB, then cut the red, white, and black wires from the PCB.

    Figure 4.17. Remove circuitry, and de-solder motor from PCB, then cut the red, white, and black wires from the PCB.

  3. Remove plastic stop. This is located under the output shaft. You have to remove the protruding piece of plastic that keeps the shaft from spinning 360 degrees. I used a soldering iron to melt the protruding piece of plastic away from the output shaft (gently). The idea here is to make sure the motor shaft can spin freely (see Figure 4-18).

    Using a soldering iron, melt away the plastic stop from the main black gear. It protrudes from the rest of the gear and keeps it from spinning continuously.

    Figure 4.18. Using a soldering iron, melt away the plastic stop from the main black gear. It protrudes from the rest of the gear and keeps it from spinning continuously.

  4. De-solder motor from PCB. The motor terminals on the Futaba S3003 Servo are soldered to the PCB and must be de-soldered. You can probably do this with a soldering iron if you don't have a de-soldering iron-though Radio Shack sells a decent de-soldering iron for around $12. You can save the circuitry boards if you want to try reversing this procedure in the future, though I have not tried this.

  5. Solder servo wires directly to motor terminals as shown in Figure 4-19. I soldered the red and white wires to the terminal with the red dot beside it and the black wire to the other terminal.

    Solder the red and white wires to the motor terminal with the red dot beside it, and the black wire to the other terminal. Now it is ready to be re-assembled.

    Figure 4.19. Solder the red and white wires to the motor terminal with the red dot beside it, and the black wire to the other terminal. Now it is ready to be re-assembled.

  6. Re-assemble and test. Make sure you have all the gears in their respective places (as in the picture), then tie a knot in the motor wire so that you make sure and keep some slack inside the motor compartment (see Figure 4-19). This keeps you from accidentally ripping the wires from the motor terminals. Now power the two terminals with +5v and Ground to make sure the motor output shaft spins.

Method 2: Servo Pulse Drive with Internal Motor Driving Circuitry

The second method involves removing only the potentiometer and soldering (2) 2.5k ohm resistors in its place, in the form of a resistor divider. This tells the servo circuitry that the motor is always at the center position. The servo circuitry determines which direction to spin the motor based on the value of the potentiometer. If the servo receives any pulse above 1.5 milliseconds it moves forward, and any pulse below 1.5 milliseconds make it reverse. Because it will never reach its destination on the potentiometer (remember we replaced it with fixed resistors), it will spin continuously until a different pulse is received.

To modify your servo motors to operate as DC gear motors that still use the servo drive circuitry, the following six steps guide you through this process.

  1. Remove four screws from rear of servo motor housing. You need a small Phillipshead screwdriver. Be careful when pulling the motor housing apart because the gears tend to fall out.

  2. Remove motor with PCB and potentiometer. This might take some finesse to keep from breaking any plastic pieces on the housing.

  3. Remove plastic stop. This is located under the output shaft. You have to remove the protruding piece of plastic that keeps the shaft from spinning 360 degrees. I used a soldering iron to melt the protruding piece of plastic away from the output shaft (gently). The idea here is to make sure the motor shaft can spin freely.

  4. Remove potentiometer from PCB (see Figure 4-20). You can either clip the leads or de-solder it completely. Either way, you want to place two 2.5k-ohm resistors in its place. You need to solder the first resistor from the center potentiometer pin to the left pin. The second resistor goes from the center pin to the right pin. This outputs a neutral 2.5v signal at all times to trick the servo motor into running continuously in the direction commanded.

    You can cut the leads on the black potentiometer or de-solder them. Then, solder (2) 2.5k-ohm resistors from each outer pin to the center pin and solder together.

    Figure 4.20. You can cut the leads on the black potentiometer or de-solder them. Then, solder (2) 2.5k-ohm resistors from each outer pin to the center pin and solder together.

  5. Replace PCB into servo housing. Make sure the gear teeth slide in without force, or remove the gears first and replace them after the motor/PCB are in place.

  6. Re-assemble and test. Make sure you have all the gears in their respective places.

To test the servo motor using its own circuitry, you need to use a servo command. Upload the code in Listing 4-1 to your Arduino and test the servo modified with method 2.

Example 4.1. Test a Servo Motor Connected to Arduino Pin 2

// Connect servo motor signal wire to Arduino pin 2, red wire to +5v,
// and black wire to GND - then upload to test.

#include <Servo.h>                // Include the Arduino Servo library

Servo Servo_Motor1;               // create servo called "Servo_Motor1"

void setup()
{
  Servo_Motor1.attach(2);         // attaches the servo to pin 2
}
void loop()
{
    Servo_Motor1.write(0);        // tell the Servo_Motor1 to go in Reverse
    delay(1000);                       // wait 1 second
    Servo_Motor1.write(179);   // tell the Servo_Motor1 to go Forward
}

The advantage of using method 2 is that because you did not remove the servo driver circuitry, you do not need a motor-controller to power the motors. You can control them with a simple pulse from any Arduino digital pin. This can save you $20 on the parts list.

The downside is that to keep the servo spinning the correct direction, you must send a pulse from the Arduino about every 20ms. Because this can complicate the coding somewhat, I chose to modify my servo motors using method 1 and drive them with a motor-driver. This way any gear-motor can be used with the same code.

Regardless of how you chose to modify your servo motors, we still need to attach wheels to them. Now we discuss how to connect the wheels to the servo adapter plate.

Fitting the Drive wheels

I have had extremely good luck finding old R/C toys at my local thrift store. Each car, boat, or motorcycle usually yields several DC motors, wheels, gear-boxes, and sometimes a servo motor or other interesting piece. This is where Linus' wheels come from (see Figure 4-21).

Some wheels from a thrift-store R/C car with the servo mounting bracket

Figure 4.21. Some wheels from a thrift-store R/C car with the servo mounting bracket

Though there are many wheels you can buy that mount directly to a servo motor, I opted to use the mounting hardware that came with my servo motors (the four leg cross shape bracket) and mounting them to two large wheels that I pulled from an old R/C motorcycle from the thrift store. You can use any diameter wheel you like (larger = faster), as long as you can attach the servo-mounting bracket to it. I used small #6 bolts to hold the bracket to the wheel and it is quite secure with only two bolts, as shown in Figure 4-22.

Both wheels with the servo brackets mounted and the motors next to them

Figure 4.22. Both wheels with the servo brackets mounted and the motors next to them

If using a salvaged set of wheels, follow the following four steps to mount the wheels to the servo mounting brackets.

  1. Line up the bracket in the center of the wheel and mark two holes–one at each end of the bracket.

  2. Drill holes through both the bracket and the wheel.

  3. Secure bolts tightly with screwdriver. Make sure the bracket hub points out so it can mount to the servo output shaft.

  4. Repeat for other wheel.

With the rear wheels installed, we only need a front caster wheel to have a rolling frame. In the next section, we focus on making a bracket to use when mounting the front caster wheel. Making a Caster bracket

The tin I used was relatively small and space was fairly tight, so I chose to mount the front caster wheel to the front of the tin using an "L" bracket made from aluminum pieces. My first attempt uses two pieces of aluminum strips that I bent using a vise. I later used the same process for a piece of 2-inch wide piece of flat aluminum to make one large bracket instead of two small ones, but either way will work.

To build a caster wheel-mounting bracket, perform the following steps:

  1. Make sure the bracket gives the wheel enough room to completely spin around without hitting anything. Then bend the brackets to length in a vise or with a pair of pliers, leaving about 1 inch-1.5 inches on the back side of the bracket to mount to the tin frame (see Figure 4-23).

    Bend the brackets so that there is enough room to swing the caster completely around. Then mark the mounting brackets, using the caster wheel-mounting holes with a permanent marker.

    Figure 4.23. Bend the brackets so that there is enough room to swing the caster completely around. Then mark the mounting brackets, using the caster wheel-mounting holes with a permanent marker.

  2. Drill holes for the caster mounting plate to mount to the aluminum brackets, as shown in Figure 4-24. My caster wheel required (2) 1.75 inches by 1.25 inches "L" brackets.

    Drill holes through "L" bracket where marked.

    Figure 4.24. Drill holes through "L" bracket where marked.

  3. Use bolts or rivets to secure the caster wheel to the "L" brackets, as shown in Figure 4-25. With the brackets mounted, the caster wheel is ready to be mounted to the frame.

    The caster wheel with all four bolts secured to the mounting bracket.

    Figure 4.25. The caster wheel with all four bolts secured to the mounting bracket.

At this point, the two rear wheels should be able to mount to the servo motors and the front caster wheel should have a bracket mounted and ready to install onto the frame. Next, we need to build the frame.

Making a Frame

I actually modified an aluminum tin from the thrift store to use as Linus' frame. Anytime I build a robot, I look through my current stock of materials and scraps to see whether anything can be re-used for my new bot. If not, I make a trip to the local thrift store to check out their supply of used goods. This trip, I found a pile of old cookie tins that are now empty and sold for around $0.39 each! As it turns out, a cookie tin can serve as an excellent lightweight metal frame for a small robot. I bought several of different shapes and sizes to give myself some options later.

The tin I decided to use was a Poke'mon children's card game tin that has a nice little clear plastic window on the lid, so you can see the electronics neatly tucked away inside. The lid serves as a stabilizer for the rest of the frame, tying the whole thing together-but also allows for easy access to the electronics if needed.

There are several modifications needed for the tin in order to mount motors, the Arduino, and the IR board inside, which are outlined in the following steps:

  1. First, we need to measure, mark, and cut the holes for the drive motors. The bottom of the tin should sit about 0.25 inch above the ground so that the frame does not scrape when driving. First, measure the radius of the wheel, and then subtract 0.25 inch from that measurement. This tells you exactly how high on the tin that the center of the wheel axle (motor output shaft) should be mounted. Use a permanent marker to mark this spot, measured from the bottom and toward the rear of the frame.

    Next it is time to measure the servo motor and mark these dimensions, centered around your previous mark. The dimensions of my motor mounting holes were 0.75 inch W by 1.625 inches L, though I added a little padding to make sure I could move the motor around slightly if needed. Measure the same distance on the other side of the tin.

    Now using a Dremel rotary tool or similar, carefully cut the holes that you marked using a metal cutoff wheel (see Figure 4-26). This metal is sharp when cut, so wear gloves and don't cut yourself!

    Using a Dremel rotary tool (or similar), cut holes the size of your motors.

    Figure 4.26. Using a Dremel rotary tool (or similar), cut holes the size of your motors.

  2. Test fit the servo motors into the mounting holes. If they fit, place the wheels onto the motors and make sure there is about 0.25 inch clearance between the bottom of the frame and the ground (this should be the same on each side). After proper clearance is achieved, you can mount the motors with (4) #6 bolts and nuts (see Figure 4-27). You can also mount the wheels to the motors at this time, using the screws that came with your servo motors. Simply slide the wheel onto the output shaft, and insert the screw through the center of the wheel hub. Tighten the screw down so that the wheel cannot wobble or move side to side.

    The wheel holes have been cut, the wheel test-fitted, and the rear ground-clearance looks good (about 0.25 inch to 0.5 inch).

    Figure 4.27. The wheel holes have been cut, the wheel test-fitted, and the rear ground-clearance looks good (about 0.25 inch to 0.5 inch).

  3. Now we mount the caster wheel assembly to the front of the frame, as shown in Figure 4-28. Drill a hole in the back of the bracket on each side to mount into the tin frame. Now center the caster wheel bracket on the front of the frame and adjust the height until it is the same as the rear (0.25 inch) and mark each caster bracket mounting hole to the frame. After marked, drill holes through the frame and mount the front caster wheel.

    The caster wheel assembly is mounted in the frame along with the motors.

    Figure 4.28. The caster wheel assembly is mounted in the frame along with the motors.

    Note

    I went back and removed the 2 "L" brackets I previously made with a single 2-inch wide piece of aluminum flat bar (shown in Figure 4-28). I cut it to length and bent it in a vice as I did the previous brackets. I felt that the new piece looked nicer, but you can use whichever method you like.

  4. Next we need to cut an access hole for the IR sensors to peek through the bottom of the frame. This hole enables us to mount the sensor board inside of the frame. I had to clip the edges of my IR sensor board PCB with a pair of pliers to make it fit inside the odd-shaped tin. Measure the total outline of the IR sensors and mark a rectangle on the bottom of the tin (I positioned my sensor board at the front of the frame). This is where the IR sensors will poke through the bottom of the frame and detect the Line on the ground. Carefully cut this shape out with a Dremel tool (see Figure 4-29).

    The hole cut for the IR sensor board to fit through the frame toward the ground

    Figure 4.29. The hole cut for the IR sensor board to fit through the frame toward the ground

  5. Place the IR board with the sensors down, into the frame and through the access hole that you cut in the front base of the frame. With the sensors poking through the access hole, mark four mounting holes in the IR board with a marker. You can place mounting holes anywhere that does not interfere with the wires in the circuit. Drill the marked holes with a 1/8-inch bit and mount #6 bolts through the frame, from the bottom pointing upward. Now place the IR board onto the bolts and secure it with another nut on each side (see Figure 4-30). Make sure the IR sensors are evenly protruding from their access hole in the base-they should each be about 0.25 inch from the ground.

    Mount the IR sensor board into the frame, face down, and tighten nuts.

    Figure 4.30. Mount the IR sensor board into the frame, face down, and tighten nuts.

  6. Mounting the Arduino. Now we need to add some mounting bolts to the base of the frame to hold the Arduino. Place your Arduino in the bottom of the tin (centered), and mark a hole for the USB programming port to protrude from the back of the frame (you might also want to mark a hole for the DC power port). Using a ½-inch bit, drill a hole for each port at the marked spots. With the USB port extending slightly through its new access port in the back of the frame, mark the three mounting holes on the base of the frame with a permanent marker. Drill these holes with a ⅛-inch drill bit and mount (3) #6 bolts (0.5 inch-1 inch long), securing each tightly (see Figure 4-31).

    Install mounting bolts for Arduino in the frame.

    Figure 4.31. Install mounting bolts for Arduino in the frame.

  7. Now place the Arduino on the mounting bolts and secure with one more nut. The USB port should poke through the back of the frame for easy programming.

  8. Install Adafruit motor-shield. This simply plugs on top of the Arduino. You should connect the VIN jumper that enables the Arduino to use the same power supply as the motor-controller, which will simplify the wiring.

Congratulations, you are finished building a basic Linus, the Line-bot. It is now time to make the electrical connections (see Figure 4-32).

Bottom view of the finished Line-bot

Figure 4.32. Bottom view of the finished Line-bot

Making Connections

It is time to connect each of the sensor signal wires into the Arduino analog ports, according to Table 4-2. Each analog input pin is accessible from the top of the AF motor-shield. By connecting each infrared sensor to an analog input of the Arduino, Linus will have five different points of detection.

Table 4.2. Where to Connect Each Sensor to the Arduino

Sensor Number

Arduino Analog Port

Sensor 1

A0

Sensor 2

A1

Sensor 3

A2

Sensor 4

A3

Sensor 5

A4

Speed control Potentiometer (if used)

A5

With the sensors connected, we still need to connect them to a power source. The Arduino is an excellent option here, because it has a built-in 5v regulator-simply connect the IR sensor board power wires to the Arduino +5v and GND pins.

Lastly, we need to connect both motors to the motor-controller. The left motor should connect to M1 on the AF motor-shield, and right motor should connect to M3 on the motor-shield. If the motor does not spin forward when powered, you need to reverse the polarity of the motor by swapping the terminal wires connected to the motor-shield. With all of the electronics installed, we need to find a battery to fit in our frame (see Figure 4-33).

Inside view of the Line-bot

Figure 4.33. Inside view of the Line-bot

With all of the electronics mounted inside of Linus, we need to add only a power supply to get him moving.

Installing Batteries

You can use any type of batteries that you can find, provided that they are between 5v–8v, and fit inside the frame. I am using (2) 6v 1000mAH NiCad rechargeable R/C batteries packs from Radio Shack. They were on clearance for $0.50 each with a charger, so I bought a few and arranged them in parallel (positive terminals tied together and negative terminals tied together) to produce 6v with 2000mAH-that means it will run at the same speed as one battery pack (6v), but with twice the run time (1000mAH × 2).

I placed my batteries into the front of the frame above the IR shield. They fit nicely in front of the motors, though I wedged a small piece of styrofoam between the battery pack and the inside of the frame to keep everything secure.

If you don't want to use a battery pack, you can buy a battery holder from Radio shack, which enables you to place four "AA" batteries (either re-chargeable or regular) into the pack to produce between 4.8v–6v depending on the batteries used (Radio Shack part #270-391-$1.79).

Keep in mind that servo motors were designed to run on voltages from 4.5v – 7.5v. Using a voltage above this level can damage the servo motor.

Install Power Switch

I used a SPST toggle switch to switch the positive supply wire between the batteries and electronics. By mounting the switch at the rear of the frame above the Arduino USB port, you can easily kill the power with the flip of a switch. The positive wire coming from the battery should be soldered to one post the switch, and the other post should be connected to the power supply of the AF motor-shield. If you set the VIN jumper on the AF motor-shield, your Arduino will be powered using the same source as the motor-controller. The Arduino ground wire can be connected directly to the battery ground supply.

With everything installed in the frame, it is time to load the code and start testing.

Loading the Code

Now that we are done with the hard part, it is time to load the code to your Arduino. First open the Arduino IDE and copy the code to a blank sketch (you can also download the code so you don't have to type it all out). After copied, press the Compile button to make sure there are no errors. Now select your Atmega chip from the "Tools • Board" menu (I am using the Arduino Duemilanove with the Atmega328 chip). Now plug in the Arduino to your PC USB port and press the Upload button. Instead of

Download Code: https://sites.google.com/site/arduinorobotics/home/chapter4_files

The plan is for Linus to try to line up his center IR sensor (sensor 3) directly on top of the black line on the track (Listing 4-2). If the value of sensor 3 is below the threshold (reading a black surface), we know that the bot is centered on the line and we can command it to drive both motors straight forward.

If sensor 3 rises above the threshold value, we will then check both the left-center sensor (sensor 2) and the right-center sensor (sensor 4) to see whether either is below the threshold. If so, we proceed forward with both motors, and if not we proceed to the next test.

If by some chance, sensors 2, 3, and 4 are all above the threshold, we proceed to check sensors 1 and 5 (the far left and far right sensors) to see whether either of them are below the threshold value. If so, we turn back from that direction to return to center.

You might have to calibrate your Max and Min values for each sensor, because they might differ from mine. They are denoted as "s1_min" and "s1_max" for sensor 1, and so on. To test the max value, place the assembled bot onto your white poster-board track-with no black tape beneath it, which should enable all five sensors to read their highest value. Now place each sensor above the black tape, and record both the minimum and maximum values for each sensor. Remember, sensor 1 should be the far left sensor, and sensor 5 is the far right (see Table 4-1 for the parts list).

Example 4.2. Full code listing for Linus.

// Linus the Line-bot
// Follows a Black line on a White surface (poster-board and electrical tape).
// Code by JDW 2010 - feel free to modify.

#include <AFMotor.h>  // this includes the Afmotor library for the motor-controller

AF_DCMotor motor_left(1);  // attach motor_left to the Adafruit motorshield M1
AF_DCMotor motor_right(3); // attach motor_right to the Adafruit motorshield M3

// Create variables for sensor readings

int sensor1 = 0;
int sensor2 = 0;
int sensor3 = 0;
int sensor4 = 0;
int sensor5 = 0;

// Create variables for adjusted readings

int adj_1 = 0;
int adj_2 = 0;
int adj_3 = 0;
int adj_4 = 0;
int adj_5 = 0;


// You can change the min/max values below to fine tune each sensor on your bot

int s1_min = 200;
int s1_max = 950;

int s2_min = 200;
int s2_max = 950;

int s3_min = 200;
int s3_max = 950;

int s4_min = 200;
int s4_max = 950;

int s5_min = 200;
int s5_max = 950;
// this threshold defines when the sensor is reading the black line
int lower_threshold = 20;

// value to define a middle threshold (half of the total 255 value range)
int threshold = 128;

// this threshold defines when the sensor is reading the white poster board
int upper_threshold = 230;

// this value sets the maximum speed of linus (255 = max).
// using a speed potentiometer will over-ride this setting.


int speed_value = 255;

// end of changeable variables

void setup()
{
  Serial.begin(9600); // start serial monitor to see sensor readings

// declare left motor
  motor_left.setSpeed(255);
  motor_left.run(RELEASE);

// declare right motor
  motor_right.setSpeed(255);
  motor_right.run(RELEASE);
}

void update_sensors(){

// this will read sensor 1
  sensor1 = analogRead(0);
  adj_1 = map(sensor1, s1_min, s1_max, 0, 255);
  adj_1 = constrain(adj_1, 0, 255);

// this will read sensor 2
  sensor2 = analogRead(1);     //  sensor 2 = left-center
  adj_2 = map(sensor2, s2_min, s2_max, 0, 255);
  adj_2 = constrain(adj_2, 0, 255);

// this will read sensor 3
  sensor3 = analogRead(2);         // sensor 3 = center
  adj_3 = map(sensor3, s3_min, s3_max, 0, 255);
  adj_3 = constrain(adj_3, 0, 255);

// this will read sensor 4
  sensor4 = analogRead(3);     //  sensor 4 = right-center
  adj_4 = map(sensor4, s4_min, s4_max, 0, 255);
  adj_4 = constrain(adj_4, 0, 255);
// this will read sensor 5
  sensor5 = analogRead(4);  // sensor 5 = right
  adj_5 = map(sensor5, s5_min, s5_max, 0, 255);
  adj_5 = constrain(adj_5, 0, 255);

// check value for speed potentiometer if present  (to read the pot, uncomment line below)
//speed_pot = analogRead(5) / 4;

}

void loop(){

  update_sensors(); // update sensors

  //speed_value = speed_pot;  // Leave commented out, unless using potentiometer


// first, check the value of the center sensor
  if (adj_3 < lower_threshold){

// if center sensor value is below threshold, check surrounding sensors
    if (adj_2 > threshold && adj_4 > threshold){

      // if all sensors check out, drive forward
      motor_left.run(FORWARD);
      motor_left.setSpeed(speed_value);

      motor_right.run(FORWARD);
      motor_right.setSpeed(speed_value);
    }
    // you want the bot to stop when it reaches the black box.

    else if (adj_1 < 1){
      if (adj_2 < 1){
        if (adj_3 < 1){
          if (adj_4 < 1){
            if (adj_5 < 1){

          //  if all sensors are reading black, stop Linus.
              motor_left.run(RELEASE);
              motor_right.run(RELEASE);

            }
          }
        }
      }
    }
  }

// otherwise, the center sensor is above the threshold
// so we need to check what sensor is above the black line
else {


     // first check sensors 1
     if (adj_1 < upper_threshold && adj_5 > upper_threshold){
      motor_left.run(RELEASE);
      motor_left.setSpeed(0);

      motor_right.run(FORWARD);
      motor_right.setSpeed(speed_value);
    }

    // then check sensor 5
    else if (adj_1 > upper_threshold && adj_5 < upper_threshold){
      motor_left.run(FORWARD);
      motor_left.setSpeed(speed_value);

      motor_right.run(RELEASE);
      motor_right.setSpeed(0);
    }

    // if not sensor 1 or 5, then check sensor 2
    else if (adj_2 < upper_threshold && adj_4 > upper_threshold){
      motor_left.run(RELEASE);
      motor_left.setSpeed(0);

      motor_right.run(FORWARD);
      motor_right.setSpeed(speed_value);
    }

    // if not sensor 2, then check sensor 4
    else if (adj_2 > upper_threshold && adj_4 < upper_threshold){
      motor_left.run(FORWARD);
      motor_left.setSpeed(speed_value);

      motor_right.run(RELEASE);
      motor_right.setSpeed(0);
    }


  }

  ///// Print values for each sensor

  /////sensor 1 values
  Serial.print("sensor 1:  ");
  Serial.print(sensor1);
  Serial.print("  -  ");

  Serial.print("Adj 1:  ");
  Serial.print(adj_1);
  Serial.print("  -  ");
/////sensor 2 values
  Serial.print("sensor 2:  ");
  Serial.print(sensor2);
  Serial.print("  -  ");

  Serial.print("Adj 2:  ");
  Serial.print(adj_2);
  Serial.print("  -  ");

  /////sensor 3 values
  Serial.print("sensor 3:  ");
  Serial.print(sensor3);
  Serial.print("  -  ");

  Serial.print("Adj 3:  ");
  Serial.print(adj_3);
  Serial.print("  -  ");

  /////sensor 4 values
  Serial.print("sensor 4:  ");
  Serial.print(sensor4);
  Serial.print("  -  ");

  Serial.print("Adj 4:  ");
  Serial.print(adj_4);
  Serial.print("  -  ");

  /////sensor 5 values
  Serial.print("sensor 5:  ");
  Serial.print(sensor5);
  Serial.print("  -  ");

  Serial.print("Adj 5:  ");
  Serial.print(adj_5);
  Serial.print(" ");

  Serial.print("speed:  ");
  Serial.print(speed_pot);
  Serial.println(" ");


}

// end of code

Lastly, we need to make a track to test Linus on. The track will only require a roll of black tape and your imagination.

Making the Track

The track is the fun part, because it can be any shape or size that you want. I chose to use two pieces of white poster-board from the craft store, using black electrical tape for the line (Figure 4-34). I placed the poster-board together end-to-end and taped the underside with clear packing tape. You can add as many pieces of poster-board as you want, the bigger the better. You can make different tracks on each side of the poster-board, so you might want to buy a few rolls of electrical tape.

Track 1: Linus continuously drives around making different decisions at each turn. If he ever makes it into the black box, he gets to rest.

Figure 4.34. Track 1: Linus continuously drives around making different decisions at each turn. If he ever makes it into the black box, he gets to rest.

Although it is fun to watch the bot meander around the track at its own will, at some point you want to give it a break. So I wrote a section of code that tells the motors to stop if all sensors are reading black-then by placing a black square of electrical tape about (4 inch × 4 inch) at the end of the track, the bot will stop when it reaches this point.

The track in Figure 4-34 lets Linus wander around for as long as he wants and his path changes depending on what angle he enters each line intersection. The only drawback is that it takes Linus a long time to pick the path leading to the black box.

Unlike the above track, the track in Figure 4-35 is a definite length and might be better suited for calculating speed and tweaking Linus' settings. This track is also reversible, so when you get to the center black box, you can turn around and go back to the beginning black box.

Track 2: This track starts at the top and ends in the middle. You can turn Linus around and have him go back the way he came, but he will stop either way. This track is good for lap time testing (to see whether modifications in the code result in a faster lap time).

Figure 4.35. Track 2: This track starts at the top and ends in the middle. You can turn Linus around and have him go back the way he came, but he will stop either way. This track is good for lap time testing (to see whether modifications in the code result in a faster lap time).

Testing

After you have your track designed, place your bot on the line and turn on the power. You should see Linus start moving, and if everything is wired up correctly, following the black line. You can hold the front of the bot with the IR sensors just above the black line while the rear wheels slightly off the ground. When sensor 3 is directly above the black line, you should see both wheels spinning. If you move the bot to the right slowly, you should see the left wheel stop while the right wheel spins at full speed attempting to correct the position. If you move the bot to the left, you should see the right wheel stop while the left wheel spins.

If you want to experiment, you can change the following variables to see Linus exhibit a different behavior on the track:

// this threshold defines when the sensor is reading the black line
int lower_threshold = 20;

// value to define a middle threshold (half of the total 255 value range)
int threshold = 128;

// this threshold defines when the sensor is reading the white poster board
int upper_threshold = 230;

// this value sets the maximum speed of linus (255 = max).
// using a speed control potentiometer will over-ride this setting.
int speed_value = 255;

These variables determine how far from the black line the bot will allow before trying to correct its position and the maximum speed of Linus. If you mess it up, you can always re-download the original.

Add-ons

Now that you have your line-bot assembled and working, you can start adding whatever you want. I added two blue LED lights (one on each motor) that light up whenever that motor is turned on. I also painted the frame with flat black spray paint, and added a white "racing-stripe" down the center of the lid. I later added a potentiometer to the front to easily adjust the "speed_value" variable mentioned previously without re-programming.

LED Lights

To add LEDs to each motor, simply connect the LED to the motor terminals. You can buy pre-biased LEDs (that already have a resistor built-in), but you want to make your own by, soldering a resistor (330 ohm to 1k ohm) to either lead of the LED. After the resistor is installed, connect one LED to each motor terminal (see Figure 4-36). You have to connect the LED's positive lead to the motor's positive lead and negative to negative. If you plug it in backwards, it shouldn't hurt the LED at 6 volts, but it won't light up.

LED with resistor soldered to one leg

Figure 4.36. LED with resistor soldered to one leg

After soldering the LED leads and resistor, and connecting it to the motor terminals, you need to secure the LED in place so it doesn't wobble around (see Figure 4-37 and 4-38). You can drill a small hole on each side of the tin just above the motor and mount the LED pointing outside so you can see them light up.

LED with resistor hot-glued to the top of the servo motor casing

Figure 4.37. LED with resistor hot-glued to the top of the servo motor casing

Both blue LEDs lit up as the bot is driving forward with both motors

Figure 4.38. Both blue LEDs lit up as the bot is driving forward with both motors

As I mentioned, my tin has a small clear plastic window in the lid, so I chose to mount my LEDs on top of each Servo motor inside the tin. The LEDs can be seen through the plastic window as each motor spins (see Figure 4-39). To keep them secure, I used a hot-glue gun with a few dabs on each LED lead to keep it secure to the top of the motor. This glue holds very well but with a flat head screwdriver, but can be removed if desired in the future with no harm to your motors.

Both blue LEDs lit up with the lid on top-you can see through the plastic window.

Figure 4.39. Both blue LEDs lit up with the lid on top-you can see through the plastic window.

Painting

I decided that I didn't really want Linus to sport a Poke'mon paint job, so I took his rear wheels off, taped him up, and spray painted his frame (see Figure 4-40). I thought I would keep it simple, so he got a gray primer coat, then a flat black base coat (see Figure 4-42), then a stripe down the center with some flat white paint. I also sprayed the bottom black to make sure nothing reflected from the bottom of the silver Tin.

I used three cans of Rust-oleum spray paint. Each can of paint lasts for several different projects, so they are worth buying.

Figure 4.40. I used three cans of Rust-oleum spray paint. Each can of paint lasts for several different projects, so they are worth buying.

Prep the bot for painting with some white paper to cover the electronics and green painters tape to cover the motors, caster wheel, IR sensors, and anywhere else paint might get on something it shouldn't (see Figure 4-41). I had to tape off the clear plastic window on the lid so it would still be see-through.

The bot is prepped with tape and ready for spraying.

Figure 4.41. The bot is prepped with tape and ready for spraying.

The first coat of flat black paint, after the gray primer

Figure 4.42. The first coat of flat black paint, after the gray primer

You should spray thin, light coats with the spray paint and wait about 30–40 minutes before re-coating. Lastly, adding a stripe to the lid means putting tape everywhere, except where you want the line to be (see Figure 4-43). In this case, I wanted my stripe to be about the same width as the line on the track, so I did a rough measurement with a roll of electrical tape on each end and put masking tape everywhere else. I then primed the stripe gray, and then painted it white when that was dry. When the last coat of paint dries, you can put Linus remove all masking tape and mount the wheels back on to the motor output shafts, as shown in Figure 4-44.

Priming the stripe on the lid

Figure 4.43. Priming the stripe on the lid

And here is the finished product of the spray paint job.

The finished paint job for Linus

Figure 4.44. The finished paint job for Linus

Adding Speed Regulator (Potentiometer)

Because our five sensors are only using up five of the six Arduino analog inputs (A0-A4), we still have one available (A5). The speed of the bot can be changed in the code by adjusting the value of the "speed_value" variable, but by adding a potentiometer connected to last remaining analog pin, we can adjust the top speed of the bot on the fly without re-programming the Arduino. The speed control potentiometer is not necessary, though it makes testing the line-bot much easier.

A potentiometer and three strands of solid copper wire to use for the speed control

Figure 4.45. A potentiometer and three strands of solid copper wire to use for the speed control

If you choose to add this potentiometer, you will need to plug the left pin into Ground, the center pin into Arduino analog pin 5 (the last one), and the right pin to Arduino +5v, according to Table 4-3. Then simply remove the comment lines beneath the "update_sensors();" line at the beginning of the main loop as shown in the following code. This tells the Arduino to update the "speed_value" variable to equal the potentiometer reading, each time the sensors are updated.

Change this:

void loop(){

  update_sensors();

  // speed_value = speed_pot;

to this:

void loop(){

  update_sensors();  // this line remains unchanged.

  speed_value = speed_pot;  // removed comment lines from beginning of this line.

Table 4.3. Potentiometer wiring chart.

Wire

Potentiometer Pole

Arduino Connection

Red

Left pole

Arduino +5v

Green

Center pole

Arduino A5 (analog input 6)

Black

Right pole

Arduino Ground

To mount the potentiometer, use a ⅜-inch drill bit (or the recommended size for the potentiometer you are using) to drill a hole in the front of the frame, just above the caster wheel bracket (see Figure 4-46). Slide the potentiometer through the hole, and use the washer and nut to secure it to the frame.

The speed control potentiometer mounted through the front of the frame

Figure 4.46. The speed control potentiometer mounted through the front of the frame

Now adjusting the top speed of the bot is as simple as turning a knob. This comes in handy if you are using a battery pack above 6v, and find that the bot moves too quickly or you would like to test it at a slower speed.

You can see the finished Linus in Figure 4-47.

Top view of the finished Line-bot with the potentiometer mounted

Figure 4.47. Top view of the finished Line-bot with the potentiometer mounted

Summary

In this chapter, we used infrared light to detect the reflectivity of a surface. We found that darker colored surfaces (like black tape) reflect less infrared light than a lighter colored surface (like a white poster-board). Using a homemade infrared sensor board with five basic IR emitter/detector pairs, Linus is able to determine what sensor is directly above the black line.

We also discovered how to modify a standard hobby servo motor for continuous rotation, as well as how to remove the servo circuitry to operate as a standard DC gear motor. We then mounted the drive wheels to the servo adapter plates to secure to each motor, and made a mounting bracket for the front caster wheel.

The frame for this robot is a tin container that was used to hold a children's card game, and was modified using a Dremel rotary tool using a metal cut-off wheel attachment. The motors, front caster wheel, and Arduino were then mounted into the frame. After completing the frame, we installed the AdaFruit motor-shield atop the Arduino, a 6v battery for power, and made the connections from the IR sensor board and battery to the Arduino, and the motors to the motor-controller.

With everything installed, we loaded the code to the Arduino, made a track using poster-board and electrical tape, and began testing Linus. By changing the speed variables and light thresholds, we are able to change the way the robot responds to the track. After we got Linus working, we added accent lighting inside the Linus frame, a speed control potentiometer, and finally gave him a nice paint job. In the next chapter, we build another autonomous robot using ultrasonic "ping" sensors to detect and maintain a specific distance from the wall, as the maneuvers around a room autonomously...let's get ready to build Wally the wall-bot.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset