Thursday 5 July 2012

ATmega8 based line follower robot

This project is a microcontroller based line follower robot by using ATmega8 development board from "ROBOGENISIS". This development board consists of an on board USB programmer, motor driver and some other peripherals like LEDs, buzzers. This board is best for beginners.This can be programed using WinAVR,programers notepad.


ATmega8 microcontroller consist 3 ports:
  •    PORTB an 8 bit I/O port
  •    PORTC a 7 bit I/O port .But pin PORTC.6 is also RESET pin for the MCU so it cannot be used for input but remaining 6 pins can be used as inputs.
  •    PORTD an 8 bit I/O port
  In this board the ATmega8 works at 12 MHz crystal.
An on board L293D is used for driving motors. Separate power supply is provided motor driver and logic supply for MCU. Motor driver control pins are internally connected to the higher nibble (D7, D6, D5, and D4) pins of PORTD.

To get familier with basics of line follower click here.

I connected the sensors to PORTC lower 2 pins left sensor to C1 & right one to C0. Connect two motors to the motor output ports.



 CODE:


#include<avr/io.h>
#define F_CPU 12000000
#include<util/delay.h>
void main()
{
  DDRC=0xc0;//input for sensors make sure that all sensors are active high
                                        //( high    for wight)
  PORTC=0xff;//internal pull up
  DDRD=0xff;//motor control pins
  PORTD=0x00;//motor halt
  unsigned char sensor;
 while(1)
 {
     sensor=PINC & 0x03;//masking for lower 2 bits
       if(sensor==0x03)// both are on white
   PORTD=0xaa;//forward
  else if(sensor==0x01)//left sensor on black line
   PORTD=0x66;//left turn
  else if(sensor==0x02)//right sensor on black line
   PORTD=0x99;//right turn
  else
   PORTD=0x00;//robot stop
  
 }
}



similarly for 8051 the code will be:


#include<reg51.h>

void main()
{
  P1=0xff;//input for sensors make sure that all sensors are active high ( high    for  Wight)
  //sensors are connected to lower two pins                                    
//in 8051 to make a port input you need to write one's to the respected pins
  unsigned char sensor;
//assume that motor control pins are connected to either upper or lower 4 bits of PORT2
 while(1)
 {
       sensor=P1&0x03;
       if(sensor==0x03)// both are on white
  P2=0xaa;//forward
  else if(sensor==0x01)//left sensor on black line
    P2 =0x66;//left turn
  else if(sensor==0x02)//right sensor on black line
    P2 =0x99;//right turn
  else
    P2 =0x00;//robot stop

 }
}



41 comments:

Unknown said...

i saw ur projucts and ur full profile, very well sir, i like u sir, sir i like robotics projuct and i have lot of interest in robotics but everybody not help to him ,, plz send me simple programs to me ..

Unknown said...

thank u ir,,

IGDEV said...

sir m ece student n love to do work on bots. m tryng for line follower bot with atmege8 my bot cn easily take sharp turn of 90deg bt cn not work on N shape track please help me out sr for this...n tell me about placemnt of sensors

VAMSI DANDA said...

instead of a straight line arrange them in inverted "V" shape
---||---
-||--||-
||----||

Pave said...

hi sir... its well explained...
i just need to know how to increase the speed of the motor

VAMSI DANDA said...

only one way to increase the speed
go for high speed motors instead of geared motors
use PWM to stabilize the speed

Unknown said...

Sir in your coding what is the use of thestatement #define f_CPU 12000000

VAMSI DANDA said...

the delay.h header file calibrates the _delay_ms functions according to the crystal frequency at which the mcu is working
so to tell the compiler that im using 12Mhz crystal
im using the statement
#define f_CPU 12000000 (12Mhz=12000000hz)

F_CPU is a "macro" that holds the crystal frequency value
by default the value will be 1Mhz

to achieve perfect delay you have to redefine this as per your crystal value

Milind said...

Hello Sir.,

What if I want to use AT89C51 in place of ATmega8 and what will be change in Program.?

VAMSI DANDA said...

check the 8051 code above....

Unknown said...

Hello sir,
pls could you you help me with the avr code for grid following bot with 3 sensors for atmega 8 mcu

Unknown said...
This comment has been removed by the author.
Unknown said...

hello sir,
pls can u help undrstanding two lines of ur coding written below...
PORTD=0xaa;//forward
else if(sensor==0x01)
PORTD=0x66;//left turn
else if(sensor==0x02)

Unknown said...

could you send me the code for five sensor's we are using Atmega8 we are finding probem while interfacing the bot.The IC is taking the input properly but the output is not coming properly.That's why I am asking you the whole code for five sensors.Please If you can send us the whole code It would really helpful for us.
Because after that we would make necessary changes in our code.Please send us at ajay.dusa@gmail.com

Anonymous said...

sir

I followed your instructions and i made my 1st line following robot
but am facing a problem that my robot is going round and round in circles.
Wheels rotating in opposite directions. I didnt know where i went wrong.
Please help me regarding this.

VAMSI DANDA said...

check your sensor sensitivity to ambient light and try re calibrate them

Unknown said...

sir can u please send us the code for line follower with three sensors. we are having a problem.left and right sensors are on white surface and center sensor is on black surface. the problem is that is starts well but it stops while turning.
it will be very helpful if you could help us with this problem and send us code.
email-id : shivanggupta.srg@gmail.com

Unknown said...

please kindly provide the video for assembling the circuit...!!

VAMSI DANDA said...

hello ayush
without proper details of the project how one can help you send me your code also i will check it out mail me at: vaabrobotics@gmail.com

hello pooja before this atmega8 based line follower there is a basic line follower project article in this blog. check that out for more info

Unknown said...

Sir, i want complete program for automatic line follower robot.Is this above?Sir another question which software i have to use?

VAMSI DANDA said...

yes the above code is for line follower with two sensors. it is for winavr software.

Unknown said...

Plss send me a link to buy this atmega8 board installed with all things and plss send a way how to program the codes on to the board

Unknown said...

sir please write the code for line follower usimg pid

Unknown said...

sir please write the code for line follower using pid for winavr software

Unknown said...

hello sir,
can you please help me in writing a c code for a grid follower bot.
i am using ATMEGA 8 board with 3 ir sensors.
"need a sample grid follower code for hint"

Unknown said...

/* Line Follower: code for LOOP*/
#include
#include
#include
#include
#define val 700

int l,r,m;
void main()
{
static int x;
x=9;
DDRA=0x00;
DDRD=0xff;
ADCinit();
_delay_ms(100);
//PORTD=9;

while(1)
{
l=read_adc(2); //to read the quantizised value
r=read_adc(0);
m=read_adc(1);


if((r>val)&&(mval)) // Move foward(010)
{
PORTD=0b00001001;
x=9;
}

else if(((rval))||((rval)&&(l>val))) // Turn right (011)(001)
{
PORTD=0b00001010;
x=10;
}

else if(((r>val)&&(mval)&&(m>val)&&(lval)&&(l<val))) // Priority right at T and Y junctions (111)(101)
{
PORTD=0b00000101;
x=5;
}

else // Move back(000)
PORTD=x;
}

}

Unknown said...

chandransh that's my code alright. U've to change the adc_lib as per your requirement

Unknown said...

chandransh that's my code alright. U've to change the adc_lib as per your requirement

Unknown said...

/* Line Follower: code for LOOP*/
#include
#include
#include
#include
#define val 700

int l,r,m;
void main()
{
static int x;
x=9;
DDRA=0x00;
DDRD=0xff;
ADCinit();
_delay_ms(100);
//PORTD=9;

while(1)
{
l=read_adc(2); //to read the quantizised value
r=read_adc(0);
m=read_adc(1);


if((r>val)&&(mval)) // Move foward(010)
{
PORTD=0b00001001;
x=9;
}

else if(((rval))||((rval)&&(l>val))) // Turn right (011)(001)
{
PORTD=0b00001010;
x=10;
}

else if(((r>val)&&(mval)&&(m>val)&&(lval)&&(l<val))) // Priority right at T and Y junctions (111)(101)
{
PORTD=0b00000101;
x=5;
}

else // Move back(000)
PORTD=x;
}

}

Find my things said...

sir can i have a line follower codeing for atmega8 using two sensors ??

Find my things said...

i think you have posted many code but i could get that which code is for atmega8 ...so pls assist me sir

kalyan119 said...

I want to make a high speed lfr using 5sensor array nd pid control..
I'm having trouble wid the code
Can u help me wid that
My mail is kalyan.sri.d@gmail.com

shravs said...

sir can u plz send me the code for clap controlled robot using atmega8

Shivaleela Shastri said...

I've made a track of black tape, and I've introduced 2 horizontal lines for the not to stop.
What should I code, if I wanted to make the robot stop at the second black line and not the first line? What changes can I make in the code.
Please reply.

VAMSI DANDA said...

Hello shravs. You are asking code for clap sensor. I am not God to guess which sensor model your using. To which pins you connected it to mcu. I don't know why people don't understand this.Before asking code there is 0% chance that any one can help you with such details.I hope you got my point

VAMSI DANDA said...

Make a counter variable And increment it on detection of line. And also make a proper denouncing For sensor Like it may get increment faster and more than once at a time use some. delays over like forward until bot cross The line. All the best

Unknown said...

please can any one explain me the portion of "while(1)".

Unknown said...

Can anyone help me and send source code for a white line follower

Unknown said...

guys can any one send me what are the possible output that we can bring in Line Follower Robot

Aabhas Asit Senapati said...

You can change resistor value so it's sensitivity changes or you can change code that if it doesn't sense it will move but when it senses it will take a turn

Unknown said...

Sir , i want a clear connection diagram for line follower robot as i am new to this...... please help me sir

Post a Comment