After a fair bit of research on the subject, I landed a ten-pack of Chinese HC-SR04 4-Pin Ultrasonic Distance / Range Sensors to test their viability to measure the level of fluids in various containers. Originally intended for an outdoor water fountain, I installed one but never got a chance to test it out before the fountain was deployed. That fountain has been filling my garden with lovely trickling water sounds for two seasons now, but the water level sensor still remains connected to nothing. So it goes with many projects. One other application I had for it, however, employed such a sensor to measure the level of salt in my water softener. You can see my post about the project on the
Venturii Blog here. Over the past couple of nights I have been tinkering with the firmware in the VSAC (and made some significant improvements to the OWI code at the same time by the way...) but still get pretty consistent and random readings from the sensor. It is connected to a stable power supply (and not powered by a USB port.) Each firmware version I try causes me to swap out the Mega so I know it's not the Arduino hardware. The trouble is that some of the readings appear to be correct. With a measuring tape I've determined that the distance from sensor to salt is about 72 cm. My theory goes that as the salt is consumed, that distance will increase; some simple math will allow me to produce a
percent full number and I can even set up alerts to let me know when I need to pick up more salt. However, all that is impossible until I can get the sensor to stabilize.
Here is an example of what I am seeing:
After much reading online, I've got two theories I'm going to pursue at this time.
1. The sensor is being polled too frequently. One reader commented to a post on this subject that [they] had encountered this situation where the outgoing pulses are being sent out in such short succession (since you have control over the timing of such pulses via the trigger pin) that it can actually mis-interpret the return of a sound wave from the last pulse as though it were returning from the current sound pulse, resulting in shorter measurements.
The other theory I read about is that
a design flaw in the sensor itself can cause sonic disruptions in the air from outgoing pulses to be picked up prematurely by the receiver due to the two components being in too close physical proximity to each other. The reader who made this assertion claims he had resolved this issue by de-soldering the transmitting and receiving transducers and spacing them about 10cm apart. I'm not sure why you wouldn't just de-solder one of the two and leave the other on the PCB, most likely the approach I will take unless the reason for doing both becomes evident through experimentation. The author also noted that doing so did negatively impact measurements at shorter distances, which makes sense, and is likely not an issue for my application.
In any case, the shorter term fix may be in the firmware, I will extend the current "stun" feature to allow greater time between triggers, possibly even user-tuned. If, say, a once-per-second scan of the tank still yields wildly random results, I will sacrifice one of the sensors and attempt to spread the transducers out a bit more. If it does work, it should make for a very useful (and inexpensive) modification to any water softener. Prior to this, the only way I'd really notice I was out of salt was by accumulation of scale on the shower glass, but of course by that time it is too late!