Reads volts input convert to Liters

Hello everyone.

I have a problem reading accurately from an analog input where 0-3 volts will be received.

Basically the system reads the voltage generated by an Aqua Plumb 0-3V range depending on the water lever, compared to calibration dry/wet.

The problem I have is that I want to have an accurate input signal, and stable, that can I can pass to the arduino so it can process with a function like map.

I have done the program similar to the tutorial 9, but when gettings readings a small change affects the outcome with too much offset.
/*
ReadAnalogVoltage
Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

This example code is in the public domain.
*/

// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
// print out the value you read:
Serial.println(voltage);
}

Pasols:
I have done the program similar to the tutorial 9, but when gettings readings a small change affects the outcome with too much offset.

Are you using that program with a potentiometer or connected to your own sensor?

Post a typical sequence of the values you are getting.

Can you check the voltage from your sensor with a multimeter?

Post a link to the datasheet for your sensor.

For the future please use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

…R

Hi,

  float voltage = sensorValue * (5.0 / 1023.0);

should be this, I think..

  float voltage = (float)sensorValue * (5.0 / 1023.0);

Tom... :slight_smile:

To measure a 0-3volt signal with the highest resolution/stability, Aref must be dropped to a stable 3volt.
That can be done, for a 5volt Arduino, by connecting the 3.3volt pin to the Aref pin with a 3k3 resistor.
You MUST then also set Aref to EXTERNAL, otherwise there is a danger of damaging Aref.
https://www.arduino.cc/en/Reference/AnalogReference

Don't use an intermediate step (voltage).
Convert A/D value straight to liters.
float liters = analogRead(A0) * x.xxx;

If you have the 1meter (1mm resolution) version of the sensor, and you want to display level (not liters) it might be better to drop Aref to 1.024*3volt.
With a 3.072volt Aref, one A/D value is exactly 1mm.
No damaging voltage or mapping conversion needed.
You can make a 3.072volt Aref with a ~2.5k resistor between 3.3volt pin and the Aref pin.
Leo..