line follower robot using 8051 micro controller.doc

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

Upload: mabdullah

Post on 08-Nov-2014

2.065 views

Category:

Documents


4 download

DESCRIPTION

micro-controller programming

TRANSCRIPT

Page 1: line follower robot using 8051 micro controller.doc

Nov6

How to make a line follower robot using 8051 micro controller - P89V51RD2 IntroductionThe line follower is a self operating robot that detects and follows a line that is drawnon the floor. The path consists of a black line on a white surface (or it may be reverseof that). The control system used must sense a line and maneuver the robot to stay oncourse, while constantly correcting the wrong moves using feedback mechanism,thus forming a simple yet effective closed loop System. The robot is designed tofollow very tight curvesSample PathsThe path is a black line on a white background with width of 3 cm (except at bendswhere a little variation may be present). It may contain paths laterally displaced by aaround 3 cm and also gap of at most 5 cm. (All these specifications may vary onecompetition to other)..From above images we can conclude that in most of line follower competitions, we haveto perform some additional task apart from following the line.Basic design and requirementsThe robot is built with P89V51RD2, L293D, IR sensors, LM324 , platformconsisting of a toy car chassis (or hand made Al sheet chassis). The robot is designedusing two motors controlling wheels. It has infrared sensors on the bottom for detectblack tracking tape .It captures the line position with the help of these optical sensorscalled opto-couplers mounted at front end of the robot. (Each opto-coupler consists ofan IR LED and an IR Sensor) when the sensors detect black surface, output ofcomparator, LM324 is low logic and for white surface the output is high. It reports toFigure 1: Basic Sample Arena Figure 2: Sample Arena of Kurukshetra’08 (Anna University)the microcontroller for accurate control and steering of motors. MicrocontrollerP89V51RD2 and Motor driver L293D were used to drive the motors.Basic operationThe 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 LED’s and Photo Transistor called an optocoupleris 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 weuse two motors governing wheels motion.Block DiagramLet’s see all the system in detailed manner.INPUT SYSTEM

Page 2: line follower robot using 8051 micro controller.doc

SensorsIR 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 inresistance we use voltage divider circuit (as shown in figure below).Sample Calculation:Say Receiver has resistanceRs=150kΩ without light (on black surface)Rs=10kΩ with light (on white surface)The voltage that goes to comparatorWithout light: (on black surface)Vp=(Rs÷(Rs+R))Vcc=150÷(150+10))*5=4.6875VWith light: (on white surface)Vp=(Rs÷(Rs+R))Vcc=10÷(10+10))*5=2.5000VThus we get variation of voltage that is sensed by comparator IC (LM324).This gives logical high or low according to input.ComparatorComparator is a device which compares two input voltages and gives outputhigh/low. In circuit diagram it is normally represented by a triangle having-Inverting (negative) Input (-),Non-Inverting (positive) Input(+), Vcc,Ground, Output.Let’s see some examplesUse of comparator in IR sensorAs above we see that two inputs are required for comparator. One input is fromphoto-receiver (like photo-diode), other is generated by us using potentiometer. Thesecond 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 varyfrom 0V to Vcc. We set reference voltage as mean value of the sensor inputsmeasured with and without light.Lets connect Inverting Input of Comparator to photo- receiver, Non-Inverting Input topotentiometer (as shown in figure) and output goes to micro controller.Note: If we connect Inverting Input of Comparator to potentiometer andNonInverting Input to photo- receiver, the only difference observed is that at whitesurface we will get Low output and for black surface we will get High output.Voltage Regulator 78xxVoltage regulators convert fixed DC output voltage from variable DC. The mostcommonly used ones are 7805 and 7812. 7805 gives fixed 5V DC voltage if inputvoltage is in between 7.5V to 20V.They help to maintain a steady voltage level despite varying current demands andinput voltage variations.If input voltage is <7.5 V then regulation won't be proper i.e. if input is 6V thenoutput may be 5V or 4.8V, but there are some parameters for the voltage regulators

