Вы находитесь на странице: 1из 6

LINE FOLLOWER ROBOT

Simple line follower(black):Code-----/* Program for "Black Line Follower Robot"


Connection settings of the Kit
Pins of IR sensor is connected with the PortA of the MCU
Left Sensor -----> PA4
Right Sensor-----> PA5
Left Motor -----> PB0,PB1
Right Motor -----> PB2,PB3
BOOTLooder Condition Check--->PA0(If 0 bootler section else program execution
section of Flash memory)
Crystal Oscillator(12MHz)----->XTAL1,XTAL2
VB=Battery Supply
VCC=regulated 5V+
Gnd=Ground(0V)
*/
#define F_CPU 12000000UL // define MCU Clock speed
#include <avr/io.h>
// include avr header file
#include <util/delay.h> // include delay header file
int main(void)
{
DDRA=0b00000000;
DDRB=0b11111111;
motors

// main function
// declare PortA as a input port connected to the sensors
// declare PortB as a output port connected to the

int left_sensor=0, right_sensor=0;


while(1) // infinite loop
{
left_sensor=PINA&0b00010000; // mask PA4 bit of Port A
right_sensor=PINA&0b00100000; // mask PA5 bit of Port A

if((left_sensor==0b00000000) && (right_sensor==0b00000000))


sensors "off"
{
PORTB=0b00000000; // stop
}
if((left_sensor==0b00010000) && (right_sensor==0b00100000))
sensors "on"
{
PORTB=0b00001001; // move straight
}

// if both

// if both

if((left_sensor==0b00000000) && (right_sensor==0b00100000))


left sensor off but right sensor on
{
PORTB=0b00000001; // turn left
}
if((left_sensor==0b00010000)&(right_sensor==0b00000000)) ////if left
sensor on but right sensor off
{
PORTB=0b00001000; // turn right
}
}
}

// if

Led glows on the sensor=> sensor if off => 0b00000000

Unidirectional line follower-----Code:-

/* Program for "Black Line Follower Robot"


Connection settings of the Kit
Pins of IR sensor is connected with the PortA of the MCU
Left Sensor -----> PA4
Right Sensor-----> PA5
Left Motor -----> PB0,PB1
Right Motor -----> PB2,PB3
BOOTLooder Condition Check--->PA0(If 0 bootler section else program execution
section of Flash memory)
Crystal Ossilator(12MHz)----->XTAL1,XTAL2
VB=Battery Supply
VCC=regulated 5V+
Gnd=Ground(0V)
*/
#define F_CPU 12000000UL // define MCU Clock speed
#include <avr/io.h>
// include avr header file
#include <util/delay.h> // include delay header file
void wait(float x)
// wait function
{
for(int i=0;i<(int)(x*46);i++)
_delay_loop_2(0);
}
int main(void)
// main function
{
DDRA=0b00000000;
// declare PortA as a input port connected to the
sensors
DDRB=0b11111111;
// declare PortB as a output port connected to the
motors
int left_sensor=0, right_sensor=0,i;
while(1) // infinite loop
{
left_sensor=PINA&0b00010000; // mask PA4 bit of Port A
right_sensor=PINA&0b00100000; // mask PA5 bit of Port A

if((left_sensor==0b00000000) && (right_sensor==0b00000000)) // if


both sensors "off"
{
PORTB=0b00000000;
}
if((left_sensor==0b00000000) && (right_sensor==0b00100000))
if both sensors "on"
{
PORTB=0b00001001;
}

if((left_sensor==0b00010000) && (right_sensor==0b00100000))


// if left sensor off but right sensor on
{
PORTB=0b00000001;
}

}
}

Test code for skipping a diversion:--

//

/* Program for "Black Line Follower Robot"


Connection settings of the Kit
Pins of IR sensor is connected with the PortA of the MCU
Left Sensor -----> PA4
Right Sensor-----> PA5
Left Motor -----> PB0,PB1
Right Motor -----> PB2,PB3
BOOTLooder Condition Check--->PA0(If 0 bootler section else program execution
section of Flash memory)
Crystal Ossilator(12MHz)----->XTAL1,XTAL2
VB=Battery Supply
VCC=regulated 5V+
Gnd=Ground(0V)
*/
#define F_CPU 12000000UL // define MCU Clock speed
#include <avr/io.h>
// include avr header file
#include <util/delay.h> // include delay header file
void wait(float x)
// wait function
{
for(int i=0;i<(int)(x*46);i++)
_delay_loop_2(0);
}
int main(void)
// main function
{
DDRA=0b00000000;
// declare PortA as a input port connected to the
sensors
DDRB=0b11111111;
// declare PortB as a output port connected to the
motors
int left_sensor=0, right_sensor=0,i;
while(1) // infinite loop
{
left_sensor=PINA&0b00010000; // mask PA4 bit of Port A
right_sensor=PINA&0b00100000; // mask PA5 bit of Port A
if((left_sensor==0b00000000) && (right_sensor==0b00000000)) // if
both sensors "off"
{
PORTB=0b00000000;

}
if((left_sensor==0b00000000) && (right_sensor==0b00100000))
if both sensors "on"
{
PORTB=0b00001001;
}

if((left_sensor==0b00010000) && (right_sensor==0b00100000))


// if left sensor off but right sensor on
{
wait(1);
for(i=0;i<=3;i++)
{
i=i+1;
PORTB=0b00001001;
}
PORTB=0b00000001;
}

}
}

//

Вам также может понравиться