Code for PH Sensor DFRobot

Could you kindly explain how to calibrate readings using services? I don’t know how to pass buffers pH values…

EDIT:
Nevermind, found in read_ph.ino file instruction:

  • enterph → enter the calibration mode
  • calph → calibrate with the standard buffer solution, two buffer solutions(4.0 and 7.0) will be automaticlly recognized
  • exitph → save the calibrated parameters and exit from calibration mode

So for anybody asking, just

  1. Go to Developer Tools > Services, find:
    ESPHome: xxx_enter_ph and call service to start calibration
  2. Find ESPHome: xxx_calibrate_ph, put probe to buffer 4.00 and call service to calibrate measured value. Make the same for buffer 7.00
  3. Find ESPHome: xxx_exit_ph to save results and leave calibration.

In case of problem during calibration (matching buffer 7.00 to 4.00) in may be worth to compare received voltage values from logs to ranges defined in DFRobot_ESP_PH.h (or with ADC) file:

#define PH_VOLTAGE_ACID_OFFSET 200
#define PH_VOLTAGE_NEUTRAL_OFFSET 200
#define PH_8_VOLTAGE 995  //linear culculation
#define PH_7_AT_25 1134   //laboratory measurement with isolation circuit, PH meter V2.0 and PH probe from DFRobot kit
#define PH_6_VOLTAGE 1250 //linear culculation
#define PH_5_VOLTAGE 1380 //linear culculation
#define PH_4_AT_25 1521   //laboratory measurement with isolation circuit, PH meter V2.0 and PH probe from DFRobot kit
#define PH_3_VOLTAGE 1700 //linear culculation

#define PH_VOLTAGE_NEUTRAL_LOW_LIMIT PH_8_VOLTAGE - PH_VOLTAGE_NEUTRAL_OFFSET
#define PH_VOLTAGE_NEUTRAL_HIGH_LIMIT PH_6_VOLTAGE
#define PH_VOLTAGE_ACID_LOW_LIMIT PH_5_VOLTAGE - PH_VOLTAGE_ACID_OFFSET
#define PH_VOLTAGE_ACID_HIGH_LIMIT PH_3_VOLTAGE

In my case buffer 7.00 has 1266V and was treated as ACID VOLTAGE (between PH_VOLTAGE_ACID_HIGH_LIMIT and PH_VOLTAGE_ACID_LOW_LIMIT).
I had to remove all linear calculated values (pH 8, 6, 5 and 3) and redefine
PH_7_AT_25
PH_4_AT_25
according to my readings (1266V and 1666V from logs).

Then redefine:
PH_VOLTAGE_NEUTRAL_LOW_LIMIT
PH_VOLTAGE_NEUTRAL_HIGH_LIMIT
PH_VOLTAGE_ACID_LOW_LIMIT
PH_VOLTAGE_ACID_HIGH_LIMIT
which defines a ranges used for automatic recognition to match buffer 4.00 or 7.00

For that simply PH_7_AT_25 and PH_4_AT_25 may be used with +/- NEUTRAL and ACID OFFSETS
:slight_smile:

1 Like

Hello there. Leaving a note if somone is using this for ph mesurment.
YOU CANT use linear calibration because the voltage output from this thing is not linear. It is polynomial! i lost SO much time trying to calibrate it, it will always be ofcenter. You have to do it like this:

type or paste code here
    # https://esphome.io/components/sensor/index.html#sensor-filters
    filters:
      - median:
          window_size: 15
          send_every: 8 
      # Measured voltage -> Actual pH (buffer solution)
      - calibrate_polynomial:
          degree: 2
          datapoints:
            
            #- 3.435 -> 7.4
            - 3.91 -> 4.0
            - 3.59 -> 6.86 
            - 0 -> 14
            - 5 -> 0

Found this on github it is a custom component for the DF Robot pH and EC with calibration etc for ESP Home. JakeTheRabbit/esphome-DFRobot-pH-EC-Peristaltic: Custom components for DF Robot pH, EC, Peri pumps with calibration and servo control. (github.com)