Hello there,
If someone is using the Ali express Ph Probe.
There are many naive tries, Which may work for some ppl… but not rly.
It is more like meeh it works okayisch with linear calibration or even polynominal:
calibrate_polynomial:
degree: 2
datapoints:
- 3.91 -> 4.0
- 3.59 -> 6.86
- 3.435 -> 7.4
- 3.39 -> 8.0
This is sooo frustrating… i spent like 4 days wracking my brain about it… IT is not precise!
In the end I found the original code and converted it to a lambda with a filter function:
so from DFRobot_ESP_PH_BY_GREENPONIK/src/DFRobot_ESP_PH.cpp at 731c09f1f8d724e1d400211fa811911c692f6735 · GreenPonik/DFRobot_ESP_PH_BY_GREENPONIK · GitHub
And you get:
- platform: ads1115
name: "pH Calculated"
multiplexer: 'A0_GND'
icon: mdi:ph
accuracy_decimals: 5
gain: 6.144
id: ph_calculated
update_interval: 1s
unit_of_measurement: Ph
filters:
- median:
window_size: 60
send_every: 60
send_first_at: 6
- lambda: |-
// Replace with your actual neutral and acid voltages
const float neutral_voltage = 3.59 * 1000;
const float acid_voltage = 3.91 * 1000;
const float slope = (7.0 - 4.0) / ((neutral_voltage - 1500.0) / 3.0 - (acid_voltage - 1500.0) / 3.0);
const float intercept = 7.0 - slope * (neutral_voltage - 1500.0) / 3.0;
const float voltage = x * 1000; // assuming input is in V and converting to mV
float ph_value = slope * (voltage - 1500.0) / 3.0 + intercept;
ESP_LOGD("ph_sensor", "PH Value: %f", ph_value);
return ph_value;
NOW hot to get this darn thing to work:
If you are not a pro electrical nerd, YOU will have a noisy supply. And this probe is REALLY sensitive. So do your self a favor and solder a 1pF cap on the pins of the probe. like under the pcb on the headers so you dont get stray voltage spikes and what not… it will look afful.
But im left with a final question, is this correct? Because as far i can tell the 3.0 and 1500 are scaling factors for 3v mesurment. It should not matter but im not sure. because the original lib is written for
DFRobot SEN016 Meter Kit
And that one has a 3v range. While the alie Express one has a 5v
It should not… but this code gives a better value:
- platform: ads1115
name: "pH filtered"
multiplexer: 'A0_GND'
icon: mdi:ph
accuracy_decimals: 5
gain: 6.144
id: ph_filter
update_interval: 1s
unit_of_measurement: Ph
filters:
- median:
window_size: 60
send_every: 60
send_first_at: 6
- lambda: |-
// Replace with your actual neutral and acid voltages
const float neutral_voltage = 3.59 * 1000;
const float acid_voltage = 3.91 * 1000;
const float slope = (7.0 - 4.0) / ((neutral_voltage - 2500.0) / 5.0 - (acid_voltage - 2500.0) / 5.0);
const float intercept = 7.0 - slope * (neutral_voltage - 2500.0) / 5.0;
const float voltage = x * 1000; // assuming input is in V and converting to mV
float ph_value = slope * (voltage - 2500.0) / 5.0 + intercept;
ESP_LOGD("ph_sensor", "PH Value: %f", ph_value);
return ph_value;
the graph function from HA gives a really precise value via the mean value. I am working on it to make the filter window good enough to get the correct value. 1 mean every minute for now.
And yes you have to use median for aggregation because the ADS reads only the current value, and we live in an imperfect world.
If you like to get a Electrical eng. Degree in EMF insulation and ground loopback insulate you pool you could read it directly, everything else means shit ton of noise… and a potentiometer does averaging to.