IoT water tank telemetry project – HC-SR04 – first trial

IoT water tank telemetry project – ultrasonic sensor – #1 described an inexpensive ultrasonic ranging sensor for trial.

Above is the HC-SR04 ultrasonic ranging sensor, it was purchased for around $6 from a local eBay seller and delivered within days. Note that there are somewhat similar looking things with a second board on the back and a different interface, the basic HC-SR04 as pictured suits this project.

A series of tests were conducted of range to a hard surface at a distance of about 250mm and calculated ‘tank’ level and temperature plotted over time. Temperature is measured on the prototype breadboard using a DS18B20, and calculation of distance is compensated for the variation in velocity of sound with temperature.

We might expect some measurement noise, but the step variations are unexpected. The steps do not correlate well to temperature, are they the results of some periodic internally triggered recalibration process?

Within each step zone, variance looks to be 2mm, but there are steps of 7mm or so that really degrade overall variance. The plot does not give reason the question the temperature compensation.

Is this a defect in an individual device, or is it somethings they all exhibit?

Now there are different ‘versions’ of the HC-SR04 sold online, the question is whether they share the same firmware and might inherit the same defect.

I have purchased some more of these from China, the item listing showed a different PCB silksceen, but hey this is China, you never know what you get till you get it, if you get it, get it?


I also ordered another type of sensor, a GY-US42 which appears to be ‘inspired’ by an  I2CXL-MaxSonar-EZ MB1242. It is an I2C device, so requires some code rewrite to support it. It is a more expensive device, but has some advantages, include that it transmits and receives from a single transducer.

This can also be used in RS232 mode and HC-SR04 compatible pulse mode.


Another interesting device is the JSN-SR04T-3.0 which uses a waterproof transducer separated from the electronics. This appears to support HC-SR04 compatible pulse mode. This appears to be a wide angle sensor, and possibly not suitable to the application… nevertheless one was ordered for trial.

A work in progress…