Calibration

In this step the Arduino sketch will be calibrated to report the volume of measured liquid. To get started, download the software for this project from the following link:
Unzip the archive and load the LiquidSensor sketch in Arduino. This sketch will read the raw sensor resistance and help you calibrate for volume measurements.

At the top of the sketch you can adjust the following #define values based on your hardware:
  • SERIES_RESISTOR - This is the value in ohms of the resistor you attached to the hardware in series with the sensor. This should be 560 unless you used a different resistor value.
  • SENSOR_PIN - This is the analog input pin which is connected to the sensor.
Ignore the remaining #define values for calibration right now. Upload the sketch to your hardware and open the serial monitor at 115200 baud. You should see text like the following output every second:

Resistance: 1963.70 ohms
Calculated volume: 0.00000

The resistance value is the measured resistance of the liquid sensor. With no liquid touching the sensor it should read a value around 1500-2000 ohms (depending on the length of the sensor).

Try pressing the sensor in various locations to see how the resistance changes. If you touch near the top of the sensor at the MAX line you should see a resistance around 200-400 ohms.

To calibrate the sensor for measuring volume, you will need to measure the following:
  • The resistance value with no liquid touching the sensor.
  • The resistance value when a known volume of liquid is touching the sensor.
  • The volume of liquid used to find the above resistance value.
For example I saw my sensor output a resistance of about 1963.7 ohms when no liquid was touching it. Then I filled the graduated cylinder with 500ml of water and saw the resistance was 512.81 ohms.

Once you've determined the above calibration values, update the #defines at the top of the sketch appropriately:
  • ZERO_VOLUME_RESISTANCE - Set this to the resistance value with no liquid, in my case 1963.70.
  • CALIBRATION_RESISTANCE - Set this to the resistance value with a known volume of liquid, in my case 512.81.
  • CALIBRATION_VOLUME - Set this to the volume of liquid, in my case 500.00 milliliters (you can use other units, but milliliters are what the web application expects).
Save the sketch and upload again. Now you should see a calculated volume value output every second. Try filling the container with various levels of liquid to see how the calculated volume changes.

If you're not using an Arduino Yun, the software setup is done and you're now able to read the volume of liquid in the container. Consider adding a display, like this small OLED, to show the measured volume!

If you're using the Yun, continue on to learn about how to setup the Yun to display volume data on a web page.
This guide was first published on Apr 14, 2014. It was last updated on Apr 14, 2014. This page (Calibration) was last updated on Jun 24, 2019.