Arduino pH Sensor Calibration

Arduino pH Sensor Calibration © CC BY-NC

Calibrating Atlas Scientific's EZO pH sensor using Arduino Uno.

  • 1,324 views
  • 3 comments
  • 4 respects

Components and supplies

Apps and online services

About this project

Calibration Theory

The most important part of calibration is watching the readings during the calibration process. It is easiest to calibrate the device in its default state (UART mode, with continuous readings enabled). Switching the device to I2C mode after calibration will not affect the stored calibration. If the device must be calibrated in I2C mode, be sure to continuously request readings so you can see the output from the probe. In this tutorial, the calibration will be done in UART mode.

Calibration Order

If this is your first time calibrating the EZO pH circuit, we recommend that you calibrate in the following order:

Single, Two point or Three point calibration

The Atlas EZO pH circuit has a flexible calibration protocol, allowing for single-point, two-point or three-point calibration.

Two-point calibration will provide high accuracy between 7.00 and the second point calibrated against such as 4.00

Three-point calibration will provide high accuracy over the full pH range. Three-point calibration at 4.00, 7.00 and 10.00 should be considered the standard.

Note: The first calibration point must be the mid-point (pH 7)

Assemble Hardware

The kit includes 1 EZO pH circuit, 1 pH probe, 1 female BNC connector, 1 4oz pH4 calibration solution, 1 4oz pH7 calibration solution, 1 4oz pH10 calibration solution, 1 4oz pH storage solution, 1 optional inline voltage isolator.

Ensure that the pH circuit is in UART mode. For instructions on switching between protocols, refer to the following LINK.

Use the breadboard to mount the circuit and BNC connector. Wire the pH circuit to the Arduino Uno as shown in the schematic above and connect the probe to the BNC connector.

Load Program Onto Arduino Uno

a) Download the sample code from this LINK. It will be in a folder titled "arduino_UNO_pH_sample_code".

b) Connect the Arduino to your computer.

c) Open the code downloaded from step a, in your Arduino IDE. If you do not have the IDE you can download it from HERE.

d) Compile and upload the code to Arduino.

e) Open the serial monitor. For access go to Tools -> Serial Monitor or press Ctrl+Shift+M on your keyboard. Set the baud rate to 9600 and select "Carriage return". You should now be able to communicate with the pH circuit. As a test, enter the command i which will return the device information.

Mid-point Calibration

a) Remove the soaker bottle and rinse off the pH probe.

b) Pour some of the pH 7.00 calibration solutions into a cup. Ensure that there is enough solution to cover the sensing area of the probe.

c) Place the pH probe into the cup and stir it around to remove trapped air. Let the probe sit in the calibration solution until the readings stabilize (small movement from one reading to the next is normal).

d) Once the readings have stabilized (1 - 2 minutes) issue the mid-point calibration command cal, mid, 7

Low-point Calibration

a) Rinse off the probe before calibrating to the low point.

b) Pour some of the pH 4.00 calibration solutions into a cup. Ensure that there is enough solution to cover the sensing area of the probe.

c) Place the pH probe into the cup and stir it around to remove trapped air. Let the probe sit in the calibration solution until the readings stabilize (small movement from one reading to the next is normal).

d) Once the readings have stabilized (1 - 2 minutes) issue the low-point calibration command cal, low, 4

High-point Calibration

a) Rinse off the probe before calibrating to the high point.

b) Pour some of the pH 10.00 calibration solutions into a cup. Ensure that there is enough solution to cover the sensing area of the probe.

c) Place the pH probe into the cup and stir it around to remove trapped air. Let the probe sit in the calibration solution until the readings stabilize (small movement from one reading to the next is normal).

d) Once the readings have stabilized (1 - 2 minutes) issue the high-point calibration command cal, high, 10

Additional Information

  • Issuing the cal,mid command after the EZO pH circuit has been calibrated, will clear the calibration points. Full calibration will have to be redone.
  • The EZO pH circuits default temperature compensation is set to 25°C. If the temperature of the calibration solution is +/- 2 °, consider setting the temperature compensation first. Temperature changes of < 2° C are insignificant.

