How to take U-turn to your robot?

This is the EIGHTH 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 program 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.

/*
	Level II project of 'U-turn Robot'
	Applicable to ATMega8/16/32/128
	Designed by: Vidyasagar Academy, Akola
	Website: www.vsagar.org

	*** 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 -> (-)
*/

#define F_CPU 12000000UL // defining the crystal frequency 12MHz 
						// given on your dev. board of ATMega8

#include <avr/io.h> // including the input-output 
		// to define the input output ports and pins
		// this file is inside the AVR folder 	

#include <util/delay.h> // including the delay file
			// this file is inside the 
			// utilities (util) folder				

	int main() // starting the main function of program

	{ // main function brace opened

	DDRB=0b00011110; // PB4-PB1 of PORTB are defined as output pins

	while(1) // starting the infinite loop to repeat the action infinitely
	
	{ // while loop brace opened

		PORTB=0b00000000; // both motors OFF
		_delay_ms(1000); // delay of 1000ms=1sec
		
		PORTB=0b00010010; // both motors rotate FORWARD
						  // so your robot will move forward for 3sec.

		_delay_ms(2000); // delay of 2000ms=2sec.

		PORTB=0b00010000; // taking right U-turn 
		_delay_ms(500); // for 0.5sec so that the robot will take U-turn

		PORTB=0b00010010; // moving forward
		_delay_ms(1000); // for 1sec

		PORTB=0b00000010; // taking left U-turn 
		_delay_ms(500); // for 0.5sec so that the robot will take U-turn 
					    // in opposite direction

		PORTB=0b00010010; // moving forward
		_delay_ms(1000); // for 1sec

	} // while loop closed

	} // main function closed

/* 
	=== HOW TO USE AND RUN THIS PROGRAM IN YOUR KIT? ===
	1) First read the program carefully. Understand the steps as taught to you.
	2) Connect your kit to USB port.
	3) Burn the 'hex' file into your kit.
	4) Connect both the IR sensors, to PC3&PC0 in your kit.
	5) Now connect battery and switch on the kit.
	6) First your robot will move forward.
	7) Then it will take U-turn. Adjust the delay if required.
	8) Then again it will move forward, then left U-turn.
	9) Finally it will go forward and then stop. And repeat endlessly.
	10) Is it working? Nice! You did it.
	11) Now don't forget to give your feedback.

	Note: You can adjust the delay of 500ms for U-turn by trial and error.
	      Try changing it to 700ms to 800ms
*/ 

If you liked this post please write Google feedback about us.
Thanks in advance!

One thought on “How to take U-turn to your robot?

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.