HC-SR04 Ultrasonic Sensor Simple Project

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? :confused:

What does the serial debug look like?

AWOL:
What does the serial debug look like?

What do you mean? I started using arduino yesterday. I am somehow newbie with some 'keywords' :confused:

xmarkx:

AWOL:
What does the serial debug look like?

What do you mean? I started using arduino yesterday. I am somehow newbie with some 'keywords' :confused:

So who has been posting on your account for the last three weeks? :wink:

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

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! :slight_smile: Sorry for the 'idiotic' questions/answers...

I am using this Download Processing / Processing.org.

  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? :confused: or its waste of time?

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

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? :confused:

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

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

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?

Did that. -1 indicates that range is out of bounds. Take a look

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.

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 :slight_smile: then it sounds like the problem could be hardware - either the sensor or the connections between it and the Arduino.

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

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

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