• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Circuit Ideas for You

Get free circuit ideas online.

  • Home
  • Privacy Policy
  • About
Home » Arduino Based Obstacle Avoidance Robot Circuit

Arduino Based Obstacle Avoidance Robot Circuit

Last updated on 9 September 2025 by Admin-Lavi Leave a Comment

This project is for making a small robot car.

Robot can move and avoid obstacle on road.

It uses Arduino Uno, ultrasonic sensor HC-SR04, motor driver L293D and two DC motors.

This Arduino Based Obstacle Avoidance Robot Circuit is simple and good for beginners.

Robot check distance with ultrasonic sensor.

If obstacle is near then robot stops and changes direction.

Circuit Coding:

int trigPin = 9;
int echoPin = 10;
int motor1pin1 = 2;
int motor1pin2 = 3;
int motor2pin1 = 4;
int motor2pin2 = 5;
long duration;
int distance;

void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(motor1pin1, OUTPUT);
pinMode(motor1pin2, OUTPUT);
pinMode(motor2pin1, OUTPUT);
pinMode(motor2pin2, OUTPUT);
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.034 / 2;
if (distance > 20) {
digitalWrite(motor1pin1, HIGH);
digitalWrite(motor1pin2, LOW);
digitalWrite(motor2pin1, HIGH);
digitalWrite(motor2pin2, LOW);
} else {
digitalWrite(motor1pin1, LOW);
digitalWrite(motor1pin2, HIGH);
digitalWrite(motor2pin1, HIGH);
digitalWrite(motor2pin2, LOW);
delay(500);
}
}

Code Explanation:

  • Variables are made for sensor and motor pins.
  • Setup function tell which pin is input or output.
  • Trig pin send short pulse.
  • Echo pin wait and read back pulse.
  • pulseIn measure time of travel.
  • Formula change time into distance.
  • If distance is more than 20 cm then both motors go forward.
  • If distance is less than 20 cm then robot stops and turn.
  • Turn done by one motor forward and other motor backward.
  • Delay is 500 ms so robot complete its turn.
  • Loop repeat always.

Circuit Working:

Arduino Based Obstacle Avoidance Robot Circuit Diagram

Parts List:

ComponentQuantity
Arduino UNO1
Ultrasonic Sensor HC-SR04 Module1
Motor Driver L293D1
BO Motor DC Gear Motor with wheels2
ON/OFF switch1
9V Battery1

Arduino Uno is main brain of this project.

Ultrasonic sensor HC-SR04 connect to Arduino pins.

Motor driver L293D run two DC motors.

Arduino alone cannot give enough current to motors.

9V battery gives power supply.

ON OFF switch connect in battery positive line for easy control.

When power is ON, ultrasonic sensor keep measure distance.

If distance more than 20 cm then robot goes forward.

If distance less than 20 cm then robot stops and turn.

After a turn the robot goes forward again.

This simple logic help robot avoid obstacles.

Formulas:

The below mentioned formula is for Arduino Based Obstacle Avoidance Robot Circuit:

Ultrasonic sensor formula:

Distance = (Time x Speed of Sound) / 2

where,

  • Ultrasonic sensor is for sound wave.
  • Sound here hit obstacle and come back.
  • Time represents total travel time (go and return).
  • Speed of sound is about 343 meter per second (0.034 cm per microsecond).
  • Divide by 2 is because sound travel two way, go and back.

So this formula gives one-way distance from sensor to obstacle.

How to Build:

To build a Arduino Based Obstacle Avoidance Robot Circuit follow the below mentioned steps for connections:

  • First gather all parts same as circuit diagram.
  • HC-SR04 VCC connect to Arduino 5V.
  • HC-SR04 GND connect to Arduino GND.
  • HC-SR04 Trigger connect to Arduino pin 9.
  • HC-SR04 Echo connect to Arduino pin 10.
  • Put motor driver L293D on breadboard.
  • Input1 and Input2 connect to Arduino pins 2 and 3.
  • Input3 and Input4 connect to Arduino pins 4 and 5.
  • Output1 and Output2 connect to left motor wires.
  • Output3 and Output4 connect to right motor wires.
  • L293D VSS pin 16 connect to Arduino 5V.
  • L293D VS pin 8 connect to 9V battery positive.
  • L293D GND pins 4,5,12 and 13 connect to Arduino GND and battery negative.
  • Battery positive wire go to VS pin 8 of L293D.
  • Battery negative wire go to GND pins 4,5,12 and 13 of L293D.
  • On/Off switch one end connect in battery positive line.
  • Other side of switch connect to VS pin 8 of L293D.

Conclusion:

This Arduino Based Obstacle Avoidance Robot Circuit make small robot car with Arduino.

Robot use ultrasonic sensor to see obstacle.

When obstacle come near the robot stops and turn.

When road is clear then robot go forward.

It is easy project for beginner to learn sensor, motor driver and coding.

More sensor or better code can make robot smarter.

References:

Obstacle Avoiding Robot using Arduino UNO and HC-SR04 Ultrasonic Sensor

Filed Under: Arduino Projects, Sensors and Detectors

About Admin-Lavi

Lavi is a B.Tech electronics engineer with a passion for designing new electronic circuits. Do you have questions regarding the circuit diagrams presented on this blog? Feel free to comment and solve your queries with quick replies

Previous Post: « Arduino Based Automatic Gate Opening and Closing Circuit
Next Post: Dancing Water Fountain Circuit with Arduino »

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar




Categories

  • Alarm Circuits (33)
  • Amplifier Circuits (67)
  • Arduino Projects (36)
  • Audio Circuits (94)
  • Automobile Circuits (19)
  • Battery Charger Circuits (48)
  • Free Energy (13)
  • Heater and Temperature Controllers (10)
  • High Voltage (1)
  • Indicator Circuits (38)
  • Inverter Circuits (13)
  • LDR Circuits (15)
  • LED and Lamps (116)
  • Meters and Testers (28)
  • Motor Controllers (18)
  • Oscillator Circuits (34)
  • Power Supply Circuits (92)
  • Remote Control Circuits (6)
  • Security and Protection (25)
  • Sensors and Detectors (84)
  • Solar Circuits (17)
  • Timer Circuits (30)
  • Transistor Circuits (57)
  • Transmitter Circuit (12)
  • Tutorials (5)
  • Water Level Controller (4)

Recent Posts

  • Sound Sensor Circuit using IC LM393
  • Sound Sensor Direction Circuit using Arduino
  • Dancing Water Fountain Circuit with Arduino
  • Arduino Based Obstacle Avoidance Robot Circuit
  • Arduino Based Automatic Gate Opening and Closing Circuit

Recent Comments

  1. Admin-Lavi on Constant Voltage, Constant Current Battery Charger Circuit
  2. Bill on Constant Voltage, Constant Current Battery Charger Circuit
  3. Admin-Lavi on Long Range FM Transmitter Circuit (2km)
  4. Sina on Long Range FM Transmitter Circuit (2km)
  5. Admin-Lavi on Long Range FM Transmitter Circuit (2km)

Copyright © 2025 | New Circuit Ideas