This Blog will cover how to measure pH in your aquaponics/hydroponics system, later we will be using this reading to control the pH.
Take a look at the blog below to see why PH is an important factor and why we need to be controlling it.
Blog:20.2 - Toying with Chemical Analysis - pH
The pH Probe
DFRobot have been nice enough to send me one of their MCU pH sensors, it is the pro model with a longer life than the normal probes [hopefully I cant break this probe].
What else you will need:
>pH calibration fluid [4 and 7]
>Arduino mega/uno
Wiring diagram
Calibration
pH probes need to calibrated routinely [one a month is a good idea] so we better have a code that lets us easily calibrate the thing.
Wire the probe up like the diagram above, upload the code below and then:
1:Place Probe into pH7 calibration fluid, open serial
2:Take Recommended cell constant and change it in the top of code
3:Rinse Probe and place in pH4 calibration fluid
4:Adjust potentiometer on pH meter shield until ph reading in serial is 4
That's it, you are now calibrated and ready to use the pH reading from serial.
The Code
This reads the ph probes shield [its an analog value] averages ten readings to reduce any noise and converts the ADC reading into a ph value. outputting the reading to serial.
PH Measurement code |
---|
/* Script to print PH to serial
28/8/2015 Michael Ratcliffe Mike@MichaelRatcliffe.com
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
Parts: -Arduino - Uno/Mega -df Robot Ph Probe Kit [SKU:SEN0169] This is a great PH sensor compared to the ones ive had in the past
See www.MichaelRatcliffe.com/Projects for a Pinout and user guide or consult the Zip you got this code from
*/
//*********************** User defined variables ****************************// //pH meter Analog output to Arduino Analog Input 0 int PHPin =A15; //The calibration constant for the PH probe float K=3.64; //The Ph we will be calibrating in int Cal_pH=7;
//********************** End Of Recomended User Variables ******************//
//************** Some values for working out the ph*****************// float Kn=0; float phValue=0; int i=0; long reading=0; long sum=0; float average=0;
//******************** Setup Loop Runs Once ******************************// void setup() { Serial.begin(9600); startupinfo(); }
//******************** Main Loops runs Forver **************************// void loop() { ReadPH(); PrintSerial(); Calabrate(); delay(1000); }
//*************************Print Some useful startup info **************************// void startupinfo(){ Serial.println("pH Probe Script for arduino"); Serial.println("Released under GNU by Michael Ratcliffe"); Serial.println("www.MichaelRatcliffe.com"); Serial.println("Element14 'Adapted_Greenhouse'"); Serial.println("Using DFRobot PH Probe Pro "); Serial.println("How to Use:"); Serial.println("1:Place Probe into pH7 calibration fluid, open serial "); Serial.println("2:Take Recomened cell constand and change it in the top of code"); Serial.println("3:Rinse Probe and place in pH4 calibration fluid"); Serial.println("4:Adjust potentiometer on pH meter shield until ph reading in serial is 4"); Serial.println(" "); Serial.println("Thats it your calibrated and your readings are accurate!");
}
//*************************Take Ten Readings And Average ****************************// void ReadPH(){ i=1; sum=0; while(i<=10){ reading=analogRead(PHPin); sum=sum+reading; delay(20); i++; } average=sum/10.0; //converting the average to PH 3.5 part convers mv to ph phValue=average*K*5/1024;
}
//*************************** Print useful data to moniter ****************************// void PrintSerial(){
Serial.print(" pH:"); Serial.print(phValue); Serial.println(" ");
}
//****************** Calculate a K value *********************************************// void Calabrate(){
Kn=((Cal_pH*1024)/(average*5)); Serial.print("If pH 7, Cell Konstant= :"); Serial.println(Kn);
}; |
Temperature Compensation:
For the time being we will not be implementing temperature correcting, because it is not a major effect. We may correct for it later if it proves to be a bigger problem than we anticipated. Here is a example of how measured PH will change with temperature [pH 4 potassium biphthalate buffer standard ] [1]
Temperature [C] | pH |
---|---|
10 | 4.00 |
15 | 4.00 |
20 | 4.00 |
25 | 4.01 |
30 | 4.02 |
35 | 4.02 |
40 | 4.04 |
45 | 4.05 |
50 | 4.06 |
55 | 4.08 |
60 | 4.09 |
Reference: