logologo
Contact

HOMEABOUTSERVICESBLOGSBOOKSSHOPCONTACT

+977 9803661701support@nepatronix.orgLokanthali, Bhaktapur

© 2025 NepaTronix all rigths reserved

Obstacle Avoiding Robot(Robotics Project)

  Back To Blogs

The Line Following Robot is a simple autonomous robot that follows a predefined path marked by a contrasting line on the ground. It utilizes infrared sensors to detect the line and adjust its movement accordingly. This project demonstrates the basic principles of robotics, including sensor integration, decision-making, and motor control.

Project : 10


OBSTACLE AVOIDING ROBOT

Introduction

The Line Following Robot is a simple autonomous robot that follows a predefined path marked by a contrasting line on the ground. It utilizes infrared sensors to detect the line and adjust its movement accordingly. This project demonstrates the basic principles of robotics, including sensor integration, decision-making, and motor control.


If you want to post your project ,research or any document related to Ai,Ml,IoT,Robotics then please email us with your image ,details and your project at blog@nepatronix.org


Components Required


  1. 1) Arduino Board (or compatible microcontroller)
  2. 2) Infrared Sensors (2x)
  3. 3) Motor Driver (L298N or similar)
  4. 4) DC Motors (2x)
  5. 5) Robot Chassis
  6. 6) Wheels (2x)
  7. 7) Power Source (Battery pack or similar)
  8. 8)Jumper Wires(20x)

