Table Top Edge Avoiding Robot using 8051 Microcontroller

Table Top Edge Avoiding Robot using 8051 Microcontroller

Alert!

The Table Top Edge Avoiding Robot 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

What is Table Top Edge Avoiding Robot?

Table Top Edge Avoiding Robot using 8051 Microcontroller is an autonomous robot designed to avoid falling off a table edge. It uses IR sensors to detect the absence of a surface (edge detection) and changes its direction accordingly to avoid falling. The 8051 Microcontroller processes sensor data and controls the motors to achieve edge avoidance.

2. Components Required

  1. 8051 Microcontroller (AT89C51)
  2. IR Sensors (2 pairs)
  3. 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 IR sensors are placed at the front corners of the robot. The table’s surface reflects the IR light, while the absence of the surface (edge) fails to reflect it, making the IR sensor output LOW (0). The robot uses these sensor outputs to make decisions:

  1. Both sensors on table → Move Forward.
  2. Left sensor detects edge → Turn Right.
  3. Right sensor detects edge → Turn Left.
  4. Both sensors detect edge → Stop.

4. Circuit Diagram

The connections are as follows:

  1. IR Sensors: Outputs connected to pins P1.0 and P1.1.
  2. Motor Driver IC (L293D): Inputs connected to pins P2.0 to P2.3.
  3. Motors: Connected to L293D outputs.
  4. Power Supply: Supplies power to the motors and the 8051 microcontroller.

5. Logic for Edge Avoidance

  1. If both sensors detect the table → Move Forward.
  2. If left sensor detects the edge → Turn Right.
  3. If right sensor detects the edge → Turn Left.
  4. If both sensors detect the edge → Stop.

6. Program Code with Explanation

Here is the complete program written in Embedded C for the Table Top Edge Avoiding Robot.

6.1 Initialization and Pin Definitions

#include<reg51.h>
sbit left_sensor=P1^0;
sbit right_sensor=P1^1;
sbit motor1_a=P2^0;
sbit motor1_b=P2^1;
sbit motor2_a=P2^2;
sbit motor2_b=P2^3;

Explanation

  1. #include<reg51.h>: Includes the 8051 microcontroller header file.
  2. sbit: Defines pins for sensors and motor control:
  3. left_sensor and right_sensor: Inputs for IR sensors.
  4. motor1_a and motor1_b: Control the left motor.
  5. motor2_a and motor2_b: Control the right motor.

6.2 Motor Control Functions

void move_forward() {
     motor1_a=1;motor1_b=0;
     motor2_a=1;motor2_b=0;
}

void move_left() {
     motor1_a=0;motor1_b=0;
     motor2_a=1;motor2_b=0;
}

     void move_right() {
     motor1_a=1;motor1_b=0;
     motor2_a=0;motor2_b=0;
}

void stop() {
     motor1_a=0;motor1_b=0;
     motor2_a=0;motor2_b=0;
}

Explanation

  1. move_forward(): Both motors move forward.
  2. motor1_a=1;motor1_b=0 → Left motor forward.
  3. motor2_a=1;motor2_b=0 → Right motor forward.
  4. move_left(): Left motor stops, and the right motor moves forward to turn left.
  5. move_right(): Right motor stops, and the left motor moves forward to turn right.
  6. stop(): Both motors stop, halting the robot.

6.3 Main Program Logic

void main() {

while(1) {
        if(left_sensor==1&&right_sensor==1) {
        move_forward();
    }

        else if(left_sensor==0&&right_sensor==1) {
        move_right();
    }

        else if(left_sensor==1&&right_sensor==0) {
        move_left();
    }

        else if(left_sensor==0&&right_sensor==0) {
        stop();
   }
 }
}

Explanation

  1. while(1): Infinite loop for continuous edge detection and movement.
  2. Condition Checks: if(left_sensor==1&&right_sensor==1): Both sensors detect the table surface → Move Forward.
  3. else if(left_sensor==0&&right_sensor==1): Left sensor detects an edge → Turn Right.
  4. else if(left_sensor==1&&right_sensor==0): Right sensor detects an edge → Turn Left.
  5. else if(left_sensor==0&&right_sensor==0): Both sensors detect edges → Stop the robot.

7. Flowchart

Here is the flow of the robot operation:

  1. Start → Initialize ports and pins.
  2. Read Sensor Values.
  3. Check Conditions: Both sensors detect table → Move Forward.
  4. Left sensor detects edge → Turn Right.
  5. Right sensor detects edge → Turn Left.
  6. Both sensors detect edge → Stop.
  7. Repeat Steps Continuously.

8. Assembly Language Program (ALP)

This code is given to the students and hobbyists who are interested to work with ALP code of the project. Try it…! Its perfectly working, as it is tested in Vidyasagar Academy Lab.

ORG 0000H           ; Starting address of the program

; Pin Definitions
LEFT_SENSOR  EQU P1.0
RIGHT_SENSOR EQU P1.1
MOTOR1_A     EQU P2.0
MOTOR1_B     EQU P2.1
MOTOR2_A     EQU P2.2
MOTOR2_B     EQU P2.3

; Motor Control Subroutines
MOVE_FORWARD:
    SETB MOTOR1_A
    CLR  MOTOR1_B
    SETB MOTOR2_A
    CLR  MOTOR2_B
    RET

MOVE_LEFT:
    CLR  MOTOR1_A
    CLR  MOTOR1_B
    SETB MOTOR2_A
    CLR  MOTOR2_B
    RET

MOVE_RIGHT:
    SETB MOTOR1_A
    CLR  MOTOR1_B
    CLR  MOTOR2_A
    CLR  MOTOR2_B
    RET

STOP_MOTORS:
    CLR  MOTOR1_A
    CLR  MOTOR1_B
    CLR  MOTOR2_A
    CLR  MOTOR2_B
    RET

; 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
    JNB RIGHT_SENSOR, TURN_RIGHT
    SJMP TURN_LEFT

CHECK_RIGHT:
    JB RIGHT_SENSOR, MOVE_FWD
    SJMP TURN_LEFT

MOVE_FWD:
    ACALL MOVE_FORWARD
    SJMP CHECK_SENSORS

TURN_LEFT:
    ACALL MOVE_LEFT
    SJMP CHECK_SENSORS

TURN_RIGHT:
    ACALL MOVE_RIGHT
    SJMP CHECK_SENSORS

STOP_ROBOT:
    ACALL STOP_MOTORS
    SJMP CHECK_SENSORS
END

9. Working

  1. IR Sensors: The sensors monitor the table surface continuously.
  2. Sensor Logic: When the table surface disappears (edge), the corresponding sensor sends a LOW signal to the microcontroller.
  3. Microcontroller: Processes the sensor inputs and decides the robot movement by controlling the motors.
  4. Motors: Receive signals from the L293D motor driver and perform actions like moving forward, turning left/right, or stopping.

10. Advantages

  1. Prevents the robot from falling off surfaces.
  2. Simple and cost-effective.
  3. Practical implementation of edge detection using IR sensors.

11. Conclusion

The Table Top Edge Avoiding Robot using the 8051 Microcontroller successfully detects table edges and avoids falling by changing its direction. The use of IR sensors ensures accurate edge detection and the 8051 processes the inputs to control motor movements. This project can be extended further for obstacle avoidance or more complex surface detection.

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