You are on page 1of 34

Nov 6

How to make a line follower robot using 8051 micro controller - P89V51RD2
Introduction The line follower is a self operating robot that detects and follows a line that is drawn on the floor. The path consists of a black line on a white surface (or it may be reverse of that). The control system used must sense a line and maneuver the robot to stay on course, while constantly correcting the wrong moves using feedback mechanism, thus forming a simple yet effective closed loop System. The robot is designed to follow very tight curves Sample Paths The path is a black line on a white background with width of 3 cm (except at bends where a little variation may be present). It may contain paths laterally displaced by a around 3 cm and also gap of at most 5 cm. (All these specifications may vary one competition to other). . From above images we can conclude that in most of line follower competitions, we have to perform some additional task apart from following the line. Basic design and requirements The robot is built with P89V51RD2, L293D, IR sensors, LM324 , platform consisting of a toy car chassis (or hand made Al sheet chassis). The robot is designed using two motors controlling wheels. It has infrared sensors on the bottom for detect black tracking tape .It captures the line position with the help of these optical sensors called opto-couplers mounted at front end of the robot. (Each opto-coupler consists of an IR LED and an IR Sensor) when the sensors detect black surface, output of comparator, LM324 is low logic and for white surface the output is high. It reports to Figure 1: Basic Sample Arena Figure 2: Sample Arena of Kurukshetra08 (Anna University) the microcontroller for accurate control and steering of motors. Microcontroller P89V51RD2 and Motor driver L293D were used to drive the motors. Basic operation The basic operations of the line follower are as follows: 1. Capture line position with optical sensors mounted at front end of the robot. For this a combination of IR LEDs and Photo Transistor called an optocoupler is used. The line sensing process requires high resolution and high robustness. 2. Steer robot to track the line with any steering mechanism. To achieve this we use two motors governing wheels motion. Block Diagram Lets see all the system in detailed manner. INPUT SYSTEM

Sensors IR reflective sensors have one emitter (IR LED) and one receiver (Phototransistor or photo diode. If we have white surface it reflects the light and it will sensed by the receiver, similarly if we have black surface it absorbs the light and receiver can not sense light. Photo diode has property that if IR light fall on it its electrical resistance comes down ( i.e. its comes down from 150k to 10k if no noise present).For sense the change in resistance we use voltage divider circuit (as shown in figure below). Sample Calculation: Say Receiver has resistance Rs=150k without light (on black surface) Rs=10k with light (on white surface) The voltage that goes to comparator Without light: (on black surface) Vp=(Rs(Rs+R))Vcc=150(150+10))*5=4.6875V With light: (on white surface) Vp=(Rs(Rs+R))Vcc=10(10+10))*5=2.5000V Thus we get variation of voltage that is sensed by comparator IC (LM324). This gives logical high or low according to input. Comparator Comparator is a device which compares two input voltages and gives output high/low. In circuit diagram it is normally represented by a triangle havingInverting (negative) Input (-),Non-Inverting (positive) Input(+), Vcc, Ground, Output. Lets see some examples Use of comparator in IR sensor As above we see that two inputs are required for comparator. One input is from photo-receiver (like photo-diode), other is generated by us using potentiometer. The second voltage is also called as reference voltage for that sensor. Setting of reference voltage (Vref) We can vary reference voltage by using potentiometer, such that it can vary from 0V to Vcc. We set reference voltage as mean value of the sensor inputs measured with and without light. Lets connect Inverting Input of Comparator to photo- receiver, Non-Inverting Input to potentiometer (as shown in figure) and output goes to micro controller. Note: If we connect Inverting Input of Comparator to potentiometer and NonInverting Input to photo- receiver, the only difference observed is that at white surface we will get Low output and for black surface we will get High output. Voltage Regulator 78xx Voltage regulators convert fixed DC output voltage from variable DC. The most commonly used ones are 7805 and 7812. 7805 gives fixed 5V DC voltage if input voltage is in between 7.5V to 20V. They help to maintain a steady voltage level despite varying current demands and input voltage variations. If input voltage is <7.5 V then regulation won't be proper i.e. if input is 6V then output may be 5V or 4.8V, but there are some parameters for the voltage regulators

