loading
Picture of Arduino HC-SR04 Ultrasonic Rover

Simple Arduno Rover with HC-SR04 Ultrasonic sensor.

Step 1:

Picture of
P1050658.JPG
P1050660.JPG

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.

 
1-40 of 49Next »
ahnaf.rafid.37 months ago

can u help me. I cannot find A4 on the motor driver shield can u show me a daigram

you need to soldering a header to pin A0-A5 on Driver motor shield. Sorry for my bad english

mas andy,,punya saya ko cuma maju mundur yah??ada yg salah kah,,saya pakai servo sg90

What is the difference between turnRight()/Left and veerRight()/Left?

marciokoko8 days ago

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...}'

byç212 days ago

i download afmotor.h library but giving error " afmotor.h no such file or directory" why, please help ?

marciokoko16 days ago

I was wondering if you have a tutorial on how you soldered A4 and A5 from the Arduino to the motor shield.

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....
EdizonBlu5 months ago

a

Hi guys, I would like to ask on how to stabilize my ultrasonic sensor mounted in a servo motor. It is because everytime an "Out of Range" 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.

Here is my code://

#define trigPin 13

#define echoPin 12

#define led 11

#define led2 10

#include <Servo.h>

int pos = 0; // variable to store the servo position

int defPOS = 0;

Servo myservo;

void setup() {

Serial.begin (9600);

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

pinMode(led, OUTPUT);

pinMode(led2, OUTPUT);

myservo.attach(9);

myservo.write(0);

}

void loop() {

long duration, distance;

digitalWrite(trigPin, LOW); // Added this line

delayMicroseconds(2); // Added this line

digitalWrite(trigPin, HIGH);

// delayMicroseconds(1000); - Removed this line

delayMicroseconds(10); // Added this line

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance = (duration/2) / 29.1;

//0 Left

//1 Center

//2 Right

int buttonState1 = digitalRead(led); //red

int buttonState2 = digitalRead(led2); //green

if( (buttonState1 == 0 && buttonState2 == 1) && (defPOS != 1))

{

delay(2000);

if(defPOS == 2)

{

for(pos = 0; pos <= 90; pos += 1) // goes from 0 degrees to 180 degrees

{ // in steps of 1 degree

myservo.write(pos); // tell servo to go to position in variable 'pos'

delay(2); // waits 15ms for the servo to reach the position

}

}

else if(defPOS == 0)

{

for(pos = 0; pos <= 90; pos += 1) // goes from 0 degrees to 180 degrees

{ // in steps of 1 degree

myservo.write(pos); // tell servo to go to position in variable 'pos'

delay(2); // waits 15ms for the servo to reach the position

}

}

defPOS = 1;

}

if (distance < 30) { // This is where the LED On/Off happens

digitalWrite(led,HIGH); // When the Red condition is met, the Green LED should turn off

digitalWrite(led2,LOW);

if(defPOS == 0)

{

for(pos = 90; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees

{

myservo.write(pos); // tell servo to go to position in variable 'pos'

delay(2); // waits 15ms for the servo to reach the position

}

defPOS = 2;

}

else if(defPOS == 2)

{

for(pos = 0; pos <= 90; pos += 1) // goes from 0 degrees to 180 degrees

{ // in steps of 1 degree

myservo.write(pos); // tell servo to go to position in variable 'pos'

delay(2); // waits 15ms for the servo to reach the position

}

defPOS = 1;

}

else if(defPOS == 1)

{

for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees

{ // in steps of 1 degree

myservo.write(pos); // tell servo to go to position in variable 'pos'

delay(2); // waits 15ms for the servo to reach the position

}

defPOS = 0;

}

//myservo.write(180);

// delay(1000);

//myservo.write(0);

}

else {

digitalWrite(led,LOW);

digitalWrite(led2,HIGH);

}

if (distance >= 400 || distance <= 0){

Serial.println("Out of range");

}

else {

Serial.print(distance);

Serial.println(" cm");

}

delay(500);

}

nik raikar5 months ago

in the code it says no file or directory such as new ping.h .so should i download the ping library

yes

fansblink made it!7 months ago

Cool, this realy fun... thanks for tutorial...

andy.jpg
BeO2 fansblink5 months ago

How Can I Contact With You?

fansblink BeO25 months ago

muhandi.prasetyo@gmail.com

gadge_s6 months ago

i want to replace arduino with pic18f4520..help me with code plzz!!

gadge_s6 months ago

i want to replace arduino with pic18f4520..help me with code plzz!!

gadge_s6 months ago

i want to replace arduino with pic18f4520..help me with code plzz!!

gadge_s6 months ago

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...

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.

vishj6 months ago
I built the same project .....but this is not run proprly.....what i do ....all the connnection is same as yours
prash287 months ago
Or give me the link 2 buy
prash287 months ago
What type of servo you used is it continous rotation

can i use l293b???

pesogebra9 months ago

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

vladimirkl19 months ago

function void checkPath() { .......

........... line 67 ROBOT.ino

if (curDist > curDist) {maxAngle = pos;}

//what is the condition?


Do you have the code without the servo?

excelente modelo y trabajo

Thank you for the code I tried to make something similar to this but I had trouble with the code and now it works!

mb641 year ago

hello I cannot download your code I get an error

Eagle199393 (author)  mb641 year ago

here is ROBOT.ino

ok thanks

Thanks

To bad it don't work here. One motor refuses to work ?!

E3D31 year ago

Annoying that the code is in rtf-format, plain Chinese would have been nicer.

moek001 year ago

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 ?

gholam1 year ago
gooooooooood
b101011 year ago

Hi, Nice robot. did you have any problems with spiking results from the ultrasonics?

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:

4 5 8 15 17 21 9

3 5 7 35 18 21 8

4 4 7 14 16 3 9

4 6 9 34 17 22 7

Notice the center values swapping without the bot moving 15 35 14 34 ??

Also 2nd last column 21 21 3 22 Where did the 3 come from.

The code is simple, I have been a code cutter for years so I am no stranger to debugging.

Only this one has the better off me so far.

Any ideas

Cheers

biomech751 year ago

Nice Job!!! 2 Things:

  1. You can use a 9V battery pack (less weight, less space)
  2. If the code wont compile even with the NewPing code you need to install the Adafruit motor shield library Link: http://learn.adafruit.com/adafruit-motor-shield/library-install
Eagle199393 (author)  biomech751 year ago

L293 drivers, 2 motors, servo consumes too much power for 9v battery. Using 9v batteries is waste of money. Only rechageable 9V are good, but I dont have one.

epaybot1 year ago

got an error with the code

1-40 of 49Next »