i want to make line follower robot,i have control speed of single motor.i want to know what changes needed to control two motors and which snesor i should use IR, LDR or photodiode.
#include<avr/io.h>
#include<util/delay.h>
#define s5 200 // s for speed
#define s4 150
#define s3 100
#define s2 50
#define s1 20
#define s0 0
#define forward 0b00000010
#define reverse 0b00000001
#define right 0b00011010
#define left 0b00010110
#define stop 0b00001111
void move(char speed,char direc)
{
OCR0=speed;
PORTA=direc;
}
void main()
{
///////////I/O Ports setup///////////////
DDRC=0b00000000; //PORTC for PORTC input
PORTC=0x00; //Internal pullup enable
DDRA=0xff; //PA0 & PA1 for right motor control
//PORTA=0x00; //PA2 & PA3 for left motor direction
///////////Setting up Timers/////////////
TCCR0 = 0b01101100; //Fast PWM, Output at OC0
/////////// Variable declarations ///////
char prev=0x00;
/////////// Mian Loop ///////////////////
while(1)
{
if(1)
{
if((PINC & 0xf0)== 0b00000000)
{
move(s5,forward);
}
else if((PINC & 0xf0 )== 0b00010000 )
{
move(s5,left);
}
else if((PINC & 0xf0 )== 0b00100000)
{
move(s3,left);
}
else if((PINC & 0xf0) == 0b00110000)
{
move(s3,left);
}
else if((PINC& 0xf0 )== 0b01000000)
{
move(s3,right);
}
else if((PINC & 0xf0) == 0b01010000)
{
move(s3,right);
}
else if((PINC & 0xf0 )== 0b01100000)
{
move(s3,reverse);
_delay_ms(2000);
}
else if((PINC & 0xf0 )== 0b01110000)
{
move(s3,reverse);
_delay_ms(2000);
}
else if((PINC & 0xf0 )== 0b10000000)
{
move(s5,right);
}
else if((PINC & 0xf0 )== 0b10010000)
{
move(s3,forward);
}
else if((PINC & 0xf0 )== 0b10100000)
{
move(s3,right);
}
else if((PINC & 0xf0)== 0b10110000)
{
move(s3,left);
}
else if((PINC & 0xf0)== 0b11000000)
{
move(s3,right);
}
else if((PINC & 0xf0)== 0b11010000)
{
move(s3,right);
}
else if((PINC & 0xf0)== 0b11100000)
{
move(s3,right);
}
else if((PINC & 0xf0)== 0b11110000)
{
move(s5,reverse);
_delay_ms(3000);
}
}
}
}
thanx for reply.......