line follower program doubt
I have a doubt in the program given on this website -
#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*/
//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();
}
}
Here the output pins of 89s52, P0_0 and P0_4 are connected to enable pins of l293d which should be set to logic 1 in order to drive the left and right half of the l293d.
Then why they are not being set to logic 1 anywhere in the program?? I dont think the mcu will automatically give 5V output to these pins and without giving 5V to these pins the motors will not work.


Hi pratik20990,
Yes you need to set pins P0_0 and P0_4 to logic 1. It has not been done so in this program because while making the line follower we had given the logic 1 to enable pins of L293D externally. But yes it should be there. Thanks a lot!
is it necessary to give power frm one power source<7805>or three...1 for sensors one for comparator...and last for the microcontroller will work ...coz i m getting a voltage drop...
@sujit
You should preferably use single 7805 to give power supplies to all the modules. All the modules - sensor, comparator,microcontroller and motor driver are interconnected, so they must have their grounds common. Moreover, its easier to give power from battery to a single 7805 than to multiple 7805s.
About voltage drop try following things-
1. Check if your 7805 is working correctly - connect the black lead of multimeter on the middle pin(ground)and red lead on right most pin(ouput) of 7805 while the circuit is on. You should get a reading of 5V.
2. The voltage drop u r telling, if it is on breadboard then try the circuit on pcb board. If u r already using pcb board then try shortening the length of the connecting wires u have used. Properly solder the connections and make sure there is no loose connection.
3. Do not create too many individual modules like one for sensors, other for comparator,and so on for mcu and motor driver too(especially on breadboard). Just create two individual modules- one for mcu and motor driver and other for sensors and comparator and then see if it works.
3. Try using the main power source(battery or any other) of high current ratings and voltage of minimum 9V or 12V.
4. Make sure the circuit is correct. You can probably post your circuit here to check if its correct or not.
thanks for the rply :)
i get the voltage drop when i connect the sensors to the comparator and give the power frm the same source.
the LED(white) to check the output of the comparator fades away as time passes(not more than 2 min).
else other circuits are workin fine.
i dont have any means to upload the circuit pic now.i'll be doing it tomorrow.
pls suggest possible errors :)
thanks again
@sujit
ensure that you are making the led circuit correctly by adding a resistor of suitable value in series with it as described here -
http://www.botskool.com/tutorials/electronics/general-electronics/buildi...
u have not told tht whether u r making the circuit on breadboard or pcb board. do include a pic of your circuit in ur next post.
can any one tell me how to make line follower if the track consist of loops,what ciruit is to be modified and programming..plllzzzzzzzz help me out..
hi ... this is vandy... i was trying to write a code for an 8 sensored bot in c lanuage...
can u temme if the following logic n the program is correct n wud possibly work........!!!
plz... im really in gr8 need of help//!
logic: consider centre condition 00011000 when the bot is on the centre of the line.. converting this to decimal gives 24.
at any instant of time, the readings from ports are converted to decimal using convert() and stored in x. the error e=centre condition - instantaneous value(x)
when the line moves right.. error becomes positive
when it moves left.. the error is negative
the motors are run in right or left accordingly to steer in a direction in order to reduce the error to 0 n thus reach the centre of the line
anticonvert() fn. is used inorder to equalise the time taken to reach centre condition since error is greater due to the msb bits of the input sensors
the value of extreme sensors are checked and if high.. the bot moves hard right or hard left
#include<reg51.h>
#include<math.h>
unsigned int convert()
{
unsigned int p,q=0,j;
for(j=0;j<8;j++)
{
p=pow(2,j) * (P1^j);
q=q+p;
}
return q;
}
unsigned int anticonvert()
{
unsigned int p,q=0,j,l=7;
for(j=0;j<8;j++)
{
if(l>=0)
{
p=pow(2,j) * (P1^l);
q=q+p;
l--;
}
}
return q;
}
void main()
{
unsigned int centre=24,i;
unsigned long int x,y;
int e;
P1=0xFF;
P3=0x00;
while(1)
{
x=convert();
y=anticonvert();
e=centre-x;
while(e==0)
{
P3=0x0A;
}
while(e>0)
{
if(P1^0==1)
P3=0x09;
else
{
for(i=x;i<centre;i++)
P3=0x08;
}
}
while(e<0)
{
if(P1^7==1)
P3=0x06;
else
{
for(i=y;i<centre;i++)
P3=0x02;
}
}
}
}
plzzzzzzzz i request for help to debug and simulate it and check if the port values are working correctly..
hi
I'm impressed, you are actually working on 8 bit IR line follower.. kindly add comments after each motion instruction so that one can understand your code better.. and before writing your code do make a rough flow chart it helps in debugging ..
>> avoid using too many while loops, better use if(s) think over it..
or make functions like turnright() , turnleft(), forward(), etc..to make your code look better and easy for debugging..
>>put condition e==0 as e<=5 or e<=10 .. coz the performance is definitely going to be non-ideal.. change its value which would help you tune the bot's performance..
good effort! keep posting your doubts!
Hi vandy,
I have gone through your logic and yes your logic is correct. Have you simulated your program in Keil IDE?
Hi styrobo,
You need to have an array of 6 - 8 sensors in front of the robot to detect crossovers and loops. You need to continuously calculate the average of the measured values from the line sensor. In the case of a crossover the average value will increase by a significant amount.
@shashwat
i m using 24V 200rpm motors and circuit and programming is same as on this website. The circuit works fine but after some time the motors stop working or one motor works and other does not. One more thing I have to again and again press the reset button to make motors work. The motors are otherwise perfectly fine and run properly when directly connected to battery terminals. Is back emf related to this? Should I use filters across motors and across power supply?
Hi pratik20990,
Yes most probably this is related to back emf. First of all comment out the delay() function used in the program and recompile your code and reprogram your microcontroller just to make sure that delay function is not interfering with normal functioning of the motor. Try this out.
@shashwat
If it is due to back emf then what can be done to prevent it?? as I want to use the delay function in the program.
I have found some circuits showing filters connected across motors and pin8 of l293d. Are they used for preventing back emf?
i want your help in minor prjct
inelec and comm branh
cn you help me
Hi pratik20990,
Its ok if you want to use delay in your program. I was just asking you to cross-check whether the motors are working fine without using delay() function. Did you check this out?
Yes filter circuits are used to prevent back emf. Capacitors are placed in circuit along with motors. I will give you the circuit diagram soon. First check your motors without delay function.
Hi rathik_2552,
Please post in detail what are you trying to develop as your minor project and what problem are you facing in it?