pH Measurement with Arduino

This tutorial will guide you How to measure water quality and other parameters ? and How  to use with Arduino? In this tutorial we use analog pH meter sensor, specially designed for Arduino controllers and has built-in simple, convenient and practical connection and features. It has an LED which works as the Power Indicator, a BNC connector and PH2.0 sensor interface. To use it, just connect the pH sensor with BNC connector, and plug the PH2.0 interface into the analog input port of any Arduino controller.
Attention: In order to ensure the accuracy of the pH probe, you need to use the standard solution to calibrate it regularly. These standard calibration solutions come with this pH sensor. Generally, the period is about half a year. If you measure the dirty aqueous solution, you need to increase the frequency of calibration.


  • Water quality testing
  • Aquaculture

In chemistry, pH is the negative log of the activity of the hydrogen ion in an aqueous solution. Solutions with a pH less than 7 are said to be acidic and solutions with a pH greater than 7 are basic or alkaline. Pure water has a pH of 7. Contrary to popular belief, this value can extend past 0 or 14 for sufficiently concentrated acids and bases, however it is difficult to measure precisely.
The pH scale is traceable to a set of standard solutions whose pH is established by international agreement. Primary pH standard values are determined using a concentration cell with transference, by measuring the potential difference between a hydrogen electrode and a standard electrode such as the silver chloride electrode. Measurement of pH for aqueous solutions can be done with a glass electrode and a pH meter, or using indicators.
Mathematically, pH is the negative logarithm of the activity of the (solvated) hydronium ion, more often (albeit somewhat inaccurately) expressed as the measure of the hydronium ion concentration.

Step to Use the pH Sensor with Arduino


  • Please use an external switching power supply, and the voltage as close as possible to the +5.00V. More accurate the voltage, more higher the accuracy.
  • Before using pH electrode, you need to calibrate it by the standard solution provided in sensor kit, in order to obtain more accurate results.
  • The best environment temperature is about 25 ℃, and the pH value is known and reliable, close to the measured value. If you measure the acidic sample, the pH value of the standard solution should be 4.00. If you measure the alkaline sample, the pH value of the standard solution should be 9.18.
  • Before the pH electrode measure different solutions, Cleaning of electrode using deionized water is recommended.

Step 1: Components Required for pH Measurement

ph Measurement Components
ph Measurement Components

Step 2: pH Measurement Arduino Circuit

Do not solder on pH Module, it is high sensitive, high impedance circuit. You may easily damage it by soldering wires on it, Never cut or solder the BNC Connector wires.

Connect pH sensor according to the circuit diagram, that is, The pH electrode is connected to the BNC connector on the pH sensor circuit board,and pH sensor board is connected to the digital pins 2 and 3 (software serial) of the Arduino controller. When the Arduino controller gets power,you will see the blue LED on board is on. (color and LED depends on board manufacturer)

Arduino ph Measurement Circuit
ph Measurement Circuit

Step 3: pH Measurement Arduino Code

Upload the sample code to the Arduino controller.

//pH Measurement using Atlas Scientific pH Sensor

#include <SoftwareSerial.h> //We are using Software serial to free the hardware serial port
#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 software serial port is going to work

char ph_data[20];    //20 byte char array to hold incoming data from pH
char computerdata[20]; //20 byte char array to hold incoming data from PC
byte received_from_computer=0; //how many characters recived
byte received_from_sensor=0; 
byte arduino_only=0; //if you would like to operate the pH Circuit with the Arduino only and
                     //not use the serial monitor to send it commands set this to 1.

byte startup=0;    //Used to make sure the Arduino rakes over control of the pH Circuit properly
float ph=0;        //used to hold a floating point number that is the pH
byte string_received=0;  //used to identify when we have received a string from the pH circuit

void setup() {
  Serial.begin(38400);   //enable the hardware serial at BAUD: 38400
  myserial.begin(38400); //enalble the software serial

void serialEvent(){    //this interrupt will trigger when the data coming from
                       //the serial monitor(pc/mac/other) is received.
  if(arduino_only!=1){ //if Arduino_only does not equal 1 this function will be bypassed.    
    received_from_computer=Serial.readBytesUntil(13,computerdata,20);  //we read the data sent from the serial monitor
                                                                       //(pc/mac/other) until we see a <CR>. We also count
                                                                       //how many characters have been received.
    computerdata[received_from_computer]=0;        //we add a 0 to the spot in the array just after the last
                                                   //character we received.. This will stop us from
                                                   //transmitting incorrect data that may have been left
                                                    //in the buffer. 
    myserial.print(computerdata);        //we transmit the data received from the serial monitor
                                         //(pc/mac/other) through the soft serial port to the
                                         //pH Circuit.   
    myserial.print('\r');               //all data sent to the pH Circuit must end with a <CR>.

void loop() {                           //if we see that the pH Circuit has sent a character.
  if(myserial.available() > 0){

      //we read the data sent from pH Circuit until we see a <CR>. We also count how many character have
      //been received.

      //we add a 0 to the spot in the array just after the last character we received. This will stop us from
      //transmitting incorrect data that may have been left in the buffer.                                                                                   

      //a flag used when the Arduino is controlling the pH Circuit to let us know that a complete string
        has been received.
      //lets transmit that data received from the pH Circuit to the serial monitor.
  if(arduino_only==1){Arduino_Control();} //If the var arduino_only is set to one we will call this
                                //function. Letting the Arduino take over control of the pH Circuit

void Arduino_Control(){
    if(startup==0){        //if the Arduino just booted up, we need to set some things up first.
        myserial.print("e\r");   //take the pH Circuit out of continues mode.
        delay(50);              //on start up sometimes the first command is missed.
        myserial.print("e\r");  //so, let's send it twice.
        delay(50);       //a short delay after the pH Circuit was taken out of continues mode is used to make   
                               //sure we don't over load it with commands.
        startup=1;       //startup is completed, let's not do this again during normal operation.
    delay(800);     //we will take a reading ever 800ms.
    myserial.print("R\r");    //send it the command to take a single reading.
    if(string_received==1){   //did we get data back from the ph Circuit?
      ph=atof(ph_data);         //many people ask us "how do I convert a sting into a float?" This is how...
      if(ph>=7.5){Serial.println("high\r");}   //This is the proof that it has been converted into a float.
      if(ph<7.5){Serial.println("low\r");}     //This is the proof that it has been converted into a float.
      string_received=0;                      //reset the string received flag.  

Step 4: Testing and Result

Put the pH electrode into the standard solution whose pH value is 7.00. Open the serial monitor of the Arduino IDE, you can see the pH value printed on it.

Leave a Reply