The Obstacle Avoiding Robot project teaches you how to build an autonomous robotic system that combines sensing and movement to navigate independently. This project creates a smart robot that detects obstacles and avoids them automatically..
In this project, an HC-SR04 ultrasonic sensor continuously scans for obstacles. Two DC motors drive the robot forward. When the sensor detects an obstacle too close, Arduino stops the motors, rotates the robot, and resumes movement.
When the robot powers up, it moves forward autonomously. As it approaches an obstacle, the sensor detects it within safe distance. The robot automatically stops, backs up slightly, rotates, and continues. This behavior repeats indefinitely.
This project teaches Autonomous Navigation, Obstacle Detection and Response, Motor Coordination, Decision-Making Logic, and Robotics Fundamentals.
By finishing this project, you’ll know how autonomous robots work in warehouse automation, robotic vacuum cleaners, rover vehicles, and industrial inspection systems.
To build this circuit, collect these specific items from your kit:
Arduino Uno × 1, Breadboard × 1, Robot Chassis × 1, DC Motors × 2, Motor Driver Module (L298N) × 1, HC-SR04 Ultrasonic Sensor × 1, Servo Motor × 1, Battery Pack (6V-9V) × 1, Caster Wheel × 1, Jumper Wires × 15, USB Cable × 1
Connect the Arduino GND pin to the negative rail of the breadboard. This creates a shared ground for all components in the robot system.
Connect the positive terminal of the battery pack to the +12V input of the L298N motor driver. Connect the negative terminal to the GND of the motor driver.
Connect the GND pin of the motor driver to Arduino GND to establish a common ground reference point for proper operation.
Connect the left motor’s positive terminal to OUT1 of the motor driver. Connect the negative terminal to OUT2 of the motor driver.
Connect the right motor’s positive terminal to OUT3 of the motor driver. Connect the negative terminal to OUT4 of the motor driver.
Connect the ENA pin of the motor driver to Arduino Pin 5. Connect the ENB pin to Arduino Pin 6 for PWM speed control.
Connect the IN1 pin to Arduino Pin 2. Connect IN2 to Pin 3 and IN3 to Pin 4. These pins control motor direction.
Connect the HC-SR04 VCC to Arduino 5V. Connect GND to breadboard GND. Connect TRIG to Pin 9 and ECHO to Pin 10.
Connect the servo VCC to Arduino 5V. Connect servo GND to breadboard GND. Connect the servo signal to Arduino Pin 8.
Attach the motors to the robot chassis. Mount the ultrasonic sensor on a servo for scanning capability. Secure Arduino and breadboard to frame.
Test motor rotation by manually turning the wheel. Verify sensor readings in Serial Monitor. Ensure battery voltage is appropriate for motors.
Important: The robot requires stable power. Battery voltage must be sufficient for motor operation. Test each motor independently before integrating obstacle avoidance system.
In setup(), Arduino configures pins 2 through 6 as outputs for motor control. Pins 9 and 10 are configured for the ultrasonic sensor. Pin 8 controls the servo scanner.
Inside the main loop, Arduino measures the distance to objects using the HC-SR04 sensor. If distance is greater than 20 centimeters, the obstacle is far away.
When no obstacle is detected or the obstacle is far away, Arduino sends forward movement commands to both motors. Both motors receive equal PWM values.
First, the motors stop completely. Then the robot backs up by reversing motor direction for half a second. Next, the robot rotates for one second. Finally, motors resume forward movement.
After uploading your code, here is what happens.
After uploading your code, the robot moves forward automatically. As it approaches a wall, distance decreases and the robot stops. The robot backs up, rotates left or right, then resumes forward movement. This cycle repeats continuously.
Robot Does Not Move :- Verify the battery is fully charged and properly connected. Check the motor connections at the driver output terminals. Test each motor individually to ensure functionality.
Robot Moves Only in Circles :- Check that both motors receive equal speed values. Adjust the PWM values to balance motor power. If motors have different speeds, one will rotate faster.
Obstacle Detection Does Not Work :- Verify the HC-SR04 connections to Pins 9 and 10. Check the distance threshold value in your code. Test the sensor independently with Day 9 code.
Robot Does Not Turn Properly :- Check the rotation time delay value. If too short, the robot won’t rotate enough. If too long, the robot rotates too much.
Servo Scanner Does Not Rotate :- Verify the servo signal wire connects to Pin 8. Check that servo receives proper 5V power. Ensure the servo write() commands include appropriate angle values.
By finishing this project, you now know :-
How to coordinate multiple motors simultaneously for movement control. You understand how to implement autonomous decision-making logic for navigation. You learned to create obstacle detection and response systems effectively. You mastered building practical robotic platforms with independent operation. You developed intelligent navigation behaviors for autonomous systems.
In Day 26, you’ll learn how to build a Line Follower Robot that autonomously follows a black line on the ground using infrared sensors. You will implement proportional control for precise path following.