Hi,
I am using HC-SR04 ultrasonic sensor with Arduino mega as a DIY project.
Every thing is working well so far but I noticed that if the sensor is disconnected some how, it would randomly shows a number. It might put me into trouble as I did not notice that the sensor is not connected.
So, what is the best way to test the sensor function and connection? for example, if in the middle of job, the cable is cut, how I can understand that the sensor is off?
Thanks
Wire the thing up for normal operations, once running normally, cut the cable observe what happens and code for the happening.
reezaro:
Every thing is working well so far but I noticed that if the sensor is disconnected some how, it would randomly shows a number.
Really? If the sensor is disconnected the distance is 0 for me....
it would randomly shows a number.
That would probably be from a floating input. Use INPUT_PULLUP on the Arduino receive pin to prevent that.