IoT water tank telemetry project – ultrasonic sensor – #1 described an inexpensive ultrasonic ranging sensor for trial.
Above is the GY-US42v2 ultrasonic ranging sensor, it was purchased for around $14 on Aliexpress delivered within 10 days.
This sensor has three operating modes, I2C, RS232, and PWM (HC-SR04 compatible). The tests reported here are PWM mode, so it is working with exactly the same code as IoT water tank telemetry project – HC-SR04 – first trial.
The basic operation is that a short pulse is sent on the TRIG pin and a short while later, a pulse occurs on the ECHO pin of duration equal to the round trip time. The speed of sound is about 340m/s @ 20°, and so the distance to the water can be calculated. Because the speed of sound is a little dependent on air temperature, the project incorporates a DS18B20 one wire temperature sensor to feed a compensation calculation.
We might expect some measurement noise, and over this trial the standard deviation is 1.9mm over the last 100 observations. To the eye, it appears that the temperature compensation is fairly good.
Above is an example using I2C mode where the range reading is rounded to cm. In this scenario, the target range is constant, but we we some variation in temperature and compensated range measurement rolling into the simulated dam volume measurement. The steps are due to the cm rounding, and we observe that those coarse steps do not appear in the PWM mode.
The code was written to deal with the variance of the HC-SR04 sample, and it made eight measurements, discarded the two highest and lowest, and took the mean of the remaining four for a significant improvement in variance of observations. This is not necessary with this sensor, the standard deviation of a set of eight measurements is similar to that of 100 observations, so it proves the the outliers with the HC-SR04 were due to the HC-SR04 rather than the tanklevelu code and hardware. More HC-SR04 are on order and will be tested to see if the issues are exhibited by the type in general.
Performance is much better than observed with the HC-SR04 trial. This device has the advantage of a single transducer, and support for I2C.
The I2C mode unfortunately returns range as an integer number of cm, so it becomes quite coarse… not very suited to a shallow tank such as a machine coolant tank. Further, that on tests in I2C mode, it gives unreliable results for ranges less than 20cm, typically indicating longer distances possibly multiple round trips.
These are sold to the UAV market, but I don't think I would try one as finding that at distances below 20cm, the readings double or worse suggesting that might cause serious instability to an automated landing using the ultrasonic for altitude sensing.
Overall, a much better sensor than the HC-SR04 tried, but the short range limit and limitations on its I2C mode may be unacceptable in some applications.
Searches for a datasheet have been unsuccessful. Some sellers point to the Maxbotic MB1242, suggesting then that this might be a cheap clone of that device.
A work in progress…