Home » 2009 » September » 15 » failurebos 5
8:21 PM
failurebos 5

FailureBot 5 - A Line Following Robot

May 27th, 2006
FailureBot 5 - Complete Robot FailureBot 5 - In Action
FailureBot 5 - Complete Robot FailureBot 5 Following A Line


The objectives of the FailureBot project originated simply as "build a line-following robot". However, it somehow evolved into a 3-year robotics experiment. My first attempt to build a robot was such a complete failure that I jokingly called it "FailureBot". The name seemed quite appropriate even as the project evolved as every one of the many, many failures yielded a critical lesson in the robot-building process.

For me, hobby robotics is about creativity. I didn't want to throw a couple sensors on a robot kit, I wanted to build it from the ground up. Looking through catalogs, reading datasheets, and building the robot within the constraints of my limited resources was the ultimate experience. Much of this robot is built from raw materials and hardware available at local hardware stores-- and done so on a very limited budget. Throughout the process, I kept a couple of concepts in mind:

  • Close enough is good enough. I'm not a NASA engineer, I'm a hobbyist. It doesn't have to be perfect, it just has to work. This is especially true considering that my "workshop" is merely a bedroom floor and a Dremel rotary tool. I don't have the facilities to make straight cuts or aligned holes. Improvise.
  • The overall goal is to learn and discover. When it felt like I was re-inventing the wheel I just reminded myself that I was learning how the wheel was invented.
  • Success is a series of failures. It can be very discouraging to spend large amounts of time only to hit a dead-end and start over. This is FailureBot 5 because I've had to start over from scratch 5 times with the physical construction. The lessons learned made it very much worth while.
  • Work within your means. I would often get discouraged by what I see other people building--making molds, welding, etc. I don't have those resources nor a large budget. A roboticist shouldn't be thinking about how it is supposed to be done, but how it could be done considering the elements.
FailureBot 5 - Complete Robot FailureBot 5 - In Action
FailureBot 3 - Alluminum Frame/PIC16F627A FailureBot 4 - Breadboard/PIC16F877A

Line Following Robots

A line-following robot, or "line follower" is a pretty common type of robot for hobbyists. Robotics competitions usually have a line-following event. The line is usually a black line about 3/4" wide, such as black electrical tape, on a white surface. Advanced courses may add new challenges such as inclines, tighter turns, intersections, thinner lines, or changing line colors. The robots typically sense the line by measuring light reflected off the ground, where a black line reflects little/no light and the white floor reflects a lot of light back.There are TONS of websites relating to line-following robots as it's a very common beginner project. The Robot Room has some great information on a couple of line following robots.

FailureBot 5 Overview

FailureBot 5 is actually a fairly good robot base which could easily be adapted to maze solving, obstacle avoiding, or other applications of a small, 2-wheeled robots. However, at this point in time, it only follows a line. The robot consists of 2 plastic round decks, differential drive using 2 DC gearhead motors, a sensor board with 5 photo-transistor/LED sensors, an L293D H-Bridge motor controller board, and an Atmel ATMega8 processor board.

FailureBot 5 Block Diagram

A sensor board with 5 sensors shines light downward at the ground. If the line is underneath the sensor, then the little/no light will be reflected back to a paired phototransistor. If the line is not underneath the sensor, more of the light will be reflected back. A microcontroller measures the output of each of the phototransistors through it's analog-to-digital converter (ADC). Based on the position of the line underneath the robot, the microcontroller adjusts the speed/direction of the DC motors to steer the robot.

Building FailureBot 5

Building the robot was the hardest part for me. I am by no means a mechanical engineer and had a lot to learn. FailureBot 5 is a round, 2-deck, 2-wheeled differential-drive robot.

A differential-drive robot works like a tank. The two wheels provide both the drive and the steering. By stopping one motor and not the other, the robot pivots on the stopped motor to turn. By turning one motor forward and the other motor backward, the robot turns in place. The wheels are offset forward slightly and a caster is placed in the back of the robot for support.

The Base and Second Deck

