PH Value - nke69/FishPino GitHub Wiki

Calibrate the sensor

As we can see that there are two potentiometers in the circuit. Which it is closer to the BNC connector of the probe is the offset regulation, the other is the pH limit.

Offset: The average range of the probe oscillates between negative and positive values. The 0 represents a pH of 7.0. In order to be able to use it with Arduino this circuit adds an offset value to the value measured by the probe, so the ADC will only have to take samples of positive voltage values. Therefore we will force a pH of 7.0 by disconnecting the probe from the circuit and short-circuiting the inside of the BNC connector with the outside. With a multimeter measure the value of Po pin and adjust the potentiometer to be 2.5V.

PH Limit: This potentiometer is to set a limit value of the pH sensor circuit that causes the red LED to light up and the Do pin signal to turn ON.

In addition we have to calculate the voltage conversion that will give us the pH sensor so we will need two pH reference value and measure the voltage returned by the sensor on the pin Po. The best thing to do is to use a calibration solution in powders, there are also in liquid but it is easier to preserve the powders. These solutions are sold in different values but the most common are pH 4.01, pH 6.86 and pH 9.18.

Graph of the measured voltage and pH equation. y= -5.70 * x + 21.34

Using the powders with pH 4.01 and pH 6.86 we obtain the voltages on the pin Po 3.04V and 2.54V respectively. The sensor is linear so by taking two points we can deduce the equation to convert the measured voltage to pH. The general formula would be y = mx + b, so we have to calculate m and b since x would be the voltage and y the pH. The result is y = -5.70x + 21.34.

Connection with Arduino

To connect with Arduino we will need an analog input (A0), power (5V) and two GND that actually in the sensor circuit are separated but we can use the same.

Code

The code consists of taking 10 samples of the analogue input A0, ordering them and discarding the highest and the lowest and calculating the mean with the six remaining samples by converting this value to voltage in the variable pHVol, then using the equation that we have calculated with the pH reference values we convert pHVol to pHValue and send it to the serial port to see it in the serial monitor.

const int analogInPin = A0; ` `int sensorValue = 0; ` `unsigned long int avgValue; ` `float b; int buf[10],temp; void setup() {

 `Serial.begin(9600);`
`}`
`void loop() {`
`for(int i=0;i<10;i++) `
 `{ `
  `buf[i]=analogRead(analogInPin);`
  `delay(10);`
 `}`
 `for(int i=0;i<9;i++)`
 `{`
  `for(int j=i+1;j<10;j++)`
  `{`
   `if(buf[i]>buf[j])`
   `{`
    `temp=buf[i];`
    `buf[i]=buf[j];`
    `buf[j]=temp;`
   `}`
  `}`
 `}`
 `avgValue=0;`
 `for(int i=2;i<8;i++)`
 `avgValue+=buf[i];`
 `float pHVol=(float)avgValue*5.0/1024/6;`
 `float phValue = -5.70 * pHVol + 21.34;`
 `Serial.print("sensor = ");`
 `Serial.println(phValue);`
 `delay(20);`
`}`
⚠️ **GitHub.com Fallback** ⚠️