I have set up a DFRobot KIT0139 pressure water level sensor. The board (Olimex ESP32-PoE2) is delivering 24V to the sensor. The returned voltage is read out through one of the ESP32 GPIOs. I read ADC on the ESP32 can be quite noisy. So I suppose this is common behaviour?
The GPIO I'm using on the ESP32 has a 10k resistor, might this be interfering with the readings?
I'm going to use the exponential moving average filter to even it out a bit.
A few sample readings:
[13:53:51.178][S][sensor]: 'Water tank level' >> 1.54 V
[13:54:21.183][S][sensor]: 'Water tank level' >> 1.47 V
[13:54:51.176][S][sensor]: 'Water tank level' >> 1.41 V
[13:55:21.181][S][sensor]: 'Water tank level' >> 1.53 V
[13:55:51.175][S][sensor]: 'Water tank level' >> 1.48 V
[13:56:21.179][S][sensor]: 'Water tank level' >> 1.51 V
[13:56:51.171][S][sensor]: 'Water tank level' >> 1.48 V
[13:57:21.175][S][sensor]: 'Water tank level' >> 1.49 V
[13:57:51.184][S][sensor]: 'Water tank level' >> 1.45 V
[13:58:21.172][S][sensor]: 'Water tank level' >> 1.48 V
[13:58:51.180][S][sensor]: 'Water tank level' >> 1.46 V
[13:59:21.185][S][sensor]: 'Water tank level' >> 1.50 V
[13:59:51.178][S][sensor]: 'Water tank level' >> 1.51 V
[14:00:21.182][S][sensor]: 'Water tank level' >> 1.43 V
[14:00:51.175][S][sensor]: 'Water tank level' >> 1.53 V
[14:01:21.179][S][sensor]: 'Water tank level' >> 1.43 V
Yes, the ADC in esp chips are known to be less than great.
Yes, it is possible to make them better with software.
You didn't show the design/layout of your circuit. The sensor you are using has a current output, so you need something to convert it to voltage. What are you using?
Here is a good basic description of one way to do it.
For the few analog sensors I have (ratiometric water pressure sensors) I use them with the ADS1115. It is a decent quality ADC, so it needs much less software help to get good readings.
Thanks for responding, and my apologies. First time I built something like this, I've been using ESPHome for little more than BT proxies until now. The questions are:
If this is what one can expect when using the ESP32 ADC indeed.
If using a GPIO with a resistor would cause less accurate readings.
I'm using the DFRobot KIT0139 which comes with a SEN0262 analog to current voltage converter that can send up to 3V.
Looks noisier than my experience with ESP32. But I don't know if you use multisampling or not (you should). Also, don't you have any free adc pin without resistor?
And shouldn't you power your converter at 3.3V since esp is 3.3V board
There are better ADCs. It depends on what you are doing with the data if you need one or not.
Precision, accuracy, repeatability all matter for some applications and not so much for others.
I use temperature sensors to control some heaters for freeze protection. Absolute accuracy doesn't matter much, since I have the control point well above freezing. Precision and repeatability do matter some, since I want to minimize the energy used.
So, what are you really trying to do that you need a pressure sensor?
While not best in class, I find esp32 adc suitable for most of cases. Where it fails is <200mV and >3100mV ranges. C3 instead can't make it above ~2900mV.
Setting samples: 64 kills noise sufficiently. Small capacitor would improve even more.
[16:21:53.465][S][sensor]: 'Water tank level' >> 1.47 V
[16:31:53.482][S][sensor]: 'Water tank level' >> 1.49 V
[16:41:53.488][S][sensor]: 'Water tank level' >> 1.49 V
[16:51:53.489][S][sensor]: 'Water tank level' >> 1.48 V
[17:01:53.485][S][sensor]: 'Water tank level' >> 1.49 V
[17:11:53.504][S][sensor]: 'Water tank level' >> 1.49 V
[17:21:53.512][S][sensor]: 'Water tank level' >> 1.49 V
[17:31:53.512][S][sensor]: 'Water tank level' >> 1.48 V
[17:41:53.513][S][sensor]: 'Water tank level' >> 1.48 V
[17:51:53.515][S][sensor]: 'Water tank level' >> 1.48 V
[18:01:53.532][S][sensor]: 'Water tank level' >> 1.49 V
[18:11:53.533][S][sensor]: 'Water tank level' >> 1.49 V
[18:21:53.531][S][sensor]: 'Water tank level' >> 1.48 V
[18:31:53.544][S][sensor]: 'Water tank level' >> 1.49 V
As for the 5V, the manufacturer states this:
This module employs 0.1% high precision sense resistor and ultra-low noise rail-to-rail zero-drift op amp, high accuracy, no need to calibration, so it is convenient to use. 3.3V~5.5V wide voltage power supply [...].
So 5V should be OK.
I do have free pins without resistor, I'll see if that makes a difference, thanks.
Measuring the level of our rainwater tank. It does not need to be super accurate; monitoring is mostly to make sure we add tap water once it runs too low (you don't want to find out you're out of rain water when trying to flush the toilet). So I will be setting like a 10% treshold, we'll see how that goes.
What does that translate to in terms of tank full/empty?
The fuel gauge in my newest car is digital and seems somewhat non-linear. It only has about 10 levels from full to empty. Surprisingly, that doesn't feel as good as the analog gauges I am used to, which have more precision (but probably not accuracy).
Almost full, I have this sitting in the YAML as well to convert to a percentage, but it's disabled for now since I wanted to monitor the voltage reported.
This is a graph of the cistern of my gravity fed irrigation system over two days.
I am using a 240-33 Ohm Float Sensor. and wire it like this
+5
sensor
---------------------> to ESP8266 ADC
resistor (sized to keep the voltage < 1V)
GND
I also have full and empty level sensors (which are "filtered").
At 6PM a zone turns on. Shortly after, as the water flows, the full sensor indicates not full which turns on the pump from the well (and off when full). Similarly, in the early morning a series of zones turn on and off.
You can see a lot of noise. I ask myself, "What would I do differently if that noise were filtered out?" What the noise does tell me is that the ESP8266 is still working
The level sensor is not triggering the pump so it does not cause my pump to cycle.
Much better, but i would still use multisampling. In certain cases the first sample is not accurate Try with:
samples: 64
attenuation: 12db
I don't know the circuit of that converter, but since you use 3v3 microcontroller, in my opinion that's the correct supply voltage. Otherwise converter might scale the output up to higher voltage.
Thanks. I have moved the sensor to the 3,3V line and to a resistorless pin. Voltage is now reporting around 1,9V, still fluctuating, but good enough for what I need.
I'll play a bit with the samples and exponential_moving_average settings.