Black line following robot using AT89S52

The MUC AT89S52 is such a nice microcontroller that I fell in love with it. Its got very simple coding style of LFR and even a novice will surely understand how to set the ‘sbit’ and get your robot ready to run on any black track.

Following is the program for it. Beginners are advised to read each and every line carefully and that the connection details for motors, sensors and buzzer are also given.

/*
	Program designed by: Prof. Dattaraj Vidyasagar
	For the students of Advanced Robotics Course (LEVEL-3)
	of YANTRAM ROBOTICS CLUB
	For more information visit: www.vsagar.org
*/

#include 
sbit buzzer=P2^0;
sbit LS=P3^1;
sbit RS=P3^0;
sbit LM1=P1^3;
sbit LM2=P1^2;
sbit RM1=P1^1;
sbit RM2=P1^0;

// P1.3 to P1.0 are defined as output pins for the motors
// LM is connected to P1.3 (+) and P1.2 (-)
// RM is connected to P1.1 (-) and P1.0 (+)

Forward() // user defined functions
	{
		LM1=1;
		LM2=0;
		RM1=0;
		RM2=1;
	}

SoftLeft()
	{
		LM1=0;
		LM2=0;
		RM1=0;
		RM2=1;
	}

SoftRight()
	{
		LM1=1;
		LM2=0;
		RM1=0;
		RM2=0;
	}

Stop()
	{
		LM1=0;
		LM2=0;
		RM1=0;
		RM2=0;
	}

void main()
	{
	int a,b;
	LS=1; // P2.1 is defined as input pin
	RS=1; // P2.0 is defined as input pin

	while(1)
	{
		if ((LS==0)&(RS==0))
		{
			Stop();
		}
		if ((LS==0)&(RS==1))	// left turn
		{
			SoftLeft();
			buzzer=1;
			for (a=0; a<=100; a++)
			{
				for (b=0; b<=100; b++);
			}
			buzzer=0;
		}
		if ((LS==1)&(RS==0))
		{
			SoftRight();
			buzzer=1;
			for (a=0; a<=100; a++)
			{
				for (b=0; b<=100; b++);
			}
			buzzer=0;
		}
		if ((LS==1)&(RS==1))
		{
			Forward();
		}
	 } // while closed
	 
	 } // main closed

You can download our updated basic programs of AVR robotic kit using ATMega8/16 microcontroller. Click here to download.

Leave a comment

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