This is the FIFTEENTH PROGRAM in your course of FUNDAMENTALS OF ROBOTICS. To use this program, you must use our robotics kit already supplied to you.
If you do not have this kit, then you can purchase our distance learning programme in robotics or contact us to join our regular batches of robotics.
Now read the following program carefully and work as per the given instructions, to enjoy your FIRST COURSE in robotics.
To use this program directly for your robotic kit, copy it, create new project in AVR Studio and then paste it into the coding area. Then compile it. OR ELSE, DESIGN YOUR OWN, BY REFERRING TO THIS PROGRAM.
![track](https://vsagaracademy.wordpress.com/wp-content/uploads/2021/09/robotic-competition-track-1.png?w=415)
/* Applicable to ATMega8/16/32/128 *** CONNECTION DETAILS OF KIT *** 1) The 2 motors in your kit, are connected to PB4-PB1, as follows: Left motor: PB4 -> (+) and PB3 -> (-) Right motor: PB1 -> (+) and PB1 -> (-) 2) Connect the 2 sensors to PC3 & PC0 in your kit. Connect LEFT SENSOR to PC3 and RIGHT SENSOR to PC0 */ #define F_CPU 1200000UL // defining clock frequency for accurate delay #include <avr/io.h> // includes input/output header file #include <util/delay.h> // includes delay header file int main(void) { DDRB=0b00011110; //PORTB as output Port connected to motors DDRC=0b0000000; //PORTC Input port connected to Sensors int LS=0, RS=0; int counter=1; // a counter is initiated at ‘1’ while(1) // infinite loop { LS=PINC&0b0001000; // masking PC3 to receive left sensor status RS=PINC&0b0000001; // masking PC0 to receive right sensor status { // simple BLFR code starts if((LS==0b0001000) & (RS==0b0000001)) // both sensors ON { PORTB=0b00010010; // move forward } if((LS==0b0000000)&(RS==0b0000001)) { PORTB=0b00010000; // turn right } if((LS==0b0001000)&(RS==0b0000000)) { PORTB=0b00000010; // turn left } } // simple BLFR code completed if((LS==0b0000000)&(RS==0b0000000)&(counter==1)) // both sensors OFF { PORTB=0b00000000; // stop _delay_ms(300); PORTB=0b00010000; // turn right _delay_ms(100); counter++; // here value of counter=2 LS=172; // random values stored RS=183; } if((LS==0b0000000)&(RS==0b0000000)&(counter==2)) // both sensors OFF { PORTB=0b00000000; // stop _delay_ms(300); PORTB=0b00010000; // turn right _delay_ms(100); counter++; // here value of counter=3 LS=182; RS=177; // random values stored } if((LS==0b0000000)&(RS==0b0000000)&(counter==3)) // both sensors OFF { PORTB=0b00000000; // stop _delay_ms(300); PORTB=0b00000010; // turn left _delay_ms(100); counter++; // counter=4 LS=203; RS=289; } if((LS==0b0000000)&(RS==0b0000000)&(counter==4)) // both sensors OFF { PORTB=0b00000000; // stop _delay_ms(300); PORTB=0b00010010; // move forward _delay_ms(100); counter++; // counter=5 LS=158; RS=196; // random values stored } if((LS==0b0000000)&(LS==0b0000000)&(counter==5)) // both sensors OFF { PORTB=0b00000000; // stop break; } } // while closed } // main closed