Line Follower

A line follower is an autonomous bot that can follow a specific colored line painted on a surface of different contrast, such as white on black.

To start with first of all I will be discussing a small concept of light. I believe you all know that the light that strikes any platform is reflected. The reflection and absorption coefficient of light depend upon material, color of platform and other factors. In simple words the black surface absorbs the light and the white surface reflects it, this is the basic concept behind making a line follower.

Line Follower

So the line follower has an emitter and a reflector. The reflector receives the light and generates a voltage proportional to the intensity of the light, if this voltage is above a threshold it means SIGNAL=1 (logic one) else SIGNAL= 0 (logic zero).

Let’s take up an example where we have to move our bOt on black surface having white line. Suppose I have two Infra Red (IR) sensor pairs that are on different halves of a bOt with respect to geometrical central axis of the bOt. The sensors are placed in such a way that the white line lies in between both the sensors when the bOt is placed on the white track painted on black surface to move. Now if the white line is between both the sensors while moving forward both the sensors will be on black surface and the detectors/receivers will receive less amount of light since black absorbs light and hence signal provided by both the infra-red receivers will be low.

Line Follower explanation

Now if the heading/direction of the white line changes one of the sensors will move in the region of white line and will start giving output signal as high. This information can be used to ‘turn’ the bOt and orient itself in the right direction. For example in the above figure if the bot is located in position 1, then bOt will move forward and if the bOt is in position 2 it will have to turn left .

Let’s move on and discuss everything step by step in detail. We will be discussing the making of line follower under three heads:

  1. Chassis of robot { those familiar can skip this section}
  2. Electronics/Hardware Designing
  3. Programming/Software Designing

 

CHASSIS OF ROBOT

1. Base of robot: The base or the material of the platform of robot can be made with any easily available material like switch board, wood, acrylic sheet or steel sheet. As our robot will be very light, you don’t have to think a lot about strength and other such factors. We recommend you to make a small size and light weight bOt. Here we are using steel base:

Chassis of line follower

2. Motors and Driving Mechanism:

  • We will need a set of two motors that have same rpm (revolution per minute).
  • We will be using differential drive for maneuvering our bOt i.e. we will have three wheels for our bOt, the front two will be powered and the rear will be free wheel.
  • When the bot is moving straight both the motors should have equal speed.
  • For turning, one of the motor is switched off. If we switch off the left motor, the bot will turn left and vice versa.

 Line Follower motor

  • You can choose a motor of rpm around 100 and a torque of 1kg-cm

 MotorLine follower bOt 

 

3. Coupling wheels & clamping motors: For clamping the motors you can use pipe clamps or make right angled clamps. The right angle clamps ensure more rigidness. To couple the motor ensure that the shaft of motor and hole of wheel have equal diameter (if you can’t find one check the tutorial on wheels).

  Line follower clampingLine follower clamping 2

 

ELECTRONICS

Line follower flowchart

Below is a flow chart that explains the working of the bOt:-

The Infra Red sensors are used to interact with the environment. The emitter sends a ray which is received by detector in the form of voltage and it then amplified by amplifier since the signals are weak (more on this later). Below are the circuit diagrams of Infra-red LED emitter and receiver.

 

Line follower IR sensorLine follower IR receiver

 

 

Op-Amplifier (LM324)

If the rays received by the IR- LED receiver are above a particular threshold then an amplified signal is generated by the amplifier (LM324). Note that the sensors cannot directly send a signal to the microcontroller as the signal voltage generated by them is too low and even when sensors are on white surface signal generated by them will interpreted low by the microcontroller.

 Line Follower LM324

Microcontroller (AT89S52)

The microcontroller receives the signal and responds accordingly. It takes the decision based on input signal received by both the receiver LEDs. It will give command to motors through H-bridge to move forward, or take a left turn or a right turn.

H-bridge (L293B)

The microcontroller sends a signal to the H-bride that acts as a switch. If the signal received by the H-bridge is high it will rotate the motor or else it won’t do so. Note that microcontroller only sends a signal to a switch which gives the voltage required by the motor to rotate. Here we are using L293B which can be used to control two motors.

Pin connections for H-bridge:

  • En1 & En2 are given logic 1 from microcontroller or give 5V from outside and are used to activate/deactivate one ‘half’ of the H-bridge.
  • V is the voltage that you want to supply to the motor(s) : 9 or 12V
  • Vcc is the logic 1 or 5V

 

Line Follower motor circuit diagram

The complete circuit diagram with all the integrated circuits required for making a line follower is shown below:-

Line follower circuit

Here we are using pins P1.0 and P1.4 for taking inputs from the IR sensors after being amplified by LM324.

  • P1.0 – Input from left sensor
  • P1.4 – Input from right sensor

There are six outputs from AT89S52 microcontroller to the H-bridge.

  • Pins P0.0 and P0.4 are connected to enable pins of the H-bridge. We can use them to deactivate/active the two halves of H-bridge i.e. if pins are set to logic 1 the corresponding half of the H-bridge will be activated.
  • P0.1 – will drive the left motor in forward direction
  • P0.2 – will drive the left motor in reverse direction
  • P0.3 – will drive the right motor in forward direction
  • P0.5 – will drive the right motor in reverse direction

