OBSTACLE AVOIDING ROBOT USING L293 Motor Driver shield

 

 Obstacle Avoiding Robot Using Arduino UNO

Build a smart robotic car that automatically detects and avoids obstacles using an ultrasonic sensor. This beginner-friendly robotics project is perfect for learning automation, sensors, and embedded systems.

The robot uses Arduino Uno as the main controller and an HC-SR04 to measure distance.


 Components Needed

  • Arduino Uno

  • HC-SR04

  • L293D Motor Driver Shield

  • 2 or 4 DC Motors

  • Robot Chassis

  • Wheels

  • Jumper Wires

  • Battery (7.4V–12V recommended)


 Working Principle

  1. The ultrasonic sensor continuously measures the distance ahead.

  2. If no obstacle is detected → Robot moves forward.

  3. If an obstacle is closer than 15 cm:

    • Robot stops

    • Turns left or right

    • Continues moving forward

All decisions are controlled by the Arduino.


 Ultrasonic Sensor Working

The HC-SR04 sensor works using sound waves.

Step-by-Step Process:

1️⃣ Trig Pin sends ultrasonic pulses.
2️⃣ Sound waves travel and hit an obstacle.
3️⃣ Echo Pin receives the reflected signal.
4️⃣ Arduino measures the time taken.
5️⃣ Distance is calculated using a formula.


 Distance Calculation Formula

distance = (time × speed of sound) / 2

Speed of sound:

  • 343 m/s

  • 0.0343 cm/µs

Division by 2 is needed because the sound travels to the object and back.


 Basic Connection Overview

Ultrasonic Sensor:

  • VCC → 5V

  • GND → GND

  • Trig → Arduino Pin 9

  • Echo → Arduino Pin 10

Motor Driver:

  • Motor pins → DC motors

  • IN pins → Arduino digital pins

  • Power → Battery supply


 Sample Arduino Code

const int trigPin = 9;
const int echoPin = 10;

long duration;
int distance;

void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
}

void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);

digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance = duration * 0.0343 / 2;

Serial.print("Distance: ");
Serial.println(distance);

if (distance > 15) {
moveForward();
} else {
stopRobot();
turnRight();
}

delay(500);
}

void moveForward() {
// Add motor control logic
}

void stopRobot() {
// Stop motors
}

void turnRight() {
// Turning logic
}

 Applications

✅ Autonomous robots
✅ Warehouse automation
✅ Smart delivery robots
✅ Robotics competitions
✅ STEM education projects
✅ Beginner AI navigation systems


Comments