Tuesday, January 14, 2014

Line Tracking Robot using AT89s52

Previously, we discussed on line tracking robot without using microcontroller. Today, we will be building a simple line tracking robot which uses AT89s52 microcontroller that acts as control unit to provide decision to the robot. This following robot will also be able to detect cross or junction in the track.

Line following robot is an automatic machine which follows a line with light colors marked on dark surfaces. The decision which is required while tracking the line is provided by the microcontroller. Here, I will describe a technique to build a line tracking robot which follows a white track made on a black surface surrounding it. Now, we will begin with the block diagram of this machine which is shown below.

The block diagram of line tracking robot
fig a:- Block diagram of line tracking robot


Sensors:-

Optical sensor used in line tracking robot
Fig b:- sensor used in line tracking
robot
Optical sensors which uses principle of reflection of light are used. LDR, photosensor and photodiode can be used to make this sensor but here we will be using LDR because it will be easy to understand for beginners in robotics.The schematic of sensor used is shown in the figure b which consists of transmitter and receiver. The transmitter consists of LED which emitts light and the receiver consists of LDR where when the reflected light from the white line strikes. Since the intensity of light that LED must emit depends on the height of sensor from the ground, the value of R1 is choosen by hit and trail method as per our need. The value of R2 used is 10K. 
 When the sensor is in black surface, no light is reflected back to strike the surface of LDR. Hence the value of resistance is large which results in negligible voltage at node B i,e Vs.When this sensor is above white surface, the light emitted by LED is reflected back by white surface to strike the surface of LDR. This causes the resistance of LDR to drop and which in turn increases the voltage obtained at node B i,e Vs.

Signal Conditioning:-

Voltage obtained from sensor is analog which is converted to digital form by using the comparator LM324. The signal obtained from the sensor is fed to one input of comparaor and another input is adjusted to threshold voltage(voltage which can differentiate white and black surface clearly).

Control Unit Interface:-

In most of automatic robots, decision device or control unit contains microcontroller which provides decision based on the result after processing the signals obtained from the sensors. In this case where we are not using microcontroller, the output from signal conditioning section can be used as control unit.

Motor drivers and Motors:-

Motors act as actuator. Motors along with attached wheel helps robot to move from one position to another. Relays and transistors are most commonly used motor driver but in this case we will be using L293D motor driver ICs.
An isolating circuit will be best to use between motor drivers and control unit interface.Use of Relays, optoisolator (optocoupler) and using two different voltage source are different ways to isolate control unit circuit from motor driving circuit.

Note:-If you are willing to learn, its important you study the datasheets of components you are using. So, see datasheets of L293D,LM324,AT89s52 before preceding.

Schematic:-

A schematic used in simple line tracking robot
Fig C:- Shematic of simple line tracking robot


Working:-

A track which a robot needs to follow
Fig D:- track to follow by robot
To design a simple line tracking robot which is able to detect a cross or a junction, a minimum of three sensor is required. Lets label these three sensor as right sensor, left sensor and a middle sensor. The microcontroller which is used as decision device is programmed to follow the track if the middle sensor is just above the white track. when the right sensor is above the track it is programmed to turn left and if left sensor is above the track it is programmed to turn right.By programming the microcontroller as told above, we can build a simple line tracking robot but what is a robot is supposed to do if all the three sensors are just above the track(in cross of the track as shown in figure d). In this case, the robot can be programmed to stop or to count the cross and turn right or left by taking the number of count as a reference or you can program it as your will or according to the situation.
For eg:- Suppose a robot is at position A initially. Now, if the robot is required to stop at cross "G", then the controller can be programmed that moves the robot in forward direction untill the count is 2 and then turn left and stop when the count is 1. 


 The prototype of the function which can be used to track the line is below. 



void linetrack()

{
if(sr==0 && sm==1 && sl==0)
     out= bothfrwad;
else if(sr==1 && sm==0 && sl==0)
     out= leftforwad & rightreverse;
else if(sr==0 && sm==0 && sl==1)
     out= leftreverse & rightforward;
}

In the routine above sr, sl and sm refers to right sensor, left sensor and middle sensor respectively.
For the schematic shown in figure c, out refers to port 2 of microcontroller. The binary value for robots to move forward and reverse can be computed by inspecting the schematic.
For eg if we want both the motor to rotate in forward direction (or a robot to move forward) then the binary value to send through port 2 will be 0100 0001=0x41 (representing in hex).
Similarly,
For leftforward binary value is 0100 0000=0x40
For rightforward binary value is 0000 0001=0x01
For leftreverse binary value is 1000 0000=0x80
For rightreverse binary value is 0000 0010=0x02

Note:- In the above schematic, I have not used isolating circuit between microcontroller and motor driver. You better use isolating circuit between these two while testing your line tracking robot.

In the routine shown above , only three status of sensor are used(when middle sensor, left sensor and right sensor are at logic 1). A situation when right sensor and middle sensor are at logic 1 level may also arise or a situation when left sensor and middle sensor are at logic 1 level may arise.So better use all combinations (status) while writing the routine of line tracking. Also the more sensor you use, more precise your robot will be.

You  may also like:
PWM using AT89s52
Line tracking robot without using microcontroller

2 comments:

Unknown said...

Yp.....useful for hobbyist...

Bikal Adhikari said...

Niceeeeeeeeeeeeee.....................