Pages: [1]   Go Down
Author Topic: HC-SR04 Ultrasonic Sensor Simple Project  (Read 193 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi I am trying to do this project from http://arduinobasics.blogspot.gr/2012/11/arduinobasics-hc-sr04-ultrasonic-sensor.html?showComment=1399056576259#c2818655084083635801

I did everything as shown and the result is the image below. When i hover my hand in the sensor nothing happens...what am i doing wrong? :/


* project.png (702.16 KB, 3840x1080 - viewed 12 times.)

* DSC00633.jpg (725.67 KB, 2592x1944 - viewed 9 times.)

* DSC00637.jpg (678.79 KB, 2592x1944 - viewed 5 times.)

* DSC00634.jpg (550.22 KB, 2592x1944 - viewed 7 times.)
« Last Edit: May 02, 2014, 02:32:11 pm by xmarkx » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 286
Posts: 25678
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What does the serial debug look like?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What does the serial debug look like?
What do you mean? I started using arduino yesterday. I am somehow newbie with some 'keywords' :/
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 286
Posts: 25678
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What does the serial debug look like?
What do you mean? I started using arduino yesterday. I am somehow newbie with some 'keywords' :/
So who has been posting on your account for the last three weeks?   smiley-wink

Serial debug is the result of the serial prints in your sketch, when viewed on the serial monitor.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was! But the projects i did and the questions i asked didnt contain every keyword that is relative with arduino...I am still learning man! smiley Sorry for the 'idiotic' questions/answers...

I am using this https://www.processing.org/download/.

1. I copy paste the code.
2. I saved to a file
3. Clicked on run.

the result is in the image above. I have double monitors so whatever you see I see. There is no output on the IDE that you are missing. btw if you cannot come up with something, whats the best way of debugging here?

Should I try debuging like I do in C language? :/ or its waste of time?

Logged

Online Online
God Member
*****
Karma: 48
Posts: 671
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi xmarkx

The Arduino Basics website page has two programs: one to run on the Arduino and the other to run on your PC.  You need both working together and communicating for the project to work overall.

The PC one uses the Processing language and you posted the link to Processing.  And from your screenshot, it looks like that program is running.

But have you taken the Arduino program from the Arduino Basics website and put that on your Arduino , using the Arduino IDE?

Cheers

Ray
Logged

Hackscribble.  Writing about making things.
arduino@hackscribble.com | www.hackscribble.com

Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey, well I feel like idiot. I just understood why there are two parts of code. Its clear now what to do. I uploaded tot he arduino the code. Then I pressed run on the processing IDE and the result still remain the same. The only thing I changed Is the COM8 to COM3 caz my arduino is in COM3. Is that wrong? :/
Logged

Online Online
God Member
*****
Karma: 48
Posts: 671
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Just to check, the Arduino program compiles OK?  And when you upload to your Arduino, the IDE says at the end "Done uploading"?

If so, the program has loaded into the Arduino OK and the COM port choice is OK.

Now, what AWOL was suggesting was to use the serial monitor in the Arduino IDE to look at the output from the program.  Don't run the Processing program, just the serial monitor.

Try the hardware again and see if any data appears on the monitor.  This is the data that will be read by the Processing program, so this helps to work out where the problem is: Arduino or Processing.

Cheers

Ray
Logged

Hackscribble.  Writing about making things.
arduino@hackscribble.com | www.hackscribble.com

Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok now everything is more clear. Here is some info.

As you can see in the images the result is -1 at the serial monitor without running the other IDE.
It says done uploading...
When I have opened serial monitor I can not run the Processing IDE. Dunno I this is normal or not, I just mention it.

thats all i have...hope it helps and thanks for your time guys, appreciate it. you are the fastest forum ever...


* -1.PNG (24.74 KB, 546x397 - viewed 5 times.)

* result.PNG (69.82 KB, 994x648 - viewed 6 times.)
Logged

Online Online
God Member
*****
Karma: 48
Posts: 671
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, so I think your next step should be to look through the Arduino program to see whether -1 is an expected value and what it means.

If you wave your hand in front of the sensor, does the -1 change to anything different?
Logged

Hackscribble.  Writing about making things.
arduino@hackscribble.com | www.hackscribble.com

Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Did that. -1 indicates that range is out of bounds. Take a look
Code:
if (distance >= maximumRange || distance <= minimumRange){
 /* Send a negative number to computer and Turn LED ON
 to indicate "out of range" */
 Serial.println("-1");
 digitalWrite(LEDPin, HIGH);
 }

while I watch at the serial monitor i wave my hand and no nothing happens. It keep showing -1.

PS. I am currently not using the processing IDE. I am working and trying to debug only on arduino IDE. So everything i said is about the arduino IDE.
Logged

Online Online
God Member
*****
Karma: 48
Posts: 671
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, understand.  And if you put your hand about 30cm or 60cm away from the sensor, still no change?

Assuming that the Arduino program has been tested and works before it was put on the website :-) then it sounds like the problem could be hardware - either the sensor or the connections between it and the Arduino.
Logged

Hackscribble.  Writing about making things.
arduino@hackscribble.com | www.hackscribble.com

Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

-1 always... this is my sensor http://www.ebay.com/itm/181227585127?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649. Um I was waiting 1.5 month and now its not working? Oh man... smiley-sad

I hope my jumpers are wrong placed!!! But they are just 4 wires over there...quite simple.
Logged

Online Online
God Member
*****
Karma: 48
Posts: 671
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If the hardware looks OK, then only thing I can think to do is try another program that is meant to work with the sensor and see what it does.

There is a software library for Arduino called NewPing.  Search on this site for it and then add it to your Arduino IDE = the instructions are here: http://arduino.cc/en/Guide/Libraries

Close down Arduino IDE and start it again.  Look under File - Samples and search for NewPing example programs.  I think there must be a simple one that writes to the serial monitor.

If you do try this, check in the new sample program to see which pins it uses to connect to the sensor - it may not be the same as your current program.

Good luck!

Ray
Logged

Hackscribble.  Writing about making things.
arduino@hackscribble.com | www.hackscribble.com

Pages: [1]   Go Up
Jump to: