Obstacle Avoiding Robot Using Arduino, L298N, Ultrasonic Sensor, and Servo Motor
by faaathimaa053 in Circuits > Arduino
18 Views, 0 Favorites, 0 Comments
Obstacle Avoiding Robot Using Arduino, L298N, Ultrasonic Sensor, and Servo Motor
In this project, I built an autonomous obstacle-avoiding robot using an Arduino Uno, an HC-SR04 ultrasonic sensor, a servo motor, an L298N motor driver, and two DC motors. The robot can move forward on its own, detect obstacles in its path, scan the surroundings using a rotating ultrasonic sensor, and choose the clearest direction to continue moving.
Supplies
SUPPLIES
Arduino Uno
L298N Motor Driver
HC-SR04 Ultrasonic Sensor
SG90 Servo Motor
2 DC Geared Motors
Robot Chassis
Wheels
Castor Wheel
12V Battery
Jumper Wires
Gather the Components
Before starting, collect all the required components:
- Arduino Uno
- L298N Motor Driver
- HC-SR04 Ultrasonic Sensor
- SG90 Servo Motor
- 2 DC Geared Motors
- Robot Chassis
- Wheels
- Castor Wheel
- 12V Battery
- Jumper Wires
Assemble the Chassis
Attach the DC motors to the robot chassis.
Fix the wheels to the motor shafts and install the castor wheel at the front or rear of the chassis to provide balance.
Mount the Arduino and L298N
Place the Arduino Uno and L298N motor driver on the chassis.
Use screws, zip ties, or double-sided tape to secure them.
Leave enough space for wiring and battery placement.
ULTRASONIC SENSOR
Fix the HC-SR04 ultrasonic sensor to the servo horn.
This allows the sensor to rotate and scan the environment in multiple directions.
Make sure the sensor is facing forward when the servo is at 90°.
Connect the Motors to the L298N
Connect:
- Left Motor → OUT1 and OUT2
- Right Motor → OUT3 and OUT4
Wire the L298N to the Arduino
Connect:
- IN1 → D2
- IN2 → D3
- IN3 → D4
- IN4 → D5
- ENA → D6
- ENB → D11
These connections allow the Arduino to control the speed and direction of both motors
Connect the Ultrasonic Sensor AND Servo Motor
Wire the HC-SR04 as follows:
- VCC → 5V
- GND → GND
- TRIG → D9
- ECHO → D10
This sensor is responsible for detecting obstacles.
Wire the servo:
- Signal → D8
- VCC → 5V
- GND → GND
The servo will rotate the ultrasonic sensor to scan left and right.
Connect the Power Supply
Wire the HC-SR04 as follows:
- VCC → 5V
- GND → GND
- TRIG → D9
- ECHO → D10
- This sensor is responsible for detecting obstacles.
Ensure all grounds are connected together:
- Arduino GND
- L298N GND
- Servo GND
- Ultrasonic Sensor GND
A common ground is essential for proper operation.
Upload Code to Aurduino
Open the Arduino IDE.
Select the correct board and COM port.
Upload the obstacle-avoidance code to the Arduino Uno.
After uploading, disconnect the USB cable and power the robot using the battery.
Test the Robot
Place the robot on a flat surface.
Observe the following sequence:
- Robot moves forward.
- Obstacle is detected.
- Servo scans right.
- Servo scans left.
- Robot compares both distances.
- Robot turns toward the clearer path.
- Robot continues moving.
Adjust motor speed and obstacle distance thresholds if required.