Just picked up a Gravity Analog pH Sensor v2 from DFROBOT. just having a little issue understanding how I calibrate this sensor. I understand that it’s done by Voltage. Does anyone have an example code for the calibration or have I missed something here?
I should add I’m using an esp32
Updated, So I think I have calibrated the sensor using the following code. Does anyone know if it’s possible to add a temperature offset? or whether I need to worry about that?
A TDS will alter the PH values without having an isolator if in the same liquid system. This is the issue I am running into. I am trying to figure out how to control transistors with espHome to turn the TDS sensor on and off. Do you know how to do that?
Set the update time to, I believe, zero. It’s been a while and I can’t find the how to set a sensor to never update. You can then use the update call to take readings when you want.
No the ADS1115 is not required. I have posted 2 different versions of custom code that use 2 different libraries from GreenPonik based on whether or not you are using the ADS1115.
Good Evening
I would like to say that I have solved this, but I’m running into issues all the time. would you mind writing this in a dummy guide for me, please?
I have a Gravity Sensor v2 with no ADS1115 module.
This looks awesome (nothing new vs what has been said already but I wanted to join the crew in thanking you!.
I have one question related to the custom component:
I do not have a Dallas sensor, so I was thinking to just remove the Dallas bit from your component and plug my temperature sensor from HomeAssistant. To do so, how should I adjust this bit of code?
//add your code here to get the temperature from your temperature sensor
sensors.requestTemperatures();
return sensors.getTempCByIndex(0);
The ADC quality varies significantly on which microcontroller you are using. If you use an ESP32 then I would highly recommend the use of an ADS1115. You will get much better resolution and accuracy. If you are interested in why have a look at #340 How good are the ADCs inside Arduinos, ESP8266, and ESP32? And external ADCs (ADS1115) - YouTube. The ADS1115 requires I2C but if you have more than one analog sensor you will break even regarding pin count.
If you don’t use an ADS1115, then you should note that the ADC on the ESP32 is not linear. Using the calibrate linear filter in ESPhome doesn’t work as well as it might. I calculated the linear fit using the simple line equation y = mx + b as I wanted to be able to change the values using code and I couldn’t work out a way to use global variables in the sensor filter.
globals:
- id: ph4raw # raw v value from probe using ph 4 calibration solution.
type: float
restore_value: yes
initial_value: '2.047'
- id: ph7raw # raw v value from probe using ph 7 calibration solution.
type: float
restore_value: yes
initial_value: '1.51'
- id: phm # calculated line slope
type: float
restore_value: yes
initial_value: '-0.14667'
- id: phb # calculated line intersect
type: float
restore_value: yes
initial_value : '2.54'
ads1115:
- address: 0x48 # default
i2c:
sda: 21 # default pins on the esp32. You can change to suit
scl: 22
- platform: ads1115
internal: True
multiplexer: 'A3_GND'
gain: 2.048
name: 'ADS1115 PH'
id: ADS1115_PH
update_interval: 360s # default 60s
filters:
- median:
window_size: 7
send_every: 4
send_first_at: 3
# Use two points to calculate the equation of the line fitting your ph measurements. Note
# that if you interested in higher ph meaurements (>7) then calibrating using a ph 10 solution
# and a ph 7 solution will give you better results than using the ph 4 solution. You can easily make
# your own ph 10 solution if you have a scale with > 0.1 gram accuracy. Look on line.
# From the current raw ph measure, calculate the calibrated ph using the line
# equation phraw = phm*X + phb, X = (phraw - phb) / phm
# phm is the slope of the line
# phb is the line intersect
- platform: template
name: "Calibrated PH"
id: ph
unit_of_measurement: "pH"
accuracy_decimals: 2
state_class: measurement
icon: mdi:ph
update_interval: 360s
lambda: |-
id(phm) = (id(ph7raw) - id(ph4raw)) / 3;
id(phb) = (id(ph4raw) - (id(phm) * 4));
return((id(ADS1115_PH).state - id(phb)) / id(phm));
And I’ve got the Gravity pH Meter Pro v2 hooked up to pin 13 on my ESP32.
This is the setup of my directory structure too, ensuring that things should be in the right place: