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:

  1. 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 ..

    ReplyDelete
  2. 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

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

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

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

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

    ReplyDelete
  7. 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

    ReplyDelete
  8. Hello Sir.,

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

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

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. 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)

    ReplyDelete
  12. 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

    ReplyDelete
  13. 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.

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

    ReplyDelete
  15. 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

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

    ReplyDelete
  17. 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

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

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

    ReplyDelete
  20. 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

    ReplyDelete
  21. sir please write the code for line follower usimg pid

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

    ReplyDelete
  23. 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"

    ReplyDelete
  24. /* 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;
    }

    }

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

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

    ReplyDelete
  27. /* 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;
    }

    }

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

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

    ReplyDelete
  30. 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

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

    ReplyDelete
    Replies
    1. 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

      Delete
  32. 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.

    ReplyDelete
    Replies
    1. 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

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

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

    ReplyDelete
    Replies
    1. 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

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

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

    ReplyDelete