Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
Pull request Compare This branch is 4 commits ahead of dwblair:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Depth sensor prototype


There are various approaches to depth measurement (see Ref [1] below) -- float switches, arrays of open wires, optical and sonar distance sensors, etc. Of these, a relatively simple and inexpensive approach is to leverage the dielectric properties of water by making a capacitive measurement.

The basic picture is: a capacitor's ability to store electrical energy is enhanced when it is placed in a material with a larger dielectric constant. Water has a larger dielectric constant than air; so capacitors placed in water can store more energy than they can when in air. For a capacitor formed by a long pair of wires, partially submerged in liquid, the measured capacitance of the wires will increase in proportion to the length of the wires submerged in the liquid. So, measuring the capacitance of these wires would allow us to determine the height of the liquid.


A direct way to measure capacitance is to rely on the fact that the amount of time it takes to charge and discharge a capacitor, when applying a fixed voltage, will increase as the capacitance increases. A chip like the 555 timer performs exactly this function: it will charge a capacitor to a threshold voltage, then discharge it, then repeat the cycle, outputting a pulse every time the capacitor charges to a threshold value. If we hook up a long pair of wires as a capacitor to a 555, and measure the length of time between pulses, we then have a simple liquid level sensor:


Bill of Materials

  • a [555 timer]
  • a 1 K Ohm resistor
  • a pair of twisted wires, not electrically connected, and sealed (with e.g. hot glue) at one end:


Diagram for Riffle Protoboard

Using the Code

The code in this repo, 'riffle_depth.ino', when used with the protoboard schematic outline above and attached to a long capacitive wire pair as in the above photo, will record the average period of pulses generated by the 555 timer. This average period is then assumed to be linearly related to the amount of the wires submerged in liquid.

Calibration Methods

In order to calibrate the capacitive depth sensor, measurements of the oscillator period must be made when the wires are submerged at known depths. The easiest way to do this is by lining up the wires with a measuring tape inside a container, and recording the output of the sensor as more water is poured into the container. This method is described in detail in video accompanying the Public Lab research note here:

Using this method, a rough relationship was established between the period, in seconds of the oscillator output (recorded on SD card) and the height, in centimeters, of the liquid level. This relationship was then used to generate the following graph:

Giving the sensor more time to equilibrate and averaging readings over longer measurement periods may improve the precision of the measurement.

Compensating for sources of error

Capacitive measurements can be affected by several environmental factors, leading to errors in liquid level measurement.

A nice review of sources of error for capacitive depth sensors is outlined in Ref [4], linked here. The researchers assess error in measured liquid level due to:

  • biofilm accumulation
  • changes in conductivity
  • temperature
  • nonlinearity

and nicely summarize the relative magnitude of these errors here:

_Source: Ref [4] below_

One simple idea for mitigating these error sources is to use two capacitive sensors, with one raised a known distance above the other. If both sensors are in the same environment and are subject to approximately the same local fluctuations in temperature, conductivity, and biofilm, then the the difference in capacitance between the two wires might be relatively constant, allowing for most sources of error be divided out. The 555 timer comes in dual-package variants, and two 328p Riffle hardware interrupts could be used to measure these two sensors.

Research Notes on Public Lab


  1. Digikey's guide to depth measurement techniques:
  2. Using light sensors and a ping pong ball: e
  3. Vegetronix capacitve liquid level sensor: Vegetronix:
  4. Review of calibration issues with capacitive depth sensors:

How you can contribute

Some useful guidelines about the best way to contribute to the project (or to fork it) can be found here.

Support and Licensing

The Riffle_328 project has been supported through Public Lab's Open Water Initiative, and is licensed under CERN OHL 1.2.

You can’t perform that action at this time.