I am using a HC-SR 04 Ultrasonic Sensor and it is not responding as expected.
It gives a few readings at first and then does not respond at all.
I am using the NewPing Example code.
Please tell me is that a problem in the code or the sensor itself.
Paul_KD7HB:
How are you testing it? What readings do you expect?
Paul
I am using a serial monitor(PUTTY) and by connecting the sensor to my arduino nano and i expect to read the distance of the nearest object in front of the sensor.
Vulcan666:
Hi, I have used and tested an ultrasonic sensor before on my Arudino Uno. It should work fine for you on your board. I found this instructable to be very helpful:--
Try playing around with the code to get different results, such as letting it "see" further. Also, it might be easier if you didn't do the LED stuff and just connected your pins up, copied the code, took out the LED code, and ran it.
If you are still having issues don't hesitate to ask and I'll try to help you.
Okay, I tested it and got it working. I'll provide a new tutorial link, but don't listen to their code, but wire it up like they did. These modules a little unstable, and sometimes some of them will say like ocm or out of range even when it isn't. If this happens, just twist the cord a spec or move it and it'll go back to normal. I tested it and if you glue it all in so it's solidly connected to something that problem will go away.
New tutorial link:--
Modified Code:--
/*
HC-SR04 Ping distance sensor
VCC to Arduino 5V
GND to Arduino GND
Echo to Arduino pin 13
Trig to Arduino pin 12
More info at: TrollMaker.com is for sale | HugeDomains
Original code improvements to the Ping sketch sourced from Trollmaker.com
Some code and wiring inspired by User:Dstaub/robotcar - Wikiversity
Modified by Tolson Winters (Aug 27, 2014) for simplified serial monitor reading.
*/
Vulcan666:
Okay, I tested it and got it working. I'll provide a new tutorial link, but don't listen to their code, but wire it up like they did. These modules a little unstable, and sometimes some of them will say like ocm or out of range even when it isn't. If this happens, just twist the cord a spec or move it and it'll go back to normal. I tested it and if you glue it all in so it's solidly connected to something, like my RC Car for example, the problem will go away. Hope this helps! Sorry about the delay!
/*
HC-SR04 Ping distance sensor
VCC to Arduino 5V
GND to Arduino GND
Echo to Arduino pin 13
Trig to Arduino pin 12
More info at: http://goo.gl/kJ8Gl
Original code improvements to the Ping sketch sourced from Trollmaker.com
Some code and wiring inspired by User:Dstaub/robotcar - Wikiversity
Modified by Tolson Winters (Aug 27, 2014) for simplified serial monitor reading.
*/
if (distance >= 2000 ) {
Serial.println("Out of range");
}
else {
Serial.print(distance);
Serial.println(" cm");
}
delay(500);
}
Play around with it, try moving the cord, and changing the out of range values!
Let me know if it does or doesn't work! It should work, though, because it worked for me.
It started working properly with te code in the tutorial link you provided.I am still not able to figure out what was wrong with that sensor but I think that it was the high current draw which caused the arduino to reset.It still gives the constant OUT OF RANGE output when the objects in front of it are moving too fast.
These modules a little unstable, and sometimes some of them will say like ocm or out of range even when it isn't. If this happens, just twist the cord a spec or move it and it'll go back to normal. I tested it and if you glue it all in so it's solidly connected to something, like my RC Car for example, the problem will go away.
I'd had a project that had been working fine, then the sensor started giving nonsense readings in a very small range.
I'd tried everything in the code etc.
Unplugged the jumper cords, plugged them back in again and it's working fine again!
shadow0000:
It started working properly with te code in the tutorial link you provided.I am still not able to figure out what was wrong with that sensor but I think that it was the high current draw which caused the arduino to reset.It still gives the constant OUT OF RANGE output when the objects in front of it are moving too fast.
So,thanks for your help.
P.S:and sorry for the late reply.
hey, i have the same problem, i get is 0CM all the time .
i try many code.
anther thing, before i up-lode the code to the arduino the gnd shortens the circle.
i used in the sensor one year ago and its work , but now no...
Read distance from 4cm to 250mm
Compensate speed of sound according to the ambient temperature
Pass distance thought median filter
Set maximum distance to speed up measurement
Vulcan666:
Okay, I tested it and got it working. I'll provide a new tutorial link, but don't listen to their code, but wire it up like they did. These modules a little unstable, and sometimes some of them will say like ocm or out of range even when it isn't. If this happens, just twist the cord a spec or move it and it'll go back to normal. I tested it and if you glue it all in so it's solidly connected to something, like my RC Car for example, the problem will go away. Hope this helps! Sorry about the delay!
/*
HC-SR04 Ping distance sensor
VCC to Arduino 5V
GND to Arduino GND
Echo to Arduino pin 13
Trig to Arduino pin 12
More info at: http://goo.gl/kJ8Gl
Original code improvements to the Ping sketch sourced from Trollmaker.com
Some code and wiring inspired by User:Dstaub/robotcar - Wikiversity
Modified by Tolson Winters (Aug 27, 2014) for simplified serial monitor reading.
*/