The base and second deck are 0.118" thick x 6" diameter Acrylic Circles purchase from Tap Plastics for $1.95 ea. They were cut to allow the wheels to be mounted within the diameter of the acrylic circles. The cutting as well as drilling holes for mounting motors and electronics was all done with a Dremel rotary tool. A piece of paper with drill/cut marks was taped over the acrylic circle as a guide for cutting. A piece of aluminum foil was also taped to the under-side of the second deck and connected to ground to serve as a sheild between the motors and the processor board.

The decks are connected to each other using 4" 6-32 screws with 6-32 hex standoffs spacing the 2 decks apart. I have no idea where I got the hex standoffs, but I'm sure they're pretty common.

Cutting the Robot Base Robot Base with Motors, Controller, Wheels and Castor
Cutting/Drilling the Base with Dremel Base with Motors, Controller, Wheels and Caster
Second Deck with Foil  
Second Deck with Aluminum Foil Sheild  

Motors and Wheels

In earlier attempts I had problems with motors not having enough torque to properly move the heavy robot bases I was building. I decided to buy gearhead motors with a very high torque and use larger wheels to make up for the loss in RPMs. There are 2 Lynx Motion Planetary Gear Motors (12vdc 189:1 31rpm) ($11.40/ea) which drive the two wheels. Each wheel is made out of two 4" round discs bolted together with 2 washers spacing them out. The discs are from Home Depot ($1.49/ea) which are used to cover electrical boxes. A 4" O-ring (also from Home Depot) sits in the gap between the two discs to serve as tires. These relatively large wheels allow the slower motors to suffice for moving the robot quickly. They are also nice and thin giving the robot the ability to easily turn by pivoting on one wheel. The wheels were then attached to the motors using a pair of the 6mm Universal Wheel Hubs from Lynxmotion ($8.00).

The motors are then mounted to the base using a homemade motor mount. Although Lynxmotion also sells motor mounts, I had already felt I had spent enough money on the motors. Home Depot (or Lowes, etc) has a section with weather stripping including long pieces of aluminum in various shapes and thicknesses. I picked up a right angle strip (4" wide piece of aluminum folded at 90 degrees) and cut it up using--once again--the Dremel rotary tool.

The motors are mounted slightly forward from the center-line of the robot and a caster from Home Depot ($2.95) was mounted in the back/center of the robot.

Lynxmotion Motor with Homemade Mount Lynxmotion Motor with Homemade Mount
Lynxmotion Motor with Home-made Mount Lynxmotion Motor with Home-made Mount
Capacitors on Motor Terminals Homemade Wheel and Lynxmotion Hub
0.1uF Capacitors on Motor Terminals Home-made Wheel and Lynxmotion Hub
Wheel without Tire Parts Making Up Homemade Wheel
Wheel without Tire Disassembled Wheel

Sensor Board

The sensor board was one of the only things that worked since the very first FailureBot. There are 5 line sensors. Each line sensor consists of a single red LED and a photo-transistor. The electronics of the sensor board will be discussed later. However, the construction here does make a difference. The phototransistors will be sensitive to the ambient light in the environment and thus I want to keep that down to a minumum. I want the light from the LEDs bouncing off the ground back to the phototransistor to be the primary light hitting the phototransistor.

I used a piece of acrylic plastic (Home Depot and Lowes sell acrylic rectangles for a few bucks) which I spray painted black in numerous thin coats to ensure that it was opaque. Then, holes are drilled for the LEDs and photo transistors such that the LEDs protrude out and the phototransistors are set in a bit (see my sketch below). I wasn't too concerned with one sensor being skewed or protruding more/less as I knew I could have each LED independently calibrated via software (discussed later).

Finally, two 3" 6-32 screws with locknuts and wingnuts are used to attach the sensor board to the robot. This way, I can adjust the distance of the sensors to the ground manually by moving the locknut up/down.

Sensor Board Front View Sensor Board Bottom View
Sensor Board (front) Sensor Board (bottom)
Sensor Board Top View Sensor Board Sketch
Sensor Board (top) Sketch of Single Sensor
Sensor Board in Action  
Sensor Board Attached and Running  

FailureBot 5 Electronics

Motor Controller

The motor controller is a simple H-Bridge using the L293D ($2.70 from Digikey). 5 lines from the microcontroller are used to control the 2 motors. ENABLE runs directly to the EN pins of the L293D to disable the motors. M1DIR is the direction control for the left motor and M2DIR is the direction control for the right motor. M1PULSE is the PWM signal to run the left motor at it's desired speed (at the time of writing, the software isn't using PWM but running the motors at full speed) and M2PULSE is the same for the right motor. This is a very common DC motor control concept and thus I'm not going to go into further detail. A Google search will return numerous pages on the topic.