Programming

Below is the code in C for the line follower.

 

C Code                                             www.botskool.com

#include <AT89X52.h>

/*

                Sensors input port - P1

                  P1_0 --------> Left sensor

                  P1_4 --------> Right sensor

 

                 Motors output port - P0

                 

                  P0_0 --------> Enable pin of the left half of the H-bridge

                  P0_1 --------> will drive the left motor in forward direction

                  P0_2 --------> will drive the left motor in reverse direction

                  P0_3 --------> will drive the right motor in forward direction

                  P0_4 --------> Enable pin of the right half of the H-bridge

                  P0_5 --------> will drive the right motor in reverse direction

*/

 

 

/*Delay function runs an idle loop to create a time delay. If the crystal used is of 11.0592 MHz then the argument passed in delay is in 'milliseconds'.*/

void Delay(unsigned int itime)

{

                unsigned int i,j;

                for(i=0;i<itime;i++)

                                for(j=0;j<1275;j++);       //Idle loop

}

void Forward()

{

                P0_1=1;

                P0_2=0;

                P0_3=1;

                P0_5=0;

}

 

/*Generally for turning we use a pulsated wave so the bOt doesn’t get out of control i.e. we run the motor for sometime then again stop it and this is done very quickly to create an effective pulse. See the function below.*/

 

void TurnLeft()

{

                P0_1=0; /*Left motor is not running in any direction.*/

                P0_2=0;

                P0_3=1;   /*Right motor is running in forward direction. bOt will eventually turn left*/

                P0_5=0;

                Delay(50); /* Wait for 50 ms*/

                P0_1=0;  /*Motors are not running*/

                P0_2=0;

                P0_3=0;

                P0_5=0;

                Delay(50); /*Delay of another 50 ms*/

               

}

 

/*So in the above program we have effectively created a pulse of 100ms which is on for 50ms and off for another 50ms. You can change this value to suit your needs*/

 

/*Similarly we can write a function to turn right*/

 

void TurnRight()

{

                P0_1=1; /*Left motor running in forward direction.*/

                P0_2=0;

                P0_3=0; /*Right motor is not running.*/

                P0_5=0;

                Delay(50); /*50ms time delay*/

                P0_1=0; /*Motors not running in any direction*/

                P0_2=0;

                P0_3=0;

                P0_5=0;

                Delay(50); /*50ms time delay*/

               

}

 

 

void main()

{

/* The pins which are receiving inputs from the sensors should be initially set to logic 1.*/

                P1_0=1; /*Left sensor input*/

                P1_4=1; /*Right sensor input*/

                P0_0=1; /*Enable pin of the left half of the H-bridge*/

                P0_4=1;  /*Enable pin of the right half of the H-bridge*/


               

 

                //main loop of the program

                while(1)

                {

                                               

                                if((P1_0==0)&&(P1_4==1))

                                                TurnRight();

                                else if((P1_0==1)&&(P1_4==0))

                                                TurnLeft();

                                else

                                                Forward();

                               

                }

}

Download c program file - linefollower.c

Download hex file – linefollower.hex

Download AT89X52.h header file

 

Tags:

Comments

Member since:
21 February 2009
Last activity:
7 years 18 weeks

This thread has been locked. For discussions, queries and suggestions related to this tutorial kindly post it in our forum. Follow this link.  

Member since:
18 February 2009
Last activity:
1 year 25 weeks

Hi robofreak,

If I am correct you have SHORT-CIRCUITED the whole setup. See the picture below. 

Additional Remarks

Make sure that you are supplying 5V and not 9V to the input pins of L293D while giving dummy signals. 

Also DO NOT use LEDs for testing voltage of output pins since these output pins will have voltage of around 9V (greater than 5V) and LEDs should be used only where pins toggle between logic 1 (5V) and logic 0 (0 V). Instead connect motors directly to output pins.

While giving dummy signals give 5V to both the enable pins.

Regarding purchase of AT89S52 programmer follow this link.

Founder and Admin

Member since:
2 January 2010
Last activity:
7 years 27 weeks

Hi shashwat

 

The problm abt which i wrote on my last post has been solved nw and my motor driver circuit is now working fine.

Actually I was not grounding the other input terminals to give logic 0 to them (silly mistake) and was also connecting both the enable pins to Vcc. Now I have understood abt the enable pins that only tht side of enable is to set high from which we are taking output.

 

But do tell me abt the programmer thing for which i have written in my prev post at the end....

Member since:
2 January 2010
Last activity:
7 years 27 weeks

Hello shashwat

 

I tried to check functioning of motor driver circuit by giving dummy signals but it is not working. I replaced the L293D IC with new one and still it didn't worked.

 

I used two 9V batteries- one to give supply to 7805 and other to pin 8 of L293D and made their ground common i.e on the same breadboard. I connected each input pin to voltage supply separately one by one and checked the output. When i connected all the four outputs to four LEDs(with resistance connected to them), all of them glow irrespective of the pin to which I give input but two LEDs are dimmer than the other two.

