Pages

Chapter 8.5 - Making a Line Following Robot (LFR) with 8051 Microcontroller on Breadboard - Source Code


Make sure your connections are ok before programming. And yes, there is one more thing which you need to understand. If your motor runs in a different direction then just switch the wires of motors and cross it. Ex: reverse the connection of output1 and output2. Following is the C source code for Making a Line Following Robot (LFR) with 8051 Microcontroller on Breadboard:


//*******************************************************************
//www.go8051.com
//Chapter 8
//Making a Line Following Robot (LFR) with 8051 Microcontroller on Breadboard
//Created By go8051.com
// Open source
//email : 8051blog@gmail.com
//*******************************************************************
#include<reg51.h> // Header file for 8051 microcontroller
sbit IN1=P3^7; // Defining Port 3.7 as Input1 for motor
sbit IN2=P3^6; // Defining Port 3.6 as Input2 for motor
sbit IN3=P3^5; // Defining Port 3.5 as Input3 for motor
sbit IN4=P3^4; // Defining Port 3.4 as Input4 for motor
sbit S1=P2^0; // Defining Port 2.0 as Sensor1
sbit S2=P2^1; // Defining Port 2.1 as Sensor2
void main()
{
IN1=0; // Declare IN1 pin as Output pin
IN2=0; // Declare IN2 pin as Output pin
IN3=0; // Declare IN3 pin as Output pin
IN4=0; // Declare IN4 pin as Output pin
S1=1; // Declare S1 pin as input pin
S2=1; // Declare S2 pin as input pin
while(1) // Infinite while loop
{
if(S1==1&&S2==1) // if sensor 1 and sensor 2 are on black line then move forward
{
IN1=1; // Set IN1 as 1
IN2=0; // Set IN2 as 0
IN3=1; // Set IN3 as 1
IN4=0; // Set IN4 as 0
}
if(S1==0&&S2==1) // if sensor 1 is on white and sensor 2 is on black line then move right
{
IN1=0; // Set IN1 as 0
IN2=1; // Set IN2 as 1
IN3=1; // Set IN3 as 1
IN4=0; // Set IN4 as 0
}
if(S1==1&&S2==0) // if sensor 1 is on black and sensor 2 is on white line then move left
{
IN1=1; // Set IN1 as 1
IN2=0; // Set IN2 as 0
IN3=0; // Set IN3 as 0
IN4=1; // Set IN4 as 1
}
if(S1==0&&S2==0) // if sensor 1 is on white and sensor 2 is on white line then stop
{
IN1=0; // Set IN1 as 0
IN2=0; // Set IN2 as 0
IN3=0; // Set IN3 as 0
IN4=0; // Set IN4 as 0
}
}
}

And here is the zip file of the code. Click on the download button, to download the c source code of Making a Line Following Robot (LFR) with 8051 Microcontroller on Breadboard.

 Download C Source code for 8051

Unknown

Go8051.com is a medium for hobbyist and enthusiasts to learn 8051 microcontroller from scratch on bread board.

Related Posts:

No comments:

Post a Comment

Stuck Somewhere ? Comment Your Queries and Experts will Guide You.