Page 3: line follower robot using 8051 micro controller.doc

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 thewriting to your side, (see the figure below). You can see the heat sink above thevoltage regulator.(1-input,2-gnd,3-output).Fig b shows how to use 7805 voltage regulator. Here you can see that couplingcapacitors are used for good regulation. But there is no need for it in normal case. Butif 7805 is used in analog circuit we should use capacitor, otherwise the noise in theoutput 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 theshaft. 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 groundthen you can get voltages from 0 to Vcc by at Lead W. Mainly potentiometers areused to generate reference voltage for LM324.E.g. if we couple potentiometer to the shaft of a motor, then we can measure theangle moved by shaft by connect the output of Leads W and Lead B to an ADC to geta digital reading of angle. I.e. a shaft encoder, but there is a limitation, we can't getrotation >270 degree and also number of rotations since potentiometer shaft can onlymove from A to B.Above figure shows different types of potentiometers available. Second and thirdpotentiometers are mainly used when you only want to change the value of resistanceoccasionally 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 remainfixed. Second and third type of potentiometers also called Preset. Resistance isvaried by rotating the shaft in the body of the potentiometer.PROCESSING SYSTEMProcessing system acts as the Brain of robot, which generates desired output forcorresponding inputs. For that we use microcontrollers. In present days, there areseveral companies that manufacture microcontrollers, for example ATMEL,Microchip, Intel, Motorola, Philips etc. We will be using P89V51RD2 microcontrollerin our robot. It is an PHILIPS product.Basic hardware connections of P89V51RD2B) Software Details:Programming and SimulatingThe program code acts as the decision-maker embedded in the microcontrolleri.e. it decides what will be the outputs for particular set of input combination.Programs for the P89V51RD2 series of microcontrollers can be writtenin assembly (ASM) and C. Keil, Flash magic etc. are some free developmentsoftware’s for programming the P89V51RD2 Microcontrollers. We are usingKEIL for programming.In KEIL we write our C code, after compilation it generates ‘.hex’ file that is ahardware level code.Code for Line follower Robot:#include<reg51.h>sbit sensor1=P1.0;

Page 4: line follower robot using 8051 micro controller.doc

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 intoMicrocontrollerDRIVER IC:Driver IC works as same as muscles in human body as per the orders givenby brainL293D is a dual H-bridge motor driver integrated circuit (IC). Motor drivers act ascurrent amplifiers since they take a low-current control signal and provide ahigher-current signal. This higher current signal is used to drive the motors.L293D contains two inbuilt H-bridge driver circuits. In its common mode ofoperation, two DC motors can be driven simultaneously, both in forward andreverse direction. The motor operations of two motors can be controlled by inputlogic at pins 2 & 7 and 10 & 15. Input logic 00 or 11 will stop the correspondingmotor. 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 tostart 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 outputsare off and in the high-impedance state.Pin Description:PinNoFunction Name1 Enable pin for Motor 1; active high Enable 1,22 Input 1 for Motor 1 Input 13 Output 1 for Motor 1 Output 14 Ground (0V) Ground5 Ground (0V) Ground6 Output 2 for Motor 1 Output 27 Input 2 for Motor 1 Input 28 Supply voltage for Motors; 9-12V (up to 36V) Vcc 2

Page 5: line follower robot using 8051 micro controller.doc

9 Enable pin for Motor 2; active high Enable 3,410 Input 1 for Motor 1 Input 311 Output 1 for Motor 1 Output 312 Ground (0V) Ground13 Ground (0V) Ground14 Output 2 for Motor 1 Output 415 Input2 for Motor 1 Input 416 Supply voltage; 5V (up to 36V) Vcc 1DC MOTOR:DC Motors convert electrical energy (voltage or power source) to echanicalenergy (produce rotational motion). They run on direct current. The Dc motorworks on the principle of Lorentz force which states that when a wire carryingcurrent is placed in a region having magnetic field, than the wire experiences aforce. This Lorentz force provides a torque to the coil to rotate.A commonly used DC Motor is shown in the image above.Why two motorsBy using two motors we can move our robot in any direction. This steeringmechanism of robot is called as differential drive.Let’s 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. Today’s 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, Don’t 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.

Page 6: line follower robot using 8051 micro controller.doc

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 robot’s 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 sensor’s 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.

Page 7: line follower robot using 8051 micro controller.doc

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!

Page 8: line follower robot using 8051 micro controller.doc

***************************************************************************************/

#define F_CPU 1000000UL

#include <avr/io.h>

#include <util/delay.h>

#define S1 (PINA&0x01) // sensors

#define S2 (PINA&0x02)

#define S3 (PINA&0x04)

#define S4 (PINA&0x08)

#define FS (PINB&0x01)

#define N 1

#define S 2 // directions

#define E 3

#define W 4

int bot_dir; // variable to store robot initial direction

int bot_x,bot_y; // variable to store robot initial cordinate

int grid_x , grid_y; // variable to store grid size

int block=0; // variable to store if block is detected or not

void forward(void)

{ PORTD&=0xF0; // Forward function to move robot straing forward

PORTD|=0x05; }

void left(void)

{ PORTD&=0xF0; // Left function to make robot turns left

PORTD|=0x01; }

Page 9: line follower robot using 8051 micro controller.doc

void right(void)

{ PORTD&=0xF0; // Right function to make robot turns right

PORTD|=0x04; }

void reverse(void)

{ PORTD&=0xF0; // Reverse function to make robot move backward

PORTD|=0x0A; }

void stop(void) // Stop function to stop motion

{ PORTD&=0xF0; }

void left_ninety(void) // this function will make robot to rotate left on the intersection

