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.

Advertisement

<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="http://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>
<p>Thanks</p><p>To bad it don't work here. One motor refuses to work ?!</p>
<p>Annoying that the code is in rtf-format, plain Chinese would have been nicer.</p>
<p>I try to make this, but I cannot upload the codes. some errors are coming... ? how can I add NewPing.h libry? if I an using L298N H bridge for motors, instead of motor shield how the codes should change ? </p>
gooooooooood
<p>Hi, Nice robot. did you have any problems with spiking results from the ultrasonics?</p><p>I rotate mine at 15 degree intervals reading in both directions. giving me 7 values 15 degrees apart. But I get two things happen, odd spikes and swapping values, for eg:</p><p>4 5 8 15 17 21 9</p><p>3 5 7 35 18 21 8</p><p>4 4 7 14 16 3 9</p><p>4 6 9 34 17 22 7</p><p>Notice the center values swapping without the bot moving 15 35 14 34 ??</p><p>Also 2nd last column 21 21 3 22 Where did the 3 come from.</p><p>The code is simple, I have been a code cutter for years so I am no stranger to debugging.</p><p>Only this one has the better off me so far.</p><p>Any ideas</p><p>Cheers</p>
<p>Nice Job!!! 2 Things:</p><ol><li> You can use a 9V battery pack (less weight, less space)<li>If the code wont compile even with the NewPing code you need to install the Adafruit motor shield library Link: <a href="http://learn.adafruit.com/adafruit-motor-shield/library-install" rel="nofollow">http://learn.adafruit.com/adafruit-motor-shield/library-install</a> </ol>

About This Instructable

117,626views

430favorites

License:

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