With the input of the pH meter circuit board shorted out (or the electrode in a solution with pH=7) the output should be close to +2 volts. It will not be exactly +2V due mainly to the tolerance of resistor values. That's why when setting up your meter you need to put a value for "Offset" into the code. The next step is to adjust the gain of the amplifier using the preset potentiometer (which should not affect the +2 volts). I see in the Arduino code . . . . .
. . . . . so evidently you adjust the gain so a change of pH value of 3.5 gives a change of output voltage of 1 volt (it's an inverting amplifier). The maximum possible pH is 14 so, after adjusting the gain, the theoretical maximum output voltage will be +4.0V. The minimum possible pH is 1, so the minimum voltage should be 1/3.5 = +0.286V. Of course your actual minimum and maximum output voltages will depend on the maximum acidity and maximum alkalinity of the solutions you are measuring. The output voltage could also be limited by the output voltage swing available from the operational amplifiers on the circuit board.
The circuit board of the ORP meter is very similar but has a fixed gain close to unity (inverting). Its output should also be close to +2 volts with input shorted (calibrate button pressed).
The Arduino code below acts as a reasonable voltmeter over the range +0.15V to +3.15V and prints the corresponding pH value (currently with Offset=0).
Code: Select all
long sum;
float average, voltage, pHValue, Offset=0;
void setup()
{
Serial.begin(115200);
}
void loop()
{
for (int i=0 ; i<100 ; i++)
{
sum = sum + analogRead(34); // Input pin 34, 12 bits
delay(10);
}
average =sum/100;
sum=0;
voltage = average*0.000817 + 0.15;
pHValue = 3.5*voltage + Offset;
Serial.printf("V= %4.2f pH= %4.2f \n", voltage, pHValue);
}
I derived the linear equation coefficients 0.000817 and 0.15 by calibrating my ESP32 against a digital voltmeter.
If you are using ESP-IDF code as example
here, I understand you can rely instead on coefficients burned into eFuses during factory calibration (at least for recently manufactured ESP32s).
There remains the question as to whether you need a voltage divider. Without a voltage divider, the coefficients for my particular ESP32 would allow reading of values of pH between 0.6 and 11 (with default ADC attenuation); similarly values of ORP between -1150mV to +1850mV (subject to checking). I don't know anything about ORP but I guess those ranges are sufficient. However it is somewhat risky to connect a 5 volt device to an ESP32; if the signal goes much above 3.3V it could destroy the ESP32. If your sensor electronics is powered by a different power supply to your ESP32, you ought to consider the risk of destroying your ESP32 if the sensor electronics is powered up before the ESP32 is powered up. I would be inclined to only insert a resistor in series with the input of the ESP32 to limit the current but I have not been able to find in the datasheet what current the ESP32 would tolerate. A voltage divider would provide similar protection and extend your pH measurement range.
I have been very unimpressed by the variation between successive digital readings (before averaging). Perhaps I ought to earth other ADC inputs, as recommended by Pibbotley. Also there is noticeable non-linearity above about 2.6V.