If you want to buy the components and give it a try you can find the components in SHOP section .search for product :03 

    Pin Configuration

    • Motor Driver:
      • in1, in2, in3, in4: Control pins for motor direction

    • Infrared Sensors:
      • R_S: Right sensor pin
      • L_S: Left sensor pin

    Libraries Used

    No external libraries are used in this project.

     

    Circuit Diagram:


    If you want to post your project ,research or any document related to Ai,Ml,IoT,Robotics then please email us with your image ,details and your project at blog@nepatronix.org

    Code:

    #include <ESP32Servo.h>

    boolean goesForward = false;

    int distance = 100;

    Servo servo_motor;

    #define trigPin 5

    #define echoPin 18

    long duration;

    #define in1 27

    #define in2 26

    #define in3 25

    #define in4 33

    #define servoPin 15

     

    void setup() {

      Serial.begin(115200);

      pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output

      pinMode(echoPin, INPUT); // Sets the echoPin as an Input

     

     

      pinMode(in1, OUTPUT);

      pinMode(in2, OUTPUT);

      pinMode(in3, OUTPUT);

      pinMode(in4, OUTPUT);

      servo_motor.attach(servoPin);

      servo_motor.write(115);

      delay(2000);

     

      distance = readPing();

      delay(100);

      distance = readPing();

      delay(100);

      distance = readPing();

      delay(100);

      distance = readPing();

      delay(100);

     

    }

     

    void loop() {

      int distanceRight = 0;

      int distanceLeft = 0;

      delay(50);

      if (distance <= 20) {

        moveStop();

        delay(300);

        moveBackward();

        delay(400);

        moveStop();

        delay(300);

        distanceRight = lookRight();

        delay(300);

        distanceLeft = lookLeft();

        delay(300);

        if (distance >= distanceLeft) {

          turnRight();

          moveStop();

        }

        else {

          turnLeft();

          moveStop();

        }

      } else {

        moveForward();

      }

      distance = readPing();

     

    }

     

    int lookRight() {

      servo_motor.write(50);

      delay(500);

      int distance = readPing();

      delay(100);

      servo_motor.write(115);

      return distance;

    }

     

    int lookLeft() {

      servo_motor.write(170);

      delay(500);

      int distance = readPing();

      delay(100);

      servo_motor.write(115);

      return distance;

    }

     

    int readPing() {

      digitalWrite(trigPin, LOW);

      delayMicroseconds(2);

      // Sets the trigPin on HIGH state for 10 micro seconds

      digitalWrite(trigPin, HIGH);

      delayMicroseconds(10);

      digitalWrite(trigPin, LOW);

      // Reads the echoPin, returns the sound wave travel time in microseconds

      duration = pulseIn(echoPin, HIGH);

      // Calculating the distance

      distance = duration * 0.034 / 2;

      // Prints the distance on the Serial Monitor

      Serial.print("Distance: ");

      Serial.println(distance);

     

      delay(20);

      if (distance == 0) {

        distance = 250;

      }

      return distance;

    }

     

    void moveForward() {

      if (!goesForward) {

        goesForward = true;

        digitalWrite(in1, HIGH);

        digitalWrite(in2, HIGH);

        digitalWrite(in3, LOW);

        digitalWrite(in4, LOW);

      }

    }

    void moveBackward() {

      goesForward = false;

      digitalWrite(in1, HIGH);

      digitalWrite(in2, HIGH);

      digitalWrite(in3, LOW);

      digitalWrite(in4, LOW);

    }

     

    void turnRight() {

      digitalWrite(in1, HIGH);

      digitalWrite(in2, HIGH);

      digitalWrite(in3, LOW);

      digitalWrite(in4, LOW);

      delay(500);

      digitalWrite(in1, HIGH);

      digitalWrite(in2, HIGH);

      digitalWrite(in3, LOW);

      digitalWrite(in4, LOW);

     

    }

    void turnLeft() {

      digitalWrite(in1, LOW);

      digitalWrite(in2, LOW);

      digitalWrite(in3, HIGH);

      digitalWrite(in4, HIGH);

      delay(500);

      digitalWrite(in1, LOW);

      digitalWrite(in2, LOW);

      digitalWrite(in3, HIGH);

      digitalWrite(in4, HIGH);

    }

    void moveStop() {

      digitalWrite(in1, LOW);

      digitalWrite(in2, LOW);

      digitalWrite(in3, LOW);

      digitalWrite(in4, LOW);

    }

    Working


    1. Initialization:
      • Set up the necessary pins for motor control and sensor input.

    2. Main Loop:
      • Continuously monitor the state of the infrared sensors.
      • Based on the sensor readings, adjust the robot's movement to follow the line.

    3. Forward Movement:
      • If both sensors detect the line, move forward.
    4. Right Movement:

    5. If only the right sensor detects the line, turn right to re-align with the line.

    6. Left Movement:
      • If only the left sensor detects the line, turn left to re-align with the line.
    7. Stop:
      • If both sensors lose track of the line, stop the robot.

     

     

    Testing


    1. Setup:
      • Assemble the robot chassis, attach wheels and motors.
      • Mount the infrared sensors close to the ground with one sensor on each side of the robot.

    2. Line Following:
      • Place the robot on a track with a contrasting line.
      • Observe the robot's behavior as it follows the line.
      • Adjust the sensitivity of the sensors if needed.

    3. Edge Cases:
      • Test the robot's performance on sharp turns, intersections, and varying line thicknesses.
      • Ensure that the robot can recover from deviations and continue following the line accurately.

    Conclusion

    The Line Following Robot project demonstrates a fundamental concept in robotics and automation. By using infrared sensors to detect a line's presence, the robot can navigate predefined paths autonomously. This project serves as a starting point for more advanced robotics applications such as maze-solving robots, industrial automation, and self-driving vehicles. Further enhancements to this project could include adding PID control for smoother movement, integrating wireless communication for remote control, and implementing obstacle avoidance algorithms for increased versatility.


    If you want to post your project ,research or any document related to Ai,Ml,IoT,Robotics then please email us with your image ,details and your project at blog@nepatronix.org




    Total likes : 4

    Comments







    Read More Blogs!

    Automatic Morning Alarm(STEAM Education)

    The aim of this project is to create an automatic morning alarm system using simple electronic components.


    1.8k03

    Top 10 Robotics Projects for Final Year Students (iot projects based on arduino/esp32/esp8266)

    Looking for engaging and innovative robotics projects for your final year? Explore these top 10 projects, ranging from autonomous line-following robots to sophisticated swarm robotics. These projects cover a wide range of applications, including industrial automation, healthcare, surveillance, and human-robot interaction. Whether you're interested in building a robotic arm or a self-balancing robot, each project offers a hands-on opportunity to develop essential skills in robotics, control systems, and programming. Dive in to discover the most exciting robotics ideas for your final year and take your robotics skills to the next level!


    1.4k02

    WiFi Based Remote Control Car(Robotics Project)

    The Bluetooth-controlled robot project focuses on developing a robot that can be controlled through a mobile application using the Blynk platform. This integration allows for remote control via a WiFi connection, enabling users to send commands to the robot and monitor its status in real-time. The project leverages components like the ESP32, motor drivers, DC motors, and an LCD for status display. This project aims to enhance understanding of WiFi-based communication, motor control, and mobile app interfacing with microcontrollers.


    1.6k04

    TEMPERATURE HUMIDITY READER ON MOBILE (IoT Project)

    The Temperature Humidity Reader project utilizes an ESP32 microcontroller in conjunction with a DHT11 sensor to monitor temperature and humidity levels. The collected data is displayed on an LCD and transmitted to a mobile application using the Blynk platform. This project provides an efficient way to remotely monitor environmental conditions in real time, making it useful for applications such as home automation, weather stations, and greenhouse monitoring.


    2.2k03