Build an Obstacle-Avoiding Robot
A 2-wheel robot that drives forward and turns away when the HC-SR04 senses an obstacle within 20 cm. Uses Arduino Uno + L298N + BO motors — the canonical starter robotics project for engineering and diploma students.
Materials
- Arduino Uno R3
- L298N motor driver
- 2 × BO gear motors + wheels
- 2WD chassis + caster wheel
- HC-SR04 ultrasonic sensor
- 9 V battery + connector
- Jumper wires
Tools
- Arduino IDE
- Screwdriver
- Double-sided tape
Step-by-step guide
- 1
Assemble chassis
Fix motors to chassis, wheels to motor shafts, caster wheel at the front, Arduino + L298N on top with double-sided tape.
- 2
Wire motors to L298N
Motor 1 to OUT1/OUT2, Motor 2 to OUT3/OUT4. IN1–IN4 to Arduino pins 5, 6, 10, 11. ENA/ENB jumpers on.
- 3
Wire HC-SR04
VCC → 5V, GND → GND, TRIG → pin 9, ECHO → pin 8. Mount facing forward.
- 4
Power
9 V battery → L298N 12V input + GND. Jumper the 5V regulator; L298N will feed 5V back to Arduino VIN.
- 5
Upload logic
If distance > 20 cm → drive forward. Else → stop, reverse briefly, turn right, resume.
FAQs
My motors run in the wrong direction — how do I fix?
Swap the two wires going into OUT1/OUT2 (or OUT3/OUT4) on the L298N.
The robot restarts randomly — why?
Battery voltage dips when motors start. Use a 9 V rechargeable or two 18650 Li-ion cells in series.
Everything you need in one box
This project is fully covered by the Advanced Development Kit.
View kit
