Arduino HC-SR04 Ultrasonic Rover





Introduction: Arduino HC-SR04 Ultrasonic Rover

Simple Arduno Rover with HC-SR04 Ultrasonic sensor.

Step 1:

YOU will need to build this:

HC-SR04 Ultrasonic sensor

Battery holder for 6 AA batteries

6 AA batteries

Arduino UNO (I use UNO R2)
Motor Shield for Arduino (L293)

9g Servo

2 gear motors with wheels

CD box

4 male-to-male cables

4 female-to-female cables

few cable ties

I buy all components for this rover on ebay.

First you will need 2pcs Plastic Tire Wheel + DC 6V Gear Motor 48:1.

I solder 2 male-to-male cables and 104 capacitors.

I used slim CD box as a chassis, I made 2 holes on each side of CD box and then fixed gear motors with cable tie.

Step 2:

You can see all the components you need on this photo.

  1. HC-SR04 Ultrasonic sensor
  2. Battery holder for 6 AA batteries
  3. 6 AA batteries
  4. Arduino UNO (I use UNO R2)
  5. Motor Shield for Arduino (L293)

  6. 9g Servo
  7. 2 gear motors with wheels on CD box chassis.
  8. 4 male-to-male cables
  9. 4 female-to-female cables
  10. few cable ties

Step 3:

Сonnection scheme is very easy.

  1. Connect 9g servo to SERVO_2 pins on motorshield
  2. Left motor to M4
  3. Right motor to M1
  4. Echo - pin A4
  5. Trig - pin A5
  6. Vcc - pin +5 ; Gnd - Gnd

I fix servo on battery box with cable tie

Step 4:

Final result and video.

Faster version without servo

Step 5:

Put AFMotor.h and AFMotor.cpp to folder AFMotor in libraries folder Aduino.

2 People Made This Project!


  • Space Challenge

    Space Challenge
  • Microcontroller Contest

    Microcontroller Contest
  • Spotless Contest

    Spotless Contest

We have a be nice policy.
Please be positive and constructive.




hello I have made it but it couldn't work. when I operate it the servo once starts and then stops


it only means that you did not follow all the direction carefully...

I make the connections correctly but still it goes crazy, the servant stays looking to one side and goes forward and back without stopping other times it seems to work well but then it goes back malfunctioning.

Hi, i've seen the codes guy's i need a code of ultrasonic sensor to stop the object on which it's implemented after sensing the obstacle can anyone help?

I checked the code it will not compile :(

Ок, I uploaded correct version of the code. It works. Try it.

Okay looks good it compiles okay. I will let you know how it turns out. I am waiting for another HC-SR04. You might want to mention they will need to install the NewPing library. You can find it here -->

Thanks for sharing !


Can i have circuit diagram for this project?



The Ultrasonic sensor doesn't work for me when I connect it to pins A4,A5 in the MotorShield board. Can anyone explain me how does it make sense to use them, if they are "Analog In" pins, wheras the UltraSonic sensor requires "Digital In" & "Digital Out" pins ?!