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
}
}
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
}
}
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
}
}