Then I connected the outputs to the motor and on testing the circuit again nothing happened. I checked the input voltage(Vcc) coming from 7805 with multimeter and the voltage was approx 3.6V which I think is lower than the required voltage as I have read somewhere that voltage between 4-5V is considered as logic 1(whether its true or not i m nt sure) .

 

Another thing I am confused of is about the enable pins(pin1 and pin 9) of L293D. I know that they anable the left and right half of the half bridge but how they have to be set while giving dummy signals?

 

Here are some pictures of my circuit on breadboard-

 

output connected with motor - http://i49.tinypic.com/2cxgbxv.jpg

output connected with LEDs - http://i48.tinypic.com/23uo184.jpg              

 

My motors are absolutely fine and work properly if I directly connect them to the battery terminals.

 

One more thing, can u pls tell me where to buy a programmer for AT89S52. The one I had is not functioning properly. I dont want to buy it online so please tell me anywhere in delhi(lajpat rai market) and its price also. I dont want to make my own programmer as i have not worked with PCBs and soldering kind of stuff before.

Member since:
18 February 2009
Last activity:
1 year 25 weeks

Hi robofreak,

You are welcome.

You should definately replace your microcontroller.  

Founder and Admin

Member since:
2 January 2010
Last activity:
7 years 27 weeks

thnx shashwat, i will surely test each circuit separately. I have already checked sensor circuit and its working fine when there is complete darkness in room. When there is some light unexected things occur.

I am thikin about replacing microcontroller with a new one and then check its functioning as i have done some crazy things accidentially during experimentation like reversing the polarity in circuit by connecting wrong terminals of battery.

I'll get to u as soon as i check everything.

Member since:
18 February 2009
Last activity:
1 year 25 weeks

Hello robofreak,

Yes you WILL HAVE to make the grounds of both the power supplies COMMON i.e. connect them together, otherwise the circuit won't work. 

Also before assembling everything have you tested them (L293D, microcontroller and sensor circuit) separately?

If you haven't done so first test each of the above mentioned circuits independently before assembling them together. For example to test your L293D circuit try giving dummy signals 5V for logic 1 and 0V for logic 0 to pins 2, 7, 10, 14 and check whether the motors are moving accordingly. Similarly test your sensor and microcontroller circuit.

You should NOT use a multimeter for testing potential across microcontrollers pins since multimeter may damage your microcontroller. Instead use a LED with a resistance connected to it. Ground its one end and connect the other end to the microcontroller pin under inspection. With this arrangement in place again test your microcontroller. If there is no response try writing a more simple program (for example just provide logic 1 to any pin and see if it works) and burn it. If still there is no response from your microcontroller then replace it.

For more details regarding how to make LED circuit check out this tutorial - Building Electronic Circuits using Breadboard.

Founder and Admin

Member since:
2 January 2010
Last activity:
7 years 27 weeks

thnx shashwat for ur asisstance but u have not answered to my first question, it was - Suppose if I use another 9V battery and connect its positive terminal to the pin8 of l293d and negative to the ground of that very same breadboard, will it work?

 

and sry i mistakenly wrote microcontroller instead of multimeter.........the range set on multimeter was 20V.... and i tried the same experiment by burning the microcontroller two times but still the same result....i think may be there is some preoblem with the microcontroller....

 

will surely post the pic of my bot after i reassemble it and will post video also (if it worked ;) ).....

Member since:
18 February 2009
Last activity:
1 year 25 weeks

Hello robofreak, 

You have posted your doubts very clearly. Good work! Please do include a picture of your bOt in your next post.

Here are your answers - 

1. Pin 8 of L293D should be given that particular voltage on which you want to OPERATE YOUR MOTORS. See the rest of the circuit is working on 5V power supply. But you will obviously need to run your motors at a higher voltage (roughly around 9V - 12V or maybe even more) This particular voltage is supplied to the motors via 8th pin of L293D. So you should give pin 8 of L293D that voltage at which you want to run your motors.

2. You should ALWAYS AVOID joints in between since these joints make your circuit weak. Use a single/multistranded wire directly for the connection. And if you are forced to make such a connection which has a joint in between make sure you properly solder it to minimize power loss and ensure maximum conductivity.

3. Yes you can use a single power supply of 9V for driving both the circuits on different breadboards (if you are using a separate power supply for motors). It depends on power current rating of your battery.

Regarding your second post please clarify what do you mean by 'The range set on microcontroller was 20V.'? 

Founder and Admin

Member since:
2 January 2010
Last activity:
7 years 27 weeks

one more thing, after the burning the program on microcontroller i tried to give it dummy signal on breadbard and tested the output with multimeter.

On giving 5V to P1.0 the output voltages were P0.1-0V,P0.2-0.01V,P0.3-0V,P0.5-0.01V . On giving 5V to P1.4 the output volatges were all 0V. The range set on microcontroller was 20V.

Can u pls explain the reason why it is happening. I have made complete circuit with 11.0592 crystal and power-on reset circuit.