Hello,
I have tried ever different code I could find that demonstrates how to simply program a HC-SR04 Ultrasonic sensor. I have tried codes with and without the NewPing Library, I have copied and pasted other people's code to test it out, I have tried buying a new sensor, I have tried new wires, I look around and see everyone who had a problem with it has had it solved but I cannot get mine to work. The only values I get, which depends on what code I use is either 0 cm or 1149 cm. I have tried different computers, I have the newest version of Arduino IDE and the included NewPing library. Please someone help.
EDIT: I am using an Arduino Uno from the Starter Pack
sketch_aug07a.ino (1.13 KB)
I hooked up a HCSR04 ultrasonic rangefinder to my Uno and ran the NewPingExample from the NewPing library. Code worked fine. Then I tried the code that you posted. It printed out reasonable ranges. So I have to conclude that it is a hardware problem.
What is the measured supply voltage at the sensor?
Are you sure that the trigger and echo pins to which the sensor is connected match the code?
It may help if you post a photo of your wiring. Posting images
How to post an image.
Another page on posting images.
Hello,
I can assure you the wiring is correct. But I do not have a voltmeter to measure voltage at the sensor unfortunately. It is supplied by the 5v pin and is connected to my computer. Here is the wiring in these pictures. Black is ground, purple is 5V, white is Echo, and grey is Trig. My Uno works with an IR sensor just fine. I have tried two different Ultrasonic sensors which I bought from Amazon.
Your image, posted properly.
I can assure you the wiring is correct.
We are sure that you think so, but will continue to have doubts. You forgot to tell us which Arduino pins you connected to Echo and Trig.
Wires and connectors can be bad (open circuit), and there can be short circuits (solder blobs) between adjacent pins. Get a decent multimeter, so that you can measure voltages, resistance and check continuity. It is an essential tool.