|
Post by Tom on Aug 12, 2014 6:27:45 GMT -8
My Ultrasonic sensor program will only return a distance of 4 inches or less. I have been unable to determine the cause. I have set it up if different environments to make sure that is was not getting so odd reflection.
|
|
|
Post by 011235813 on Aug 12, 2014 21:27:46 GMT -8
Can you post the code?
|
|
|
Post by Tom on Aug 13, 2014 6:18:39 GMT -8
I used the code that I downloaded from this site for ultrasonic test. So, you can take a look on line.
|
|
jasea
Junior Member
Posts: 53
|
Post by jasea on Aug 13, 2014 22:46:04 GMT -8
Hi Tom, There are two code samples on the download site, which are you using, and have you made ANY changes to it? Also can you confirm that you have connected the Ultrasonic Sensor correctly: Pin VCC to +5V, Trig to Stem pin Digital 2 Echo to Stem pin Digital 4 Gnd to Stem Gnd.
When you say that the sensor only returns a distance of 4 inches or less, do you mean that it only detects an obstruction that is 4 inches or less away, or it returns a distance of 4 inches irrespective of how far away the object is.
|
|
|
Post by Tom on Aug 14, 2014 3:54:46 GMT -8
I used the sample titled Ultrasonic sensor test. I verified the leads for the sensor and they are correct. The sensor returns a maximum of 4 inches even if it is pointed at a wall 10 ft. away. I put a finger directly over the sensor and it returns an extremely high number as described in the directions. It appears to be functional but there something in the software calculation.
|
|
jasea
Junior Member
Posts: 53
|
Post by jasea on Aug 14, 2014 5:11:48 GMT -8
Hi again Tom, one more item to check, is the power switch on the STEM Board in the 5V position? if not then place it to this position and try your testing again. If it is, are you confident to change the code for the program "Ultrasonic sensor test " in the Arduino IDE? If so then change the last line in the void loop() function from delay(10); to delay(1000); This will slowdown the output to the terminal window to once a second.
Now you will need something flat and solid to reflect the ultrasound back to the receiver, I use a small wooden box. Whilst running the changed program and watching the terminal window move your object slowly away from the sensor. mine goes 1212in, 3092cm 1in, 3 cm at a distance of about ⅓ inch to 1 inch 2in, 5 cm at a distance of 5 CM
The accuracy is good at 10, 15 , 20, 25 and 30 CM
what do you get from your sensor?
|
|
|
Post by Tom on Aug 15, 2014 10:59:25 GMT -8
When I place the reflector against the sensor the reading is 1226 inches and when I move the reflector away from the sensor it will display 1,then 2, then 3, and then 4 and nothing above 4 even at 2 feet.
|
|
jasea
Junior Member
Posts: 53
|
Post by jasea on Aug 16, 2014 0:24:08 GMT -8
Hi Tom, Well I have had a look on the Web, but I can find no problems with the HC-SR04 like you describe. These devices either work or they don't. So assuming that it is not damaged, has been correctly installed in the bracket, then I guess that the sensor is faulty. One last test, try adding the following two lines of code after the line " duration = pulseIn(echoPin, HIGH); " in the ping() routine. This will print on the delay in microsecond between sending the pulse and receiving it back.
Serial.print("duration = "); Serial.println(duration);
I suspect that you will see a similar result to that when it is converted to inches, but this will eliminate the calculations from the problem, and confirm that the sensor is faulty. You can get them from most of the hardware shops and online at Amazon.
Do let us know what you find
|
|
|
Post by Tom on Aug 18, 2014 3:50:18 GMT -8
I inserted the lines and the duration displayed would go no higher than 619 with a distance of 4 inches. I am now sure it is the sensor so I will go look for a replacement. Thanks.
|
|
|
Post by Mel on Aug 20, 2014 15:13:10 GMT -8
Thanks, jasea for helping out with all the right checks!! @tom, email us at info@STEMCenterUSA.com and we can help you out with that replacement. Thanks! Melissa
|
|
|
Post by Tom on Aug 22, 2014 12:02:22 GMT -8
I got a replacement and installed it yesterday. Everything works perfectly now. The new sensor was a slightly different size but it fit and works. Thanks for all the help.
|
|
jasea
Junior Member
Posts: 53
|
Post by jasea on Aug 23, 2014 9:12:53 GMT -8
Hi Tom, Thank you for letting us know that you have solved your problem. Now you can start having FUN!
|
|
howie
New Member
Posts: 5
|
Post by howie on Dec 5, 2015 9:47:46 GMT -8
Glad to have found this. Mine was doing 2 inches (rarely 3). Found the exact same sensor on ebay for $0.99. Got 2.
Microcenter wanted $30.
|
|
jasea
Junior Member
Posts: 53
|
Post by jasea on Dec 6, 2015 1:15:43 GMT -8
Hi howie, Please let us know if the new sensor fixes your problem.
Regards
John
|
|
howie
New Member
Posts: 5
|
Post by howie on Dec 28, 2015 18:07:29 GMT -8
Yep. New sensor worked great. Ebay is a great place for cheap parts.
|
|