IntermediateRobotics
Obstacle-Avoiding Rover
Build a small two-wheel robot that drives forward and backs up/turns when its ultrasonic sensor sees an obstacle.
Parts from the database
- HC-SR04 ร 1Distance sensor
- L298N ร 1Dual H-bridge motor driver
- ATmega328P-PU ร 1Use on a compatible development board
Other supplies
- Arduino-compatible 5 V boardCommon build supply
- L298N motor-driver moduleCommon build supply
- two small geared DC motors and wheelsCommon build supply
- robot chassis and casterCommon build supply
- 4รAA battery holder for motorsCommon build supply
- separate USB supply for controller during testingCommon build supply
- jumper wiresCommon build supply
Amazon links may be affiliate links. As an Amazon Associate, Electronics Hobby Hub earns from qualifying purchases.
Connections
- For a common L298N module, connect Arduino D5 (PWM) to ENA, D6 to IN1, D7 to IN2, D3 (PWM) to ENB, D8 to IN3, and D11 to IN4. Confirm labels on your exact module.
- Connect motor outputs to the two geared motors. Feed motor supply through the module's rated input; remove/retain its regulator jumper according to the module manual.
- Connect HC-SR04 TRIG to D9 and ECHO to D10; share controller and driver grounds.
- Do not power motors from the Arduino 5 V pin. Keep a switch and suitable battery protection in the motor supply.
Build steps
- Raise the chassis so wheels are off the table; test each motor direction at low speed.
- Mount the sensor facing forward and confirm the distance reading while stationary.
- Load the sketch and set a conservative obstacle distance such as 25 cm.
- Test on an open floor at low speed, then tune turn time and threshold. Add a physical power switch.
Software and firmware setup
Firmware is required, but a complete rover sketch is not included yet. Implement the six-pin L298N motor mapping and HC-SR04 distance measurement described in this guide. Verify each motor direction with the wheels lifted before floor testing.
Test your build
The rover should stop, reverse briefly, turn, and continue when an obstacle is detected. Test with the wheels lifted before floor testing.
Troubleshooting
- If motors fight each other, one motor's wires may need reversing or the IN pin mapping is wrong.
- If the controller resets when motors start, separate supplies and improve common-ground routing; add motor suppression as appropriate.
- If range readings jump, keep motor wires away from ECHO/TRIG and average several measurements.
Safety and limitations
Keep wheels off the ground during first tests, secure loose hair/clothing, and use a low-voltage battery pack. Never use the robot near stairs, roads, pets, or people at speed.
Manufacturer and platform documentation
Community Notes for This Project
These are unverified visitor contributions, separate from the build guide and manufacturer specifications. Verify technical advice against the linked datasheets before relying on it.
Set up the comments service to load community notes.