like maximum output current capability, line regulation etc.. , that won't be proper. To identify the leads of the 7805, you have to keep the lead downward (Fig a) and the writing to your side, (see the figure below). You can see the heat sink above the voltage regulator.(1-input,2-gnd,3-output). Fig b shows how to use 7805 voltage regulator. Here you can see that coupling capacitors are used for good regulation. But there is no need for it in normal case. But if 7805 is used in analog circuit we should use capacitor, otherwise the noise in the output voltage will be high. The mainly available 78xx IC's are 7805, 7809,7812,7815,7824. POTENTIOMETER (POT ' ) Potentiometer is a variable resistor which is used to vary the resistance by rotating the shaft. Potentiometers are available from 100 ohm to 470Kohm (or more). Potentiometer is a voltage divider. If we connect Lead A to Vcc and Lead B to ground then you can get voltages from 0 to Vcc by at Lead W. Mainly potentiometers are used to generate reference voltage for LM324. E.g. if we couple potentiometer to the shaft of a motor, then we can measure the angle moved by shaft by connect the output of Leads W and Lead B to an ADC to get a digital reading of angle. I.e. a shaft encoder, but there is a limitation, we can't get rotation >270 degree and also number of rotations since potentiometer shaft can only move from A to B. Above figure shows different types of potentiometers available. Second and third potentiometers are mainly used when you only want to change the value of resistance occasionally while the first one is used when we have to vary resistance frequently. Second and third one are easy to be inserted in breadboard and PCB they remain fixed. Second and third type of potentiometers also called Preset. Resistance is varied by rotating the shaft in the body of the potentiometer. PROCESSING SYSTEM Processing system acts as the Brain of robot, which generates desired output for corresponding inputs. For that we use microcontrollers. In present days, there are several companies that manufacture microcontrollers, for example ATMEL, Microchip, Intel, Motorola, Philips etc. We will be using P89V51RD2 microcontroller in our robot. It is an PHILIPS product. Basic hardware connections of P89V51RD2 B) Software Details: Programming and Simulating The program code acts as the decision-maker embedded in the microcontroller i.e. it decides what will be the outputs for particular set of input combination. Programs for the P89V51RD2 series of microcontrollers can be written in assembly (ASM) and C. Keil, Flash magic etc. are some free development softwares for programming the P89V51RD2 Microcontrollers. We are using KEIL for programming. In KEIL we write our C code, after compilation it generates .hex file that is a hardware level code. Code for Line follower Robot: #include<reg51.h> sbit sensor1=P1.0;

sbit sensor2=P1.1; sbit motor1=P0.0; sbit motor2=P0.1; void main() { sensor1=sensor2=0; motor1=moto2=0; while(1) { If(sensor1==1) Motor1=1; If(sensor2==1) Motor2=1; } } Hardware connection while burning(loading) the program into Microcontroller DRIVER IC: Driver IC works as same as muscles in human body as per the orders given by brain L293D is a dual H-bridge motor driver integrated circuit (IC). Motor drivers act as current amplifiers since they take a low-current control signal and provide a higher-current signal. This higher current signal is used to drive the motors. L293D contains two inbuilt H-bridge driver circuits. In its common mode of operation, two DC motors can be driven simultaneously, both in forward and reverse direction. The motor operations of two motors can be controlled by input logic at pins 2 & 7 and 10 & 15. Input logic 00 or 11 will stop the corresponding motor. Logic 01 and 10 will rotate it in clockwise and anticlockwise directions, respectively. Enable pins 1 and 9 (corresponding to the two motors) must be high for motors to start operating. When an enable input is high, the associated driver gets enabled. As a result, the outputs become active and work in phase with their inputs. Similarly, when the enable input is low, that driver is disabled, and their outputs are off and in the high-impedance state. Pin Description: Pin No Function Name 1 Enable pin for Motor 1; active high Enable 1,2 2 Input 1 for Motor 1 Input 1 3 Output 1 for Motor 1 Output 1 4 Ground (0V) Ground 5 Ground (0V) Ground 6 Output 2 for Motor 1 Output 2 7 Input 2 for Motor 1 Input 2 8 Supply voltage for Motors; 9-12V (up to 36V) Vcc 2

