White Line Following Robot using 8051 Microcontroller

White Line Following Robot using 8051 Microcontroller

This a lab tested code of White line following robot using 8051 MUC. When there is black below an IR sensor, its output is binary-1. When there is white below an IR sensor, its output is binary-0. This code is suitable for OVAL SHAPED SIMPLE WHITE TRACKS. For complicated white tracks i.e. having many steep turns, USE POWER TURN INSTEAD OF SOFT TURN i.e. rotate one motor forward and other backward simultaneously.

Alert!

The DTMF Controlling System using 8051 Microcontroller 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.

1. Introduction

A Line Following Robot is an autonomous robot that follows a pre-defined path, typically a white or black line on a contrasting background. In this project, we use an 8051 Microcontroller to implement a white line follower. The robot senses the line using IR sensors and moves accordingly.

2. Components Required

  1. 8051 Microcontroller (AT89C51)
  2. IR Sensors (2 pairs)
  3. Motors (DC Motors)
  4. Motor Driver IC (L293D)
  5. Chassis
  6. Wheels
  7. Power Supply (Battery 9-12V)
  8. Crystal Oscillator (11.0592 MHz)
  9. Capacitors and Resistors
  10. Connecting Wires

Software required

  1. Keil µVision (for C programming) – download from this link
  2. MIDE51 or any assembler (for ALP) – download from this link
  3. Flash/Programmer Tool (e.g., ProgISP, TopWin) to burn the program into 8051 – download from this link

3. Working Principle

The robot works based on IR sensors that detect the white line. IR sensors emit infrared light, which is either absorbed or reflected depending on the surface:

  1. White Surface: Reflects most IR light back to the sensor.
  2. Black Surface: Absorbs most IR light, little to no reflection.

The sensor output is processed by the 8051 microcontroller, which sends control signals to the motor driver IC (L293D). The motors are turned ON/OFF based on the sensor inputs, enabling the robot to follow the white line.

4. Circuit Diagram

The connections are as follows:

  1. IR Sensors: Output pins are connected to the P1.0 and P1.1 pins of the 8051 microcontroller.
  2. Motor Driver IC (L293D): Input pins are connected to P2.0 to P2.3 pins of the 8051 microcontroller.
  3. Motors: Connected to the output pins of the L293D.
  4. Power Supply: Provides power to the motors and 8051 circuit.

5. Logic for Line Following

  1. If both sensors detect white (line), move FORWARD.
  2. If the left sensor detects black, turn RIGHT.
  3. If the right sensor detects black, turn LEFT.
  4. If both sensors detect black (no line), STOP.

6. Program Code and Explanation

Below is the complete code for the white line following robot with line-by-line explanations.

Code Initialization

#include <reg51.h>      // Header file for 8051 Microcontroller
sbit left_sensor = P1^0;   // Left IR sensor connected to Pin P1.0
sbit right_sensor = P1^1;  // Right IR sensor connected to Pin P1.1
sbit motor1_a = P2^0;  // Motor1 (LEFT Motor) Control Pin A
sbit motor1_b = P2^1;  // Motor1 Control Pin B
sbit motor2_a = P2^2;  // Motor2 (RIGHT Motor) Control Pin A
sbit motor2_b = P2^3;  // Motor2 Control Pin B

Explanation

  1. #include <reg51.h>: Includes the header file for the 8051 microcontroller.
  2. sbit is used to define sensor and motor control pins:
  3. left_sensor and right_sensor are connected to P1.0 and P1.1 respectively.
  4. motor1_a, motor1_b, motor2_a, motor2_b are control pins for the motor driver IC (L293D).

Motor Control Functions

void move_forward() {
    motor1_a = 1; motor1_b = 0;  // Left motor moves forward
    motor2_a = 1; motor2_b = 0;  // Right motor moves forward
}

void move_left() {
    motor1_a = 0; motor1_b = 0;  // Left motor stops
    motor2_a = 1; motor2_b = 0;  // Right motor moves forward
}

void move_right() {
    motor1_a = 1; motor1_b = 0;  // Left motor moves forward
    motor2_a = 0; motor2_b = 0;  // Right motor stops
}

void stop() {
    motor1_a = 0; motor1_b = 0;  // Left motor stops
    motor2_a = 0; motor2_b = 0;  // Right motor stops
}

Explanation

  1. move_forward(): Both motors move forward to drive the robot straight.
  2. move_left(): The right motor moves forward while the left motor stops, making the robot turn left.
  3. move_right(): The left motor moves forward while the right motor stops, making the robot turn right.
  4. stop(): Both motors stop, halting the robot.

7. Conditional Movement Logic

void main() {
    while (1) {   // Infinite loop
        if (left_sensor == 1 && right_sensor == 1) {
            move_forward();  // Move forward when both sensors detect white
        }

        else if (left_sensor == 0 && right_sensor == 1) {
            move_right();  // Turn right when left sensor detects black
        }

        else if (left_sensor == 1 && right_sensor == 0) {
            move_left();  // Turn left when right sensor detects black
        }

        else if (left_sensor == 0 && right_sensor == 0) {
            stop();  // Stop when both sensors detect black
        }
    }
}

Explanation

  1. while (1): Creates an infinite loop so the robot runs continuously.
  2. left_sensor == 1 && right_sensor == 1: Both sensors detect white, so move forward.
  3. left_sensor == 0 && right_sensor == 1: Left sensor detects black, so turn right.
  4. left_sensor == 1 && right_sensor == 0: Right sensor detects black, so turn left.
  5. left_sensor == 0 && right_sensor == 0: Both sensors detect black, so stop.
  6. The motor control functions (move_forward, move_right, move_left, stop) are called based on sensor inputs.

8. Explanation of Working

  1. The IR sensors sense the line and send digital signals (0 or 1) to the 8051 microcontroller.
  2. The microcontroller checks the sensor input and calls the appropriate motor control function.
  3. The L293D motor driver IC receives signals from the microcontroller and controls the motors accordingly.
  4. The robot moves forward, turns left, or turns right based on the sensor data.

The White Line Following Robot using the 8051 Microcontroller successfully detects and follows a white line. It uses IR sensors for detection and a motor driver IC to control the motors. This project demonstrates the concept of autonomous robots and forms the basis for more advanced robotic systems.

9. Assembly Language Code

If you are interested to make this project using Assembly Language Program (ALP) then we have also given it for your project. Read the following points step by step and use them to make your project a great success! All the best…!

Initialization and Pin Definitions

ORG 0000H           ; Starting address of the program
; Pin Definitions
LEFT_SENSOR  EQU P1.0  ; Left IR Sensor at Pin P1.0
RIGHT_SENSOR EQU P1.1  ; Right IR Sensor at Pin P1.1
MOTOR1_A     EQU P2.0  ; Left Motor Pin A
MOTOR1_B     EQU P2.1  ; Left Motor Pin B
MOTOR2_A     EQU P2.2  ; Right Motor Pin A
MOTOR2_B     EQU P2.3  ; Right Motor Pin B

Explanation

  1. ORG 0000H: Tells the assembler to start placing the program at memory address 0000H.
  2. EQU is used to define the pins for sensors and motors for clarity and easier coding.
  3. LEFT_SENSOR and RIGHT_SENSOR refer to the two IR sensors connected to P1.0 and P1.1.
  4. MOTOR1_A, MOTOR1_B, MOTOR2_A, and MOTOR2_B control the two motors.

Motor Control Subroutines

MOVE_FORWARD:

SETB MOTOR1_A   ; Left Motor moves forward
    CLR  MOTOR1_B
    SETB MOTOR2_A   ; Right Motor moves forward
    CLR  MOTOR2_B
    RET

MOVE_LEFT:

CLR  MOTOR1_A   ; Left Motor stops
    CLR  MOTOR1_B
    SETB MOTOR2_A   ; Right Motor moves forward
    CLR  MOTOR2_B
    RET

MOVE_RIGHT:

SETB MOTOR1_A   ; Left Motor moves forward
    CLR  MOTOR1_B
    CLR  MOTOR2_A   ; Right Motor stops
    CLR  MOTOR2_B
    RET

STOP_MOTORS:

CLR  MOTOR1_A   ; Left Motor stops
    CLR  MOTOR1_B
    CLR  MOTOR2_A   ; Right Motor stops
    CLR  MOTOR2_B
    RET

