Sunday, February 16, 2014

Embedded C code / program for Line follower robot using 8051 micro controller - IR sensor based

Are you making a line follower robot using a 8051 micro controller P89V51RD2 from Philips or AT89C51/AT89S51 from Atmel programmed using Keil compiler ?  Here is the code for making a simple line follower robot.

This embedded C programming language Code is based on the following design. You can modify it based on your requirements :
No. of sensors  - 2
Signal from sensors- 1 for white and 0 for black
No. of motors - 2
About motors - Both the motors are DC motors and are connected to the micro-controller through a Motor driver IC.

This Embedded C code is as per the syntax of keil compiler for 8051 micro controller

Code for Line follower Robot:
#include<reg51.h>
sbit sensor-left=P1^0;
sbit sensor-right=P1^1;
sbit motor-left=P0^0;
sbit motor-right=P0^1;


void main()
{
sensor-left=sensor-right=0;
motor-left=motor-right=0;

while(1)
{
if((sensor-left==1)&&(
sensor-right==0))
{
motor-left=1;
motor-right=0;
}
else if((sensor-left==0)&&(sensor-right==1))
{
motor-left=0;
motor-right=1;
}
else if((sensor-left==0)&&(sensor-right==0))
{
motor-left=0;
motor-right=0;
}

else if((
sensor-left==1)&&(sensor-right==1))
{
motor-left=1;
motor-right=1;
}
}
}


Adjust your motors and sensors as per your requirement.


4 comments:

  1. motor driver has 4 inputs for 2 dc motor,you declare only 2 pins
    sbit motor-left=P0^0;
    sbit motor-right=P0^1;
    where to connect othr 2 pins

    ReplyDelete
  2. other pins both connect to ground..

    ReplyDelete
  3. Automation 2/3/4/6 Weeks Regular Summer / Winter / Project Training Program for B Tech Students. For Details Contact 91-9310096831. This training will inculcate a level of confidence which will help the aspirants for achieving numerous career objectives.

    ReplyDelete

You might also like