logologo

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!

    Carbon Monoxide Reader On Mobile App(IoT project)

    The Carbon Monoxide Reader project aims to develop a robot that monitors carbon monoxide (CO) levels and reports the data to a mobile application using the Blynk platform. This integration allows for real-time data visualization and alerts through a WiFi connection, enhancing safety by providing timely notifications of dangerous CO levels. The project leverages components such as the ESP32, a CO sensor, and an LCD for local display, combined with the Blynk app for remote monitoring. This project highlights the practical applications of IoT in environmental monitoring and mobile app interfacing with microcontrollers.


    1.5k03

    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.1k03

    loRa(LOng Range)Alert System(IoT Projects Arduino)

    The IoT Projects Arduino LoRa (Long Range) Alert System is a wireless communication system designed to facilitate long-distance, low-power data transmission. In this project, two LoRa modules are employed in distinct locations, with one module acting as a transmitter and the other as a receiver. The system is engineered to send alerts or messages across large distances with minimal power consumption, making it ideal for remote monitoring and alerting applications. This IoT Projects Arduino documentation provides a comprehensive overview of the system's use, importance, operational principles, components, pin configurations, libraries used, working mechanism, main loop, notification function, and testing procedures.


    2.6k06

    Wireless Power Transmission(STEAM Education)

    To understand wireless energy transfer through mutual induction.


    1.5k04