Code

pH sensor calibration codeC/C++
//This code was written to be easy to understand.
//Modify this code as you see fit.
//This code will output data to the Arduino serial monitor.
//Type commands into the Arduino serial monitor to control the pH circuit.
//This code was written in the Arduino 1.8.9 IDE
//An Arduino UNO was used to test this code.
//This code was last tested 6/2019


#include <SoftwareSerial.h>                           //we have to include the SoftwareSerial library, or else we can't use it
#define rx 2                                          //define what pin rx is going to be
#define tx 3                                          //define what pin tx is going to be

SoftwareSerial myserial(rx, tx);                      //define how the soft serial port is going to work


String inputstring = "";                              //a string to hold incoming data from the PC
String sensorstring = "";                             //a string to hold the data from the Atlas Scientific product
boolean input_string_complete = false;                //have we received all the data from the PC
boolean sensor_string_complete = false;               //have we received all the data from the Atlas Scientific product
float pH;                                             //used to hold a floating point number that is the pH



void setup() {                                        //set up the hardware
  Serial.begin(9600);                                 //set baud rate for the hardware serial port_0 to 9600
  myserial.begin(9600);                               //set baud rate for the software serial port to 9600
  inputstring.reserve(10);                            //set aside some bytes for receiving data from the PC
  sensorstring.reserve(30);                           //set aside some bytes for receiving data from Atlas Scientific product
}


void serialEvent() {                                  //if the hardware serial port_0 receives a char
  inputstring = Serial.readStringUntil(13);           //read the string until we see a <CR>
  input_string_complete = true;                       //set the flag used to tell if we have received a completed string from the PC
}


void loop() {                                         //here we go...

  if (input_string_complete == true) {                //if a string from the PC has been received in its entirety
    myserial.print(inputstring);                      //send that string to the Atlas Scientific product
    myserial.print('\r');                             //add a <CR> to the end of the string
    inputstring = "";                                 //clear the string
    input_string_complete = false;                    //reset the flag used to tell if we have received a completed string from the PC
  }

  if (myserial.available() > 0) {                     //if we see that the Atlas Scientific product has sent a character
    char inchar = (char)myserial.read();              //get the char we just received
    sensorstring += inchar;                           //add the char to the var called sensorstring
    if (inchar == '\r') {                             //if the incoming character is a <CR>
      sensor_string_complete = true;                  //set the flag
    }
  }


  if (sensor_string_complete == true) {               //if a string from the Atlas Scientific product has been received in its entirety
    Serial.println(sensorstring);                     //send that string to the PC's serial monitor
    /*                                                //uncomment this section to see how to convert the pH reading from a string to a float 
    if (isdigit(sensorstring[0])) {                   //if the first character in the string is a digit
      pH = sensorstring.toFloat();                    //convert the string to a floating point number so it can be evaluated by the Arduino
      if (pH >= 7.0) {                                //if the pH is greater than or equal to 7.0
        Serial.println("high");                       //print "high" this is demonstrating that the Arduino is evaluating the pH as a number and not as a string
      }
      if (pH <= 6.999) {                              //if the pH is less than or equal to 6.999
        Serial.println("low");                        //print "low" this is demonstrating that the Arduino is evaluating the pH as a number and not as a string
      }
    }
    */
    sensorstring = "";                                //clear the string
    sensor_string_complete = false;                   //reset the flag used to tell if we have received a completed string from the Atlas Scientific product
  }
}

Schematics

pH sensor calibration wiring diagram
Ph probe calibration wiring diagram ylrpvvduwm

Comments

Similar projects you might like

DIY pH Dosing Pump

by Atlas Scientific

  • 1,815 views
  • 2 comments
  • 16 respects

Smoke Detection using MQ-2 Gas Sensor

by Aritro Mukherjee

  • 270,595 views
  • 47 comments
  • 171 respects

How To Use DS18B20 Water Proof Temperature Sensor

Project showcase by IoTBoys

  • 70,613 views
  • 13 comments
  • 20 respects
Add projectSign up / Login