Edge Avoiding Robot using 8051 Microcontroller

This a lab tested code of Edge Avoiding Robot using 8051 Microcontroller. When there is depth below an IR sensor, its output is binary-1. When there is white surface below an IR sensor, its output is binary-0. This code is suitable only if the speed of the wheel motors is slow enough, otherwise the robot will fall from the table on the edge.

The following code is given as per the kit developed at Vidyasagar Academy. To purchase the kit, contact us. If you are the student of Vidyasagar Academy burn the code in the given kit.

/*
  	Program of Edge avoiding robot
	Created by: VIDYASAGAR ACADEMY, http://vsagar.org/
	Date: 26.04.2017
	*** Please respect our efforts 
	and write Google review about Vidyasagar Academy, Akola. ***
*/
#include <reg51.h> // including header file
#include "delay.c" // including the customised delay file
#define motors P1 // PORT1 is assigned to "motors"
sbit LS=P3^7; // left IR sensor is connected to pin-7 of PORT3
sbit RS=P3^0; // right IR sensor is connected to pin-0 of PORT3
	
	int main() // main function
	{ // opening brace of main function

	while(1) // infinite loop
	{ // opening brace of while loop

	if((LS==0)&(RS==0)) // both sensors are on white
	{
	motors=0x09; // forward
	}

	if((LS==1)&(RS==1)) // both sensors are out of table edge
	{
	motors=0x00; // stop
	delay(1000);
	motors=0x06; // backward
	delay(600);
	motors=0x0A; // power right turn
	delay(400);
	}

	if((LS==1)&(RS==0)) // only LS is out of the edge
	{
	motors=0x00; // stop
	delay(1000);
	motors=0x06; // backward
	delay(600);
	motors=0x0A; // power right turn
	delay(400);
	}

	if((LS==0)&(RS==1)) // only RS is out of the edge
	{
	motors=0x00; // stop
	delay(1000);
	motors=0x06; // backward
	delay(600);
	motors=0x05; // power left turn
	delay(400);
	}

	} // while closed
	} // main function closed

Note: Download the file of delay.c mentioned in the above program, from following link and copy it in your project folder.

[download id=”2″]

Share on your network!
Dattaraj Vidyasagar
Dattaraj Vidyasagar

Author on this website. He is veteran of Core Electronics since last 36+ years. ATL Mentor of Change, Niti Ayog, Govt. of India, Google Certified Educator, International Robotics Trainer and author of 18 books on electronics, robotics, programming languages and web designing... ➤➤

Leave a Reply

Your email address will not be published. Required fields are marked *