Edge Avoiding Robot

Edge Avoiding Robot using ATMega8 Microcontroller.
Edge avoiding Robot works based on the line detecting IR Infrared Ray LED and Photodiode module. 2 sensors are connected in front of my robot, that detects the edge when running in the forward direction. When runs forward 2 sensors are active that is sense the surface, when comes to the edge the sensor goes outoff the table. So that time sensors are active low and motor takes backward direction the some delay moves left side.
BLOC DIAGRAM OF EDGE AVOIDER ROBOT
Edge Avoiding Robot
CONDITION OF SENSORS AND MOTOR OPERATION

LEFT SENSORRIGHT SENSORMOTOR OPERATION
ONONMoves forward
OFFONBackward
Delay
Right Turn
ONOFFBackward
Delay
Left Turn
OFFOFFBackward
Delay
Right Turn

MOTOR DRIVE CIRCUIT
Motor drive circuit is used to ON / OFF the LEFT AND RIGHT MOTORS of the robot to provide the above mentioned sensor conditions.
Main program.
#define F_CPU 12000000UL
#include<avr/io.h>
#include<util/delay.h>
void wait(float sec);
void wait(float sec)

{
for(int i=0;i<(int)46*sec;i++)
_delay_loop_2(0);
}

int main(void)
{

DDRC=0x00; //set input port
DDRB=0x0F; //PB0, PB1, PB2, PB3 as output port for motor drive
int ls=0, rs=0;

while(1) // infinite loop
{

rs=(PINC&0x01);
ls=(PINC&0x04);

if((rs==0x00)&&(ls==0x00)) // Both sensor OFF
{

PORTB=0x00; //stop
PORTB=0x09; //backward
wait(.8);
PORTB=0x02; //turn right
wait(.8);

}

if((rs==0x01)&&(ls==0x00)) // left sensor=ON and right sensor=OFF

{

PORTB=0x09; //backward
wait(.8);
PORTB=04; //turn right to avoid the edge
wait(.8);

}

if((rs==0x00)&&(ls==0x08)) // left sensor=OFF and right sensor=ON
{

PORTB=0x09; //backward
wait(.8);
PORTB=0x02; //turn left to avoid the edge
wait(.8);

}

if((rs==0x01)&&(ls==0x08)) //check sensor status for both sensor ON
{

PORTB=0-06; //move forward

}

}

}

Leave a Reply

Your email address will not be published. Required fields are marked *