Tuesday, November 6, 2012

How to make a line follower robot using 8051 micro controller - P89V51RD2

Introduction

This is an old tutorial..Click here to read the new version of this tutorial HERE

 

  

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 Kurukshetra’08 (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 LED’s 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
Let’s 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 having-
Inverting (negative) Input (-),Non-Inverting (positive) Input(+), Vcc,
Ground, Output.
Let’s 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
software’s 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.
Let’s check how it works

1 comment:

  1. thank for the code! its really helpful. very clean and neat explanation

    ReplyDelete

You might also like