here is a simple and accurate line follower circuit along with c code for at89c2051
The above circuit is the pair of irled and photo diode to detect the line
CODE
#include
sbit sen1 = P3^1;
sbit sen2 = P3^2;
sbit mot1f = P1^2;
sbit mot2f = P1^3;
sbit en1=P1^0;
sbit en2=P1^1;
void delay_ms(unsigned int);
void main()
{
en1=1;
en2=1;
while(1)
{
if(sen1==0&&sen2==0)
{
mot1f = 1;
mot2f = 1;
delay_ms(10);
}
else if(sen1==1)
{
mot1f = 0;
mot2f = 1;
delay_ms(100);
mot1f = 1;
mot2f = 1;
delay_ms(10);
}
else if(sen2==1)
{
mot1f = 1;
mot2f = 0;
delay_ms(100);
mot1f = 1;
mot2f = 1;
delay_ms(10);
}
if(sen1==1&&sen2==1)
{
mot1f = 0;
mot2f = 0;
delay_ms(100);
mot1f = 1;
mot2f = 1;
delay_ms(10);
}
}
}
void delay_ms(unsigned int i)
{
unsigned int j;
while(i-->0)
for(j=0;j<500;j++);
}