Let's consider having calibrated your pH sensor on its own (including the electronic circuit board). If pH=7, the output voltage from the electronics should be 2.0V (ignoring the 'Offset' which should be small). If pH=0, the output voltage should be 0V and if pH=14, the output voltage should be 4.0V. That's why there is the coefficient of 3.5 in the Arduino code.
Now let's consider it connected to your ESP32 via your voltage divider. If pH=0, the voltage on the ESP32 analogue input pin should be 0V and if pH=7, the voltage should be 2.0 * 470000 / (470000 + 100000) which is 1.65V. I am assuming your ESP32 code is using the eFuse calibration values so you would get more-or-less the correct value of voltage. I have not checked that with my ESP32. Now to get the pH value, you would need to multiply 1.65 by 4.24.
Unlike the Arduino, my ESP32 ADC works over the range 0.17V to 3.15V. Yours may be a little different. This means that we would not be able to measure extremely acid or extremely alkaline solutions but I don't expect that to be a problem.
I have no idea how the probe of the dissolved oxygen sensor works. You have referred to two versions of sensor. I have been looking at the information on the SKU:SEN0165 (
here). That says its measuring range is -2000mV to +2000mV which I take to be the voltage from the probe. Anyway in the circuit diagram (
here) resistor R3 connected to -5V will provide an offset of +2.0V at the output. As R1 is equal to R2, the gain of the electronics is unity but inverting.
My understanding is therefore that -2000mV from the probe will give an output of +4V and +2000mV from the probe will give an output of 0V.
The Arduino code converting from dissolved oxygen sensor output voltage to ORP value is more daunting than the code for converting from pH sensor output voltage to pH . . . . .
Code: Select all
orpValue=((30*(double)VOLTAGE*1000)-(75*avergearray(orpArray, ArrayLenth)*VOLTAGE*1000/1024))/75-OFFSET;
. . . . . note "VOLTAGE" here is the supply voltage nominally 5V, and note "OFFSET" here is the small calibration offset, not the 2.0V offset.
The first part . . . .
. . . . . when divided by 75 becomes 2000 if the VOLTAGE is 5. This is the 2.0V offset caused by R3, in millivolts.
The second part multiples by 75 and then is divided by 75. This corresponds with the unity gain. Note the minus sign. At present I am ignoring "OFFSET".
With 0mV from the probe the sensor output voltage should be 2.0V and, using voltage divider with resistors 100kΩ & 330kΩ, the voltage at the ESP32 input pin should be 2.0 * 330000/(330000+100000) which is 1.535V. With +2000mV from the probe, the ADC input should be 0V and with -2000mV from the probe the ADC input should be 3.07V. You would need to allow for the voltage divider in calculating ORP values as there will not be unity gain from probe to ADC input. I expect your ESP32 will measure up to 3.07V but it will not measure below about 0.17V. This means you would be able to measure ORP only up to about +1780mV. Is that sufficient or do we really need to add resistor R3 to the voltage divider?
EDIT: I'm finding the ADC has good linearity with attenuation set to 6dB. I therefore suggest using 6dB and making appropriate change to voltage divider. With 6dB, I get an input range of 0.14V to 1.88V.