Tank Depth Sonar

To measure the depth of water in the tank, I've decided to use a sonar module.  These modules are popular for distance detection in robots, but I use it to measure the distance from the top of the tank to the water level.

At least that was the plan.

Design

Nothing terribly designy here.  Stick a sonar module at the top of the tank and measure the distance.

A sonar module works by transmitting a pulse of sound, then waiting for it to be reflected back.  By timing the amount of time the pulse has spent in flight, and knowing that sound travels at about 340m/s in air, we can work out the distance to what ever caused the reflection; in robotics, an obstacle, for my tank, the water surface.  Sonar pinging is shown below.

For this project, I chose the SRF-04 sonar module made by Devontech.  I had one lying around, so I used it.

Construction

The picture below shows the sonar module installed in the lid of the tank.  The sonar PCB was given a heavy spray of electronic circuit board lacquer.  The only other part of it is the software in the controller.

Performance

Eeek!  I hate it when a plan doesn't come together.  The sonar is installed and "working".  Unfortunately, it is returning a constant distance of about 80 cm, when it should be about 220cm.  What I think is happening is the sonar pulses are bouncing off the sides of the tank and being partially reflected back to the sensor.  I'm not sure how to fix this.  Maybe get a sensor with a narrower beam, eg SRF235, but it's expensive and uses a different protocol.  Or hack the SRF04 and try to modify the gain - the amplified return signal - assuming the side wall reflects can be filtered out.