Another liquid level probe.


here is another liquid level sensor. I am using the CapacitiveSensor library. I am making a test system with a wire inside a steel tube. The tube is grounding via the Arduino and the wire is used for the sensor value which is attached to an analog pin . I get a reading when empty about 4000 and when full about 7000. I noticed that the actual pin value is 360 empty and 410 full. (these values are approximated)

  • The sensor value is very touchy how could I fine tune this input?

  • Eventually I will control a ball valve by mapping the input to a PWM pin.

I am just trying to serial print the output value
I want the empty level to be 51 and the max level to be 255 is this possible? So the output would be 1 V to 5 V . Any values outside of these would not be desired

I have tried to calibrate and capture the Min and Max values when a button was pressed but this has failed.

here is one of the codes I have written .
Any help with this would be great

A 1M ohm resistor is between pins A0 and D12
a 100 pF Cap is connected between A0 and Ground
the input is to pin A0
output is from D3 to a led with a 220 ohm resister in series


#include <CapacitiveSensor.h>

int count = 0 ;
int x = 0;
CapacitiveSensor liquidLevel = CapacitiveSensor(12,A0);

void setup()


void loop()
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 3; // Analog output pin that the LED is attached to

int sensorValue = 0;
int outputValue = 0;

count++ ;
long total = liquidLevel.capacitiveSensorRaw(50);

// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin, outputValue);

Serial.print(total) ;
Serial.print ("\t");
Serial.print ("\t");
Serial.print ("\n");

delay(250) ;

Did you use an insulated wire inside the tube.
A bare wire would be a resistive sensor instead of capacitive sensor.

Your code seems a mix of capacitive and resistive.