Friday, 16 September 2016

LINE_FOLLOWER

LINE_FOLLOWER:


Code:



#include<avr/io.h>
#define F_CPU 8000000ul
#include<util/delay.h>

void main()
{
DDRD=0b00000000;   //set PORTC as input port
DDRC=0b00111100;  //PB1, PB2, PB3, PB4 as output port
int ls=0, rs=0;   // define & initialize ls, rs integer as 0 to
// acquire the left sensor status in ls and right sensor
// status in rs
PORTD=0XFF;
while(1)          // create infinite loop
{
ls=(PIND&0b0000001);   //acquire only left sensor status connected at PC0
rs=(PIND&0b0000010);   // acquire only right sensor status connected at PC3

if((ls==0b0000000)&(rs==0b0000000)) //check sensor status for both sensor OFF
{
PORTC=0b00000000;  //stop
_delay_ms(1000);
PORTC=0b00101000;
_delay_ms(500);
PORTC=0b00000100;
_delay_ms(500);
ls=0;              //set sensor status off
rs=0;              //set sensor status off
}

else if((ls==0b0000001)&(rs==0b0000000))  //check sensor status for left sensor=ON and
// right sensor=OFF
{

PORTC=0b00000000;
_delay_ms(200);
PORTC=0b00101000;
_delay_ms(500);
PORTC=0b00000100;    //turn right
_delay_ms(400);
ls=0;                //set sensor status off
rs=0;                //set sensor status off
}

else if((ls==0b0000000)&(rs==0b00000010))  //check sensor status for left sensor=OFF and
// right sensor=ON
{
PORTC=0b00000000;
_delay_ms(200);
PORTC=0b00101000;
_delay_ms(500);
PORTC=0b00010000;   //turn left
_delay_ms(400);
ls=0;               //set sensor status off
rs=0;               //set sensor status off
}

else if((ls==0b0000001)&(rs==0b0000010)) //check sensor status for both sensor ON
{
PORTC=0b00010100;  //move forward
ls=0;              //set sensor status off
rs=0;              //set sensor status off
}
}
}



Simulation:







0 comments:

Post a Comment

if you have any doubt please let me know