Analog sensors like that do tend to drift. There is nothing you can do about it, except to establish some method that gives reasonably repeatable readings.
My approach to measuring conductivity with a cheap meter is to alternate between taking readings of pure, distilled water, standard solutions, and the sample and average the results.
Ok.
I have the code to read analog input and convert it to EC value (including temp. compensation).
I have EC calibration solutions of 1.41mS/cm and 2.76mS/cm which are close to my working range.
But I don't know how to apply calibration to my code. Can you help me please?
read twice.
it would remove any stray voltages on pin that might induce creep in the signal.
I did not review your code for how many decimal places you use but
ec_volts = sensor_ec.raw_pv * 4097.0 / 1024;
could be written as
ec_volts = sensor_ec.raw_pv * 4;
because there are 3 zeros in the decimal places before your first number.
or try 4.001
I would offer that you could run the numbers and see what effect that would have. it might be so minimal that there is zero alteration in results.
float offers 6-7 decimals of precision and your formula has the same values for the first 4 places.
I offer that since you are working with a 10 bit value, the step change does not offer any benefit by trying to run out decimals to great lenghts.
I measured my 1413mS/cm calibration solution. ADC Drift: 5 Average ADC value: 40 Average mV: 8.19 Average EC: 1.05
I measured my 2764mS/cm calibration solution. ADC Drift: 13 Average ADC value: 82 Average mV: 16.79 Average EC: 2.18
I am trying to put my values into the equation. RawValue: I don't know. RawLow: 1.05 ReferenceRange: 2.764 - 1413 = 1.351 RawRange: 2.18 - 1.05 = 1.13 ReferenceLow: 1.413
if you 2 point calibration, he discusses water. 0C and 100C or a 100.00 range.
you boil water, it is 100.00 C
you have ice water, it is 0,01C
the physical range is 100
you take a reading when the water is ice water at 0.01 and you get -0.5 = RawLow = -0.5°C you take a reading when the water is boiling water at 100 and you get 96 =RawHigh = 96.0°C RawRange = 96.5°C
when you take a reading and the raw reading is 37 you have to apply the correction to get the correct reading.
Ice water is 0.00C at atmospheric pressure. Its the triple point of water that's 0.01C. You need
very pure water to get the ice point or triple point that precise though.