{ forward(); // small delay to move robot forward before rotating

_delay_ms(300);

stop();

PORTD&=0xF0; // these values are for rotating robot left differentially

PORTD|=0x09;

_delay_ms(380);

left();

_delay_ms(100);

while(S1==0); // while its sensors are not alligned rotate

stop(); // stop after sensor allignment

if(bot_dir==N)

{ bot_dir=W; return;}

Page 10: line follower robot using 8051 micro controller.doc

if(bot_dir==W) // change direction variable

{ bot_dir=S; return;}

if(bot_dir==S)

{ bot_dir=E; return;}

if(bot_dir==E)

{ bot_dir=N; return;}

}

void right_ninety(void) // this function will make robot to rotate right on the intersection

{

forward(); // small delay to move robot forward before rotating

_delay_ms(300);

PORTD&=0xF0;

PORTD|=0x06; // these values are for rotating robot right differentially

_delay_ms(380);

right();

_delay_ms(100);

while(S4==0) // while its sensors are not alligned rotate

;

stop(); // stop after sensor allignment

if(bot_dir==N)

{ bot_dir=E; return;}

if(bot_dir==E)

Page 11: line follower robot using 8051 micro controller.doc

{ bot_dir=S; return;} // change direction variable

if(bot_dir==S)

{ bot_dir=W; return;}

if(bot_dir==W)

{ bot_dir=N; return;}

}

void line_follow(void)

{ if((~S2)&&(~S3))

forward(); // function for linefollowing

if((~S2)&&(S3))

left();

if((S2)&&(~S3))

right();

}

char step(void)

{ forward(); // small delay to avoid sensor fluctuation

_delay_ms(70);

while(S1||S4)

{

line_follow();

if(FS)

{block=1;

Page 12: line follower robot using 8051 micro controller.doc

stop(); // follow line till intersection if block detected return change block variable and exit

return 1; }

}

forward();

_delay_ms(70);

while(1)

{if((S1==1)||(S4==1)) // move forward till the intersection is crossed

break;

}

stop(); // stop just after intersection

if(bot_dir==N)

bot_y++;

if(bot_dir==S)

bot_y--;

if(bot_dir==E) // change robot corrdinate variable

bot_x++;

if(bot_dir==W)

bot_x--;

return 0;

}

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;

Page 13: line follower robot using 8051 micro controller.doc

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

}

}

Page 14: line follower robot using 8051 micro controller.doc

over_turn()

{

PORTD&=0xF0;

PORTD|=0x06;

_delay_ms(900);

right(); // over turn and changes direction

_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;}

}

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

Page 15: line follower robot using 8051 micro controller.doc

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

Page 16: line follower robot using 8051 micro controller.doc

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; // setting maximun X coordinate of grid

grid_y=3; // setting maximum Y coordinate of grid

bot_dir=1; // 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

Page 17: line follower robot using 8051 micro controller.doc

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.

Page 18: line follower robot using 8051 micro controller.doc

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

Page 19: line follower robot using 8051 micro controller.doc

Line Following RobotsA 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 OverviewFailureBot 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 5Building 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

Page 20: line follower robot using 8051 micro controller.doc

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 DeckThe 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

Page 21: line follower robot using 8051 micro controller.doc

Second Deck with Aluminum Foil Sheild

Motors and WheelsIn 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

Page 22: line follower robot using 8051 micro controller.doc

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

Page 24: line follower robot using 8051 micro controller.doc

Wheel without Tire Disassembled Wheel

Sensor BoardThe 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.

Page 26: line follower robot using 8051 micro controller.doc

Sensor Board (top) Sketch of Single Sensor

Page 27: line follower robot using 8051 micro controller.doc

Sensor Board Attached and Running

FailureBot 5 Electronics

Motor ControllerThe 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

Page 28: line follower robot using 8051 micro controller.doc

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)

Page 29: line follower robot using 8051 micro controller.doc

Motor Controller (top) Motor Controller (bottom)

Sensor BoardFor 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.

Page 30: line follower robot using 8051 micro controller.doc

(Click to Enlarge)

Microcontroller BoardThis 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

Page 31: line follower robot using 8051 micro controller.doc

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

Page 32: line follower robot using 8051 micro controller.doc

(Click to Enlarge)

ATMega8 Board (top) ATMega8 (bottom)

FailureBot 5 SoftwareThe 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

Page 33: line follower robot using 8051 micro controller.doc

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

SteeringThere are 6 directions defined for the robot.

GO_LEFTThe left motor is stopped and the right motor goes forward. Robot pivots to the left on the left wheel.

GO_HARD_LEFTThe 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_RIGHTThe right motor goes reverse and the left motor goes forward. Robot turns in place to the right.

GO_RIGHTThe 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 LogicThe 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

Page 34: line follower robot using 8051 micro controller.doc

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/AAll other conditions, continue in the last direction determined. Line could be between sensors or there could be a problem.