9 Enable pin for Motor 2; active high Enable 3,4 10 Input 1 for Motor 1 Input 3 11 Output 1 for Motor 1 Output 3 12 Ground (0V) Ground 13 Ground (0V) Ground 14 Output 2 for Motor 1 Output 4 15 Input2 for Motor 1 Input 4 16 Supply voltage; 5V (up to 36V) Vcc 1 DC MOTOR: DC Motors convert electrical energy (voltage or power source) to echanical energy (produce rotational motion). They run on direct current. The Dc motor works on the principle of Lorentz force which states that when a wire carrying current is placed in a region having magnetic field, than the wire experiences a force. This Lorentz force provides a torque to the coil to rotate. A commonly used DC Motor is shown in the image above . Why two motors By using two motors we can move our robot in any direction. This steering mechanism of robot is called as differential drive. Lets check how it works

Line Following Robot Full Project


Posted by admin on June 5, 2012, filed in: Microcontroller
2

Line Following Robot Full Project


In this post we will talk about Line Following Robot. Actually robot is kind of human made with machinery. Todays time is of automation and only automation. So in this time the manufacturing is not possible with the help of human. The world is Robotics world and Line Following Robot is the most important project of this Robotics world. In this post I will completely explain that how the Line Following Robot works and what components it has but before this explanation I would like to tell something about Line Following Robot. Line Following Robot is a robot that is designed to follow a specified path to pick and placement various things. In the big manufacturing industries like vehicle and machine production industries only Line Following Robots are used to manufacturing. Now I will talk about that how a Line Following Robot works and what are the basic components of this robot. Listen, Dont hurry up to make this robot because first understand the basic block diagram of a Line Following Robot and then go into the design of the circuit. The block diagram of robot you are seeing below. I will explain the working and functionality of the whole block diagram block by block.

Line Following Robot Block Diagram As you can see that there are 5 basic components of Line Following Robot. 1. Sensors : There are two sensors used in the robot. The main functionality of sensor is to sense the reflection of light. Now i will tell you that how the sensors work in this project. With the sensors there are two source lights also situated in the robot. We know that white color reflects light and black color absorbs the light so we make a white strip on the black background. When the robots sensors are on black background there will be no light reflection and if the sensors on white strip there will be a reflection of light. The sensors sense the light behavior and give their output to their corresponding comparators. 2. Comparator: The comparators are such a device which has some reference voltage. When the comparator gets an input voltage from the sensors output circuit the compare it with the reference voltage. If the sensor voltage is greater than reference voltage the comparator gives small output and if the sensors voltage is small than reference voltage of comparator then the comparator gives high voltage output. Both the outputs of comparators are fed to the micro controller that is also known as decision making device. 3. Micro controller: Micro controller is called decision making device that is programmed with a high level language such as C or C++ or assembly. There are some certain codes written in the memory of micro controller to handle the input of comparator and giving the output of motor driver circuit. 4. Motor Driver Circuit: Motor driver circuit is the final block of this robot. When the micro controller gets input from comparator it gives some output to the motor driver L293D. This is motor driver IC that can easily interact with the ATMEGA micro controllers. It takes the decision of driving the motor in left or right and slow or fast according to the micro controller signals. I am just giving the circuit diagram of Line Following Robot not only the whole circuit functionality. There are some attachments are given below to download the full Line Following Robot functionality.

