loading

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        http://youtu.be/hBHpOV5TOY8

Step 5:

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

hello I have made it but it couldn't work. when I operate it the servo once starts and then stops
<p>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?</p>
<p>I checked the code it will not compile :(</p>
<p>Ок, I uploaded correct version of the code. It works. Try it.</p>
<p>where is the code</p>
<p>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 --&gt; <a href="http://forum.arduino.cc/index.php?topic=106043.0" rel="nofollow">http://forum.arduino.cc/index.php?topic=106043.0</a></p><p>Thanks for sharing !</p>
<p>Hi,</p><p>Can i have circuit diagram for this project?</p><p>Thanks</p>
<p>Hi, </p><p>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 &quot;Analog In&quot; pins, wheras the UltraSonic sensor requires &quot;Digital In&quot; &amp; &quot;Digital Out&quot; pins ?! </p>
<p>pinMode(pinTrig, OUTPUT);</p><p>pinMode(pinEcho, INPUT);</p><p> thise for configuration </p><p>-----</p><p>digitalWrite(pinTrig, LOW);</p><p>digitalWrite(pinTrig, HIGH);</p><p>digitalWrite(pinTrig, LOW);</p><p>duration=pulseIn(pinEcho,HIGH);</p><p>distance=(duration/2)*Vson;</p><p> Serial.print(distance);</p><p> Serial.println(&quot;cm&quot;);</p><p>and this on for mesur distance (#define Vson 0.034 // cm/us)</p>
<p>i tried this but my bot keeps circling. i didnt change the code and followed each and every instruction properly. please help</p>
hey pleasee help earliest mine isnt working it just keeps on rotating i have to submit it by tommorrow help help help<br>i have<br> arduino ide 1.6.9<br>arduino uno rev3<br>afmotorsheild is same using 12v and 1ah<br>hcsro4 <br>heeellllp<br><br>
<p>well done</p>
<p>please van you send me a code without the sensor ?</p>
<p>Hi. Great job! I will try it. Would it work with <a href="http://www.aliexpress.com/item/HG7881-HG7881CP-2-Channel-Motor-driver-board-Motor-drive-module/1927809643.html" rel="nofollow">Hg7881 HG7881CP</a>? I already boutht it</p>
<p>a</p><p>Hi guys, I would like to ask on how to stabilize my ultrasonic sensor mounted in a servo motor. It is because everytime an &quot;Out of Range&quot; displays in the serial monitor it gives current to the servo motor causing it to sweep. The possibility of sweeping the servo left or right only is when there is an object being detected. BTW, the ultrasonic sensor is mounted above the servo mtor. </p><p>Here is my code://</p><p>#define trigPin 13</p><p>#define echoPin 12</p><p>#define led 11</p><p>#define led2 10</p><p>#include &lt;Servo.h&gt;</p><p>int pos = 0; // variable to store the servo position </p><p>int defPOS = 0; </p><p>Servo myservo;</p><p>void setup() {</p><p>Serial.begin (9600);</p><p>pinMode(trigPin, OUTPUT);</p><p>pinMode(echoPin, INPUT);</p><p>pinMode(led, OUTPUT);</p><p>pinMode(led2, OUTPUT);</p><p>myservo.attach(9);</p><p>myservo.write(0);</p><p>}</p><p>void loop() {</p><p>long duration, distance;</p><p>digitalWrite(trigPin, LOW); // Added this line</p><p>delayMicroseconds(2); // Added this line</p><p>digitalWrite(trigPin, HIGH);</p><p>// delayMicroseconds(1000); - Removed this line</p><p>delayMicroseconds(10); // Added this line</p><p>digitalWrite(trigPin, LOW);</p><p>duration = pulseIn(echoPin, HIGH);</p><p>distance = (duration/2) / 29.1;</p><p>//0 Left</p><p>//1 Center</p><p>//2 Right</p><p>int buttonState1 = digitalRead(led); //red</p><p>int buttonState2 = digitalRead(led2); //green</p><p>if( (buttonState1 == 0 &amp;&amp; buttonState2 == 1) &amp;&amp; (defPOS != 1))</p><p>{</p><p>delay(2000);</p><p>if(defPOS == 2)</p><p>{</p><p>for(pos = 0; pos &lt;= 90; pos += 1) // goes from 0 degrees to 180 degrees </p><p>{ // in steps of 1 degree </p><p>myservo.write(pos); // tell servo to go to position in variable 'pos' </p><p>delay(2); // waits 15ms for the servo to reach the position </p><p>}</p><p>}</p><p>else if(defPOS == 0)</p><p>{</p><p>for(pos = 0; pos &lt;= 90; pos += 1) // goes from 0 degrees to 180 degrees </p><p>{ // in steps of 1 degree </p><p>myservo.write(pos); // tell servo to go to position in variable 'pos' </p><p>delay(2); // waits 15ms for the servo to reach the position </p><p>}</p><p>}</p><p>defPOS = 1;</p><p>}</p><p>if (distance &lt; 30) { // This is where the LED On/Off happens</p><p>digitalWrite(led,HIGH); // When the Red condition is met, the Green LED should turn off</p><p>digitalWrite(led2,LOW);</p><p>if(defPOS == 0)</p><p>{</p><p>for(pos = 90; pos&gt;=0; pos-=1) // goes from 180 degrees to 0 degrees </p><p>{ </p><p>myservo.write(pos); // tell servo to go to position in variable 'pos' </p><p>delay(2); // waits 15ms for the servo to reach the position </p><p>}</p><p>defPOS = 2;</p><p>}</p><p>else if(defPOS == 2)</p><p>{</p><p>for(pos = 0; pos &lt;= 90; pos += 1) // goes from 0 degrees to 180 degrees </p><p>{ // in steps of 1 degree </p><p>myservo.write(pos); // tell servo to go to position in variable 'pos' </p><p>delay(2); // waits 15ms for the servo to reach the position </p><p>}</p><p>defPOS = 1; </p><p>}</p><p>else if(defPOS == 1)</p><p>{</p><p>for(pos = 0; pos &lt;= 180; pos += 1) // goes from 0 degrees to 180 degrees </p><p>{ // in steps of 1 degree </p><p>myservo.write(pos); // tell servo to go to position in variable 'pos' </p><p>delay(2); // waits 15ms for the servo to reach the position </p><p>}</p><p>defPOS = 0; </p><p>}</p><p>//myservo.write(180);</p><p>// delay(1000);</p><p>//myservo.write(0);</p><p>}</p><p>else {</p><p>digitalWrite(led,LOW);</p><p>digitalWrite(led2,HIGH);</p><p>}</p><p>if (distance &gt;= 400 || distance &lt;= 0){</p><p>Serial.println(&quot;Out of range&quot;);</p><p>}</p><p>else {</p><p>Serial.print(distance);</p><p>Serial.println(&quot; cm&quot;);</p><p>}</p><p>delay(500);</p><p>}</p>
<p>i want the full code the code u posted is only of the ultrasonic sensor and servo... what about the motors?can u plz help me thanks in advance</p>
<p>Hi, I have a question I would like to explain to me how and where I can change the speed and distance detection do not quite understand because the instructions are in the program, thank you.</p>
<p>How does the robot stay in balance with only 2 wheels? Or does it have something else like a ball caster or so?</p>
<p>Can someone please help me with coding on Arduino</p><p>Im new to coding and robotics and I built a biped robot with 4 servos and a HC-SRO4 servo for object avoidance. Im using Arduino uno and I only know how to make the servos move with write.microseconds. I want to make it avoid objects and be autonomous. </p>
<p>can u help me. I cannot find A4 on the motor driver shield can u show me a daigram</p>
<p>you need to soldering a header to pin A0-A5 on Driver motor shield. Sorry for my bad english</p>
<p>mas andy,,punya saya ko cuma maju mundur yah??ada yg salah kah,,saya pakai servo sg90</p>
<p>What is the difference between turnRight()/Left and veerRight()/Left?</p>
<p>Hi! Do you have an AFMotor.cpp that works? The one I downloaded from here gives me a bunch of compile errors about stray '/' and '{rtf...}'</p>
<p>i download afmotor.h library but giving error &quot; afmotor.h no such file or directory&quot; why, please help ?</p>
<p>I was wondering if you have a tutorial on how you soldered A4 and A5 from the Arduino to the motor shield.</p>
I made it..But I don't have a servo... Sadly...I don't have the idea of programing as well..Could you pls leave the programming code in the comments so that I can copy it and upload in my arduino...One more request...leave the programming code with the same pins....<br>
<p>in the code it says no file or directory such as new ping.h .so should i download the ping library</p>
<p>yes</p>
<p>Cool, this realy fun... thanks for tutorial...</p>
<p>How Can I Contact With You?</p>
<p>muhandi.prasetyo@gmail.com</p>
<p>i want to replace arduino with pic18f4520..help me with code plzz!!</p>
<p>i want to replace arduino with pic18f4520..help me with code plzz!!</p>
<p>i want to replace arduino with pic18f4520..help me with code plzz!!</p>
<p>Any way to incorporate 2 more wheels into the code? or would that just complicate things? I have two more gear boxes and wheels and would like to add them, but im not sure how the turning would work...</p>
<p>Hi I want to build a similar kind of Robot. But I dont ve the Arduino Shield. But I ve got the L293D IC. Can I use the above mentioned code to make my Robot work. if yes will you please help me in the Arduino-293d pin configuration. Thanks in Advance.</p>
I built the same project .....but this is not run proprly.....what i do ....all the connnection is same as yours
Or give me the link 2 buy
What type of servo you used is it continous rotation
<p>can i use l293b???</p>
<p>hi there, i have completed a line follower robot, but i want to combine with he coding of HC-SR04 for stopping the robot. i use the same adafruit motor driver L293D..kindly seeking your help..tq</p>
<p>function void checkPath() { .......</p><p>........... line 67 <a href="https://www.instructables.com/files/orig/FHU/E8NL/HTOQ8LBB/FHUE8NLHTOQ8LBB.ino" rel="nofollow">ROBOT.ino</a></p><p>if (curDist &gt; curDist) {maxAngle = pos;} </p><p>//what is the condition?</p><br>
<p>Do you have the code without the servo?</p>
<p>excelente modelo y trabajo</p>
<p>Thank you for the code I tried to make something similar to this but I had trouble with the code and now it works!</p>
<p>hello I cannot download your code I get an error</p>
<p>here is ROBOT.ino</p>
<p>ok thanks </p>

About This Instructable

143,655views

438favorites

License:

More by Eagle199393:2.4" TFT LCD Touch Shield Arduino LED CUBE Arduino 5x5x5 Water cannon arduino robot IR 
Add instructable to: