Ultrasonic Sensor HC-SR04 and Arduino

Hello All,

I wired the circuit and the exact code given on the following site.

It performs correctly, gives correct readings as long as I have Arduino connected to USB Power Supply. But the moment I connect it to 9V Battery, I get the below fixed reading.

Distance: 3247 cms
Distance:1270 Inches

The problem seems strange. Could you please help me?

Thanks,
Laram

The problem is not strange at all. In fact it is very common when someone uses a tiny 9 volt battery, or connects it to the wrong pins. Perhaps a drawing of your connections using the 9 volt battery should be supplied.

Paul

When you measure the voltage at the Arduino 5V pin where the sensor is powered from, do you get a good 5V to the sensor?

Swap 9V battery with 6xAA battery pack.
I have found that 9V batteries are often the "source" of the problem.

What kind of 9V battery do you use. Just change the power to a 9V-2A AC/DC Power Adapter with Cable will solved.Please check it.