Circuit Diagram Of Line Following Robot

Line Following Robot Circuit Diagram


Program for Advance Line following robot using ATmega32 mcu Crystal Frequency - No external crystal used 1Mhz internal Low Fuse Bit 0xE1 High fuse Bit 0x99 Compiler optimization --- o0 Circuit diagram and tutorial:-PlaywithRobots.com/make-it-form-scratch/advance-line-follower-robot NOTE: instead of trying complete code at once, first test small functions like forward() ,left(),right(),line_follow(),step(),left_ninety() etc if they work code will work. General logic: Step function will make robot to go from one intersection to other intersection in forward direction. Left_ninety function will rotate the robot left till robot is again allinged on line on an intersection

FEEL FREE TO CHANGE AND MODIFY!

************************************************************************************* **/ #define F_CPU 1000000UL #include <avr/io.h> #include <util/delay.h> #define S1 (PINA&0x01) #define S2 (PINA&0x02) #define S3 (PINA&0x04) #define S4 (PINA&0x08) #define FS (PINB&0x01) #define N 1 #define S 2 #define E 3 #define W 4 int bot_dir; int bot_x,bot_y; int grid_x , grid_y; int block=0; // variable to store robot initial direction // variable to store robot initial cordinate // variable to store grid size // variable to store if block is detected or not // directions // sensors

void forward(void) { PORTD&=0xF0; PORTD|=0x05; } // Forward function to move robot straing forward

void left(void) { PORTD&=0xF0; PORTD|=0x01; } // Left function to make robot turns left

void right(void) { PORTD&=0xF0; PORTD|=0x04; } // Right function to make robot turns right

void reverse(void) { PORTD&=0xF0; PORTD|=0x0A; } // Reverse function to make robot move backward

void stop(void) { PORTD&=0xF0; }

// Stop function to stop motion

void left_ninety(void) { forward(); _delay_ms(300); stop(); PORTD&=0xF0; PORTD|=0x09; _delay_ms(380); left(); _delay_ms(100); while(S1==0); stop(); if(bot_dir==N) { bot_dir=W; return;}

// this function will make robot to rotate left on the intersection // small delay to move robot forward before rotating

// these values are for rotating robot left differentially

// while its sensors are not alligned rotate // stop after sensor allignment

if(bot_dir==W) { bot_dir=S; return;} if(bot_dir==S) { bot_dir=E; return;} if(bot_dir==E) { bot_dir=N; return;}

// change direction variable

} void right_ninety(void) // this function will make robot to rotate right on the intersection { forward(); _delay_ms(300); PORTD&=0xF0; PORTD|=0x06; _delay_ms(380); right(); _delay_ms(100); while(S4==0) ; // while its sensors are not alligned rotate // these values are for rotating robot right differentially // small delay to move robot forward before rotating

stop(); if(bot_dir==N)

// stop after sensor allignment

{ bot_dir=E; return;} if(bot_dir==E)

{ bot_dir=S; return;} if(bot_dir==S) { bot_dir=W; return;} if(bot_dir==W) { bot_dir=N; return;} }

// change direction variable

void line_follow(void) { if((~S2)&&(~S3)) forward(); if((~S2)&&(S3)) left(); if((S2)&&(~S3)) right(); } // function for linefollowing

char step(void) { forward(); _delay_ms(70); while(S1||S4) { line_follow(); if(FS) {block=1; // small delay to avoid sensor fluctuation

stop(); block variable and exit return 1; } } forward(); _delay_ms(70); while(1) {if((S1==1)||(S4==1)) break; } stop(); if(bot_dir==N) bot_y++; if(bot_dir==S) bot_y--; if(bot_dir==E) bot_x++; if(bot_dir==W) bot_x--; return 0; }

// follow line till intersection if block detected return change

