HOW TO : Make an edge avoider Bot using ATmega8

post footer border
Edge avoider bot is one of the most popular project in students. As the name suggests, it makes the Bot to avoid the deep edges of the platform and save the bot to not fall from the platform.


For some it is  not other than the miracle of engineering and on the other hand for some it is just a couple of lines of coding.

Here we are using atmega 8 for edge avoider Bot. It is as similar to line follower bot with minute changes.

Here we are using IR sensors as the eyes of the Bot. In this project we are using two IR sensors. Here IR sensor will work as similar to switches.

CODE :


#define F_CPU 1000000UL     //set MCU clock speed
#include <avr/io.h>
#include <util/delay.h>


int move_backward=0b00000110;
int right_turn=0b00001010;
int move_fordward=0b00001001;
int left_turn=0b00000101;
int left_sensor_on=0b0010000;
int right_sensor_on=0b0100000;
int left_sensor_off=0b0000000;
int right_sensor_off=0b0000000;


void wait(float x)
{
for(int i=0;i<(int)(x*1302);i++)
_delay_loop_1(0);
}



int main (void)
{


DDRB = 0xFF; //Output port
DDRC = 0b0000000; //input port

  int left_sensor = 0;
  int right_sensor = 0;



while(1)   //create an infinite loop
{

 left_sensor = (PINC & 0b0010000);
 right_sensor = (PINC & 0b0100000);
    if(( left_sensor==left_sensor_off) & (right_sensor==right_sensor_off))
  {
PORTB = move_backward;     //move backward
wait(1.5);
PORTB=right_turn;           //take a right turn
wait(.5);

    }
if((left_sensor==left_sensor_on) & (right_sensor==right_sensor_on))
  {
         PORTB=move_fordward;        //move forward


      if(( left_sensor==left_sensor_off) & (right_sensor==right_sensor_on))
  {
     PORTB=move_backward;
 wait(1.5);
 PORTB=right_turn;
 wait(.5);

  }
 
 if(( left_sensor==left_sensor_on) & (right_sensor==right_sensor_off))
  {
    PORTB=move_backward;
 wait(1.5);
 PORTB=left_turn;
 wait(.5);

  }
       
}

}

In this project we are using two servo motors. 

// you can download the complete project file ( including .hex , c ) from below







Recent Posts