Obstacle-Avoiding Rover with Ultrasonic HC-SR04
Construct a 2-wheel drive autonomous rover that scans its surroundings with an ultrasonic distance sensor on a mini servo and navigates rooms without bumping into obstacles.
An essential milestone project for every robotics engineer! This mobile robot features a 2WD acrylic chassis, dual DC gearmotors with an H-Bridge driver, and an ultrasonic distance scanner mounted on an SG90 servo. The microcontroller measures distances, looks left and right when an obstacle is detected, and steers into the clearest path.
Bill of Materials (BOM) & Components
| Component | Specifications | Qty | Estimated Cost |
|---|---|---|---|
| 2WD Smart Robot Chassis Kit | Acrylic base, 2x TT yellow gearmotors, 2 wheels, 1 caster wheel | 1 | $12.00 |
| Arduino Uno or Nano | ATmega328P microcontroller running obstacle avoidance algorithm | 1 | $6.00 |
| TB6612FNG or L298N Motor Driver Module | Dual H-Bridge to drive left and right DC gearmotors | 1 | $4.00 |
| HC-SR04 Ultrasonic Sensor + SG90 Servo Bracket | Rotates sensor 180° to scan left/right before turning | 1 | $4.50 |
| 2x 18650 Li-ion Battery Holder (7.4V) or 4x AA Battery Pack | Power source with master ON/OFF toggle switch | 1 | $4.00 |
Electrical & Architecture Summary
Arduino PWM pins control Left/Right motor direction and speed on the driver. HC-SR04 is mounted on the SG90 servo. 7.4V battery pack powers motors directly with a 5V regulated feed to the Arduino.
Step-by-Step Assembly & Configuration
Chassis & Gearmotor Assembly
Mount the dual TT gearmotors to the acrylic chassis plate using the included metal brackets. Push on the rubber wheels and bolt the front swivel caster wheel.
- Solder 100nF ceramic capacitors across motor terminals to suppress brush electrical noise.
- Attach red and black stranded hookup wires to each motor.
- Secure battery holder to the bottom plate for low center of gravity.
Mounting the Pan-Scanning Sensor Tower
Mount the SG90 servo upright at the front center of the top chassis plate. Attach the HC-SR04 sensor bracket to the servo horn.
- Zero the servo at 90° (facing straight ahead) before fixing the bracket with the central screw.
- Route sensor jumper wires loosely so they do not tangle during 180° pan rotations.
Wiring Motor Driver and Microcontroller
Connect motor outputs to the driver terminals, and interface driver logic pins (IN1, IN2, IN3, IN4, ENA, ENB) to the microcontroller digital pins.
- Connect Arduino Pins: IN1 -> D4, IN2 -> D5, IN3 -> D6, IN4 -> D7.
- Connect Servo Signal -> D11, HC-SR04 Trig -> D12, Echo -> D13.
- Verify common ground between battery pack, motor driver, and Arduino GND.
Uploading Navigation & Obstacle Scanning Code
Flash the navigation state machine: Drive forward -> Detect obstacle (<20cm) -> Stop & Reverse -> Look Left -> Look Right -> Compare distances -> Turn into clearer side.
- Test motor rotational directions: verify forward command drives both wheels forward.
- Place rover on floor and test reaction to furniture and walls.