Explanation

  1. MOVE_FORWARD: SETB MOTOR1_A and SETB MOTOR2_A turn ON both motors to move forward.
  2. CLR MOTOR1_B and CLR MOTOR2_B ensure motors rotate in the forward direction.
  3. MOVE_LEFT: Stops the left motor (CLR MOTOR1_A and CLR MOTOR1_B).
  4. Moves the right motor forward (SETB MOTOR2_A).
  5. MOVE_RIGHT: Moves the left motor forward (SETB MOTOR1_A).
  6. Stops the right motor (CLR MOTOR2_A and CLR MOTOR2_B).
  7. STOP_MOTORS: Stops both motors by clearing all motor pins.
  8. RET: Returns from the subroutine to the main program.

Main Program Logic

MAIN:

MOV P1, #0FFH      ; Set P1 as input for sensors
MOV P2, #00H       ; Set P2 as output for motors

CHECK_SENSORS:

JB LEFT_SENSOR, CHECK_RIGHT   ; If LEFT_SENSOR = 1 (white), check right sensor
JNB RIGHT_SENSOR, TURN_RIGHT  ; If RIGHT_SENSOR = 0 (black), turn right
SJMP MOVE_LEFT                ; Otherwise, turn left

CHECK_RIGHT:

JB RIGHT_SENSOR, MOVE_FWD     ; If RIGHT_SENSOR = 1 (white), move forward
SJMP TURN_LEFT                ; Otherwise, turn left

MOVE_FWD:

ACALL MOVE_FORWARD  ; Call subroutine to move forward
SJMP CHECK_SENSORS  ; Go back and check sensors

TURN_LEFT:

ACALL MOVE_LEFT     ; Call subroutine to turn left
SJMP CHECK_SENSORS  ; Go back and check sensors

TURN_RIGHT:

ACALL MOVE_RIGHT    ; Call subroutine to turn right
SJMP CHECK_SENSORS  ; Go back and check sensors

Explanation

  1. MAIN: MOV P1, #0FFH: Configures Port 1 (P1) as input for the sensors.
  2. MOV P2, #00H: Configures Port 2 (P2) as output for controlling motors.
  3. CHECK_SENSORS: JB LEFT_SENSOR, CHECK_RIGHT: Checks if the left sensor detects white (1). If true, jump to CHECK_RIGHT.
  4. JNB RIGHT_SENSOR, TURN_RIGHT: If the right sensor detects black (0), jump to TURN_RIGHT.
  5. SJMP MOVE_LEFT: Otherwise, turn left.
  6. CHECK_RIGHT: JB RIGHT_SENSOR, MOVE_FWD: If the right sensor detects white (1), move forward.
  7. SJMP TURN_LEFT: Otherwise, turn left.
  8. Motor Movements: ACALL MOVE_FORWARD, MOVE_LEFT, or MOVE_RIGHT calls the respective motor control subroutine.
  9. Looping: SJMP CHECK_SENSORS: Continuously loops back to check sensor inputs.
  10. END: End of the program

10. Working Flow

  1. Initialization: Set the sensor pins as input and motor pins as output.
  2. Sensor Checking: Continuously monitor the left and right sensors.
  3. Decision Making: If both sensors detect white → Move Forward.
  4. If left sensor detects black → Turn Right.
  5. If right sensor detects black → Turn Left.
  6. If both sensors detect black → Stop.
  7. Motor Control: Appropriate motor control subroutines are called based on the sensor conditions.

The Assembly Language Program (ALP) effectively controls the white line-following robot using sensor inputs and motor control logic. It utilizes subroutines to manage motor movements and loops continuously to ensure real-time line following.

Make sure you download the software tools from their official links and follow their installation instructions carefully. Comment at the bottom of this post if need guidance during installation or usage!

Dr. Dattaraj Vidyasagar
Dr. Dattaraj Vidyasagar

M.S. Electronics & Telecomm. (Cleveland Institute of Electronics, Ohio), Associate Member (IETE, Kolkata), Panelist on Dr. Homi Bhabha Foundation, Google certified educator (Level-1), Mentor of Change (MoC-1619) Niti Ayog, Government of India, International Robotics Trainer, Veteran of Applied Electronics since 35+ years.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x