// move forward till the intersection is crossed

// stop just after intersection

// change robot corrdinate variable

void search(void) // make the robot moves as shown in video in search of block http://www.youtube.com/watch?v=GqAMgG-gc0c { bot_y=0; bot_x=0;

while(1) { while(bot_y<grid_y) { if(step()) return; } if((bot_x==grid_x)&&(bot_y==0)) return; right_ninety(); if(step()) return; right_ninety();

while(bot_y>0) { if(step()) return; } if((bot_x==grid_x)&&(bot_y==0)) return;

left_ninety(); if(step()) return; left_ninety(); } }

over_turn() { PORTD&=0xF0; PORTD|=0x06; _delay_ms(900); right(); _delay_ms(100); while(S4==0) ; stop(); if(bot_dir==N) { bot_dir=S; return;} if(bot_dir==E) { bot_dir=W; return;} if(bot_dir==S) { bot_dir=N; return;} if(bot_dir==W) { bot_dir=E; return;} // over turn and changes direction

reach_home()

// function to take robot to initial cooridnate

{ // many more condition exits according to robots direction of approching block, write them if you want! step();

bot_y--; if(bot_x!=0) { left_ninety(); while(bot_x) step(); } if(bot_x==0) { if( bot_dir==N) { over_turn(); while(bot_y) step(); return; } if ( bot_dir==W) { left_ninety(); while(bot_y) step(); return; } }

} void main (void) { DDRB=0x00; // making PORTB as input

DDRA=0x00; // making PORTA as input DDRD=0xFF; // making PORTD as output PORTD=0x30; // setting Logic high on Enable pin of L293D grid_x=3; grid_y=3; bot_dir=1; // setting maximun X coordinate of grid // setting maximum Y coordinate of grid // Initial robot direction , 1= North

_delay_ms(1000); // a small delay before code starts

search(); // function to search for robot over_turn(); // make over turn

reach_home(); // return to initial coordinate // line_follow(); while(1); // stuck in a infinite loop after task is completed }

FailureBot 5 - A Line Following Robot

FailureBot 5 - Complete Robot

FailureBot 5 Following A Line

Introduction 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 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.

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/Drilling the Base with Dremel

Base with Motors, Controller, Wheels and Caster

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 Home-made Mount

Lynxmotion Motor with Home-made Mount

0.1uF Capacitors on Motor Terminals

Home-made Wheel and Lynxmotion Hub

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)

Sensor Board (bottom)

Sensor Board (top)

Sketch of Single Sensor

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.

(Click to Enlarge)

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.

(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).

(Click to Enlarge)

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.

Download Source Code and Eagle Schematics

Calibration 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). Steering 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. The left motor goes reverse and the right motor goes forward. Robot turns in place to the left. Both motors go forward and robot goes forward. The right motor goes reverse and the left motor goes forward. Robot turns in place to the right. The right motor is stopped and the left motor goes forward. Robot pivots to the right on the right wheel. Both motors are stopped. Currently not used. Disable is used instead.

GO_HARD_LEFT GO_FORWARD GO_HARD_RIGHT

GO_RIGHT GO_BRAKE

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 Hex Decision

Pattern 00100 01110 11111 00001 00011 00111 00010 00110 01100 01000 10000 11000 11100 ?

Value 0x04 The line is in the center. Go forward. 0x0E The line is center but really thick? Go forward. 0x1F Possible intersection. Go forward. 0x01 Line on right-most sensor. Go hard right. 0x03 Line on right-most sensor. Go hard right. 0x07 Line on right-most sensor. Go hard right. 0x02 Line on mid-right sensor. Go right. 0x06 Line on mid-right sensor. Go right. 0x0C Line on mid-left sensor. Go left. 0x08 Line on mid-left sensor. Go left. 0x10 Line on left-most sensor. Go hard left. 0x18 Line on left-most sensor. Go hard left. 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.