When testing the motors, I found that they pulled 50mA with just the wheel spinning freely and 590mA stalled. The L293D can handle 600mA per channel. Just to be on the safe side, I put a heatsink on the L293D though It was never necessary in any of the earlier versions running on a breadboard.

The most important thing I learned with this part was this: BEWARE OF THE NOISE FROM MOTORS! The motors can add tremendous noise to the supply even when using a separate battery for the motors than from the rest of the electronics (common ground). The solution was the capacitors on the motors. Three 0.1uF capacitors were used on each motor. One was connected between the motor terminals, and also one from each terminal to the motor's casing. I also added the aluminum sheild to the under-side of the upper deck as mentioned above, and twisted the wire leads to the battery. Michael Simpson's "Reduce Motor Noise" discusses these techniques in more detail.

L293D Motor Controller

(Click to Enlarge)

L293D Motor Control L293D Motor Controller
Motor Controller (top) Motor Controller (bottom)

Sensor Board

For each sensor, I used a SSL-LX5093SRC/E RED LED with a clear lens in a T1 3/4 package ($0.54/ea from Digikey) paired with an OP505B phototransistor ($0.59 from Digikey). Since phototransistors are designed for the infared frequency spectrum, I was looking for an LED with a relatively high peak wavelength and a phototransistor with a relatively low peak wavelength, or at least a broad bandwidth, so that their active bandwidths overlap. I had read that you don't want to use infared LEDs for line detectors as infared light does have the same reflective properties as visible light. In rhetrospect, I was being a little overly concerned here. I believe just about any red LED and phototransistor would have sufficed considering the ability to calibrate the sensors via software.

I did not want to deal with difficult hardware for the sensors. I knew the tools I have at my disposal will not allow perfection in terms of mounting these LEDs and getting each of the 5 sensors to behave the same. Each of the phototransistors outputs are tied together resulting in a single output line fed back into the ADC of the microcontroller. However, only one LED is turned on at a time via software. Each sensor is individually calibrated so that ambient light and variations in how each sensor is mounted are accounted for.

Sensor Board Circuit
(Click to Enlarge)

Microcontroller Board

This robot has used a PIC16F84, PIC16F627A, PIC16F877A, and now finally, and Atmel AVR ATMega8. Whenever I'm learning to use a microcontroller, I make a little board for a common part (in this case the "mega8"). This allows me to experiement with the part without having to breadboard up the power supply and clock source each and every time. FailureBot 5 uses such a board. I take the board off and use it in other projects. So, this board is relatively generic. It simply contains the ATmega8 microprocessor with an 8.000MHz crystal oscillator, a low-dropout MAX667 +5V voltage regulator, and .100" pin headers for each of the I/O pins (My board also has the AREF pin at the header but is wired back to VCC for a +5V reference voltage).

AVR ATMega8 Processor Board Schematic

(Click to Enlarge)

ATMega8 Processor Board Top ATMega8 Board Bottom
ATMega8 Board (top) ATMega8 (bottom)

FailureBot 5 Software

The software for the robot is written in C for the Atmel AVR microcontrollers using avr-libc and the GNU gcc compiler (open-source). The software is still relatively primitive, however, it works quite well. The robot is able to handle 90 degree turns, inconsistant floor color (tiles) and intersections at a very decent speed. At this point in time, my gear motors have such a high reduction ratio that I do not need to use PWM to change the speed, however, the robot was originally designed to allow for PWM.

