How to design WHITE line following robot? Basic Tutorials

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

/*
	Level II project of 'WHITE line following robot (WLFR)'
	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 -> (-)
	2) Connect the two IR sensors to PC3 & PC0 in your kit.
	   Connect LEFT SENSOR to PC3 and RIGHT SENSOR to PC0
*/

#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 					
	int main() // starting the main function of program

	{ // main function brace opened

	DDRB=0b00011110; // PB4-PB1 of PORTB are defined as output pins
	DDRC=0b0000000;  // PC6-PC0 of PORTC are defined as input pins

	int s=0; // 's' is the variable to store the status value of sensor	
			 // when we write 'int s', it creates a location in memory of 
			 // microcontroller.
			 // initially '0' is stored into 's' memory location

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

	s=PINC&0b0001001; // assigning the variable 's' to PC0 of PORTC
					  // so that the output status of sensor will be 
					  // stored into the variable 's'
					  // since one sensor in our kit is connected 
					  // to PC0 and other to PC3 
					  // Note: Left sensor is connected to PC3 and
					  // right sensor to PC0

		if(s==0b0000000) // black surface below both sensors
		{
		PORTB=0b00010010; // both motors rotate in forward direction
						  // so robot moves forward
		}

		if(s==0b0001000) // white below LS and black below RS
		{
		PORTB=0b00010000; // only left motor rotates forward
						  // so robot turns right
		}

		if(s==0b0000001) // white below RS and black below LS
		{
		PORTB=0b00000010; // only right motor rotates forward
						  // so robot turns left
		}

		else // WHITE surface below both the sensors
		{
		PORTB=0b00000000; // both motors are OFF and robot stops
		}

	} // 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 make a WHITE track of oval shape.
	6) Make this track particularly on smooth surface.
	7) Now according to the width of track adjust the distance between two sensors.
	8) Keep them apart from each other as required.
	9) Place your robot on the track such that the two sensors will be on black.
	10) Now connect battery and switch on the kit.
	11) Your robot will follow the track.
	12) Is it working? Nice! You did it.
	13) Now don't forget to give your feedback.

	=== IMPORTANT NOTE (SAME AS BLFR ADJUSTMENT) ===

	If the robot is not following the track correctly, then adjust the 
	sensitivity of the IR sensors.
	For this, first keep black surface below both sensors. The indicators of the 
	sensors must remain OFF.
	If not, then turn the sensitivity screw ANTICLOCKWISE to decrease the 
	sensitivity of the sensors.
	So by trial and error, adjust the sensitivity and then check it on black track.
	Remember, when you are done correctly with this adjustment, your robot
	must follow the track correctly.

	*** So good luck friends! ***

*/ 

About the author: Admin of Vidyasagar Academy to post all types of educational material required for our students. This material is equally helpful to our online students.

Comments on this entry are closed.