When turned on, the robot spins in circles on the line for a couple seconds while it calibrates the sensors. Once this calibration is complete, the robot begins it's line detection algorithm in a loop, however, the motors are disabled. By pushing a button, the motors are enabled and the robot follows the line. Pushing this button again disables the motors again. So, the robot is always performing the line following, however, it only moves when the motor enable button is activated.


During the calibration, the robot turns in place in circles above the line in an attempt to "learn" the lighting conditions of the environment. 2 values are setup for each sensor. A low value indicating the lowest value read from that sensor and one for the highest value for that sensor. At the end of the calibration, the middle of these two values is the "trip point" for the sensor. Anything above this trip point is considered high and anything below is considered low. Each LED is calibrated many times over, one at a time, as follows:

Turn on LED.
Measure ADC value from phototransistor.
If the value is lower than the lowest value measured, save this as the lowest value.
If the value is higher than the highest value measured, save this as the highest value.
Turn off LED.

Then, a trip point is setup as low value + ((high value - low value) / 2).


There are 6 directions defined for the robot.

GO_LEFT The left motor is stopped and the right motor goes forward. Robot pivots to the left on the left wheel.
GO_HARD_LEFT The left motor goes reverse and the right motor goes forward. Robot turns in place to the left.
GO_FORWARD Both motors go forward and robot goes forward.
GO_HARD_RIGHT The right motor goes reverse and the left motor goes forward. Robot turns in place to the right.
GO_RIGHT The right motor is stopped and the left motor goes forward. Robot pivots to the right on the right wheel.
GO_BRAKE Both motors are stopped. Currently not used. Disable is used instead.

Line Detection Logic

The robot decides which direction to go based on the 5 sensors. Each sensor is read one at a time and the bit value is stored in a variable. The bits are left shifted into the variable starting with the left sensor. Therefore, the leftmost sensor is the most significant bit in the variable. Based on the final result of all 5 sensors being left-shifted into the variable, the robot decides how to steer.

Bit Pattern Hex Value Decision
00100 0x04 The line is in the center. Go forward.
01110 0x0E The line is center but really thick? Go forward.
11111 0x1F Possible intersection. Go forward.
00001 0x01 Line on right-most sensor. Go hard right.
00011 0x03 Line on right-most sensor. Go hard right.
00111 0x07 Line on right-most sensor. Go hard right.
00010 0x02 Line on mid-right sensor. Go right.
00110 0x06 Line on mid-right sensor. Go right.
01100 0x0C Line on mid-left sensor. Go left.
01000 0x08 Line on mid-left sensor. Go left.
10000 0x10 Line on left-most sensor. Go hard left.
11000 0x18 Line on left-most sensor. Go hard left.
11100 0x1C Line on left-most sensor. Go hard left.
? N/A All other conditions, continue in the last direction determined. Line could be between sensors or there could be a problem.
Views: 12357 | Added by: apeh1706 | Rating: 0.0/0
Total comments: 8
8 Golden Triangle Tour   [Entry]
Golden Triangle Tour will take you to the Golden period which India has seen in the past. http://egoldentriangletour.org

7 TherGeori   [Entry]
http://atadalafil.com/#qc96 tadalafil 20mg п»їhttp://asildenafil.com/#pg41 sildenafil http://wnolvadex.com/#hm33 buy nolvadex without pharmacy

6 Bratguatt   [Entry]
http://fdoxycycline.com/#5158 purchase doxycycline without prescription

5 Wetmyboatobaw   [Entry]
http://vclomid.com/#9941 x26 twins clomid online

4 Wetmyboatobaw   [Entry]
http://vreplicawatches.com/#6842 replica watches blog

3 vxczzxcv   [Entry]

2 vxczzxcv   [Entry]
xcvxc vxzxc

1 qdzrljtoo   [Entry]
http://www.tekila-et-ses-amis.net/ 45717711674 http://www.hd-digitalsat.com/ 61258706265 http://www.isabelmarantsneakerspascher.info/
Hello. And Bye.

Name *:
Email *:
Code *: