How to use a pH sensor with Arduino

Posted on by

pH Sensor with Probe.

Measuring the pH can be very useful if we are developing an aquarium, a hydroponic or an automated aquaponic. Next we will explain how this sensor works, how we should calibrate it and we will put an example of functional code to use it with Arduino.

How it works

PH is a measure of acidity or alkalinity of a solution, the pH scale ranges from 0 to 14. The pH indicates the concentration of hydrogen [H] + ions present in certain solutions. It can accurately be quantified by a sensor that measures the potential difference between two electrodes: a reference electrode (silver / silver chloride) and a glass electrode that is sensitive to hydrogen ion. This is what form the probe. We also have to use an electronic circuit to condition the signal appropriately and we can use this sensor with a micro-controller, such as Arduino.

Here are some examples of everyday substances and their pH:

Substance pH approximate
Lemon juice
2,4 – 2,6
Cola drink
2,5 – 2,9
Orange or apple juice
6,5 – 7,4
7,38 – 7,42
9,0 a 10,0


We discuss the specifications of circuit and probe separately since they can be purchased separately and there are variations that must be taken into account depending on the probe used.

Probes Specifications

Electrode Type
pH Range Temperature (ºC) Zero Point (pH) Response Time (min) Noise (mV)
65-1 0-14 0-80 7±1 <2
BX-5 0-14 0-80 7X±11 <2
E-201 0-14 0-80 7±0.5 <2 <0.5
E-201-C 0-14 0-80 7X±0.5 <2 <0.5
95-1 0-14 0-80 7X±0.5 <2 <0.5
E-900 0-14 0-80 7X±0.5 <2 <0.5

Circuit Specifications:

The circuit we are using has screen printed and Logo_PHsensor v1.1 on the bottom layer of the circuit.

 Supply Voltage 5 V
 Current  5-10 mA
  Consumption ≤ 0.5 W
 Working Temperature 10-50 ºC
 Green LED  Power
 Red LED Límite de pH


 To  Temperature
 Do  Limit pH Signal
 Po  Analog pH value
 G  Analog GND
 G  Supply GND
 V+  Supply (5V)

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.


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() {

void loop() {
 for(int i=0;i<10;i++) 
 for(int i=0;i<9;i++)
  for(int j=i+1;j<10;j++)
 for(int i=2;i<8;i++)
 float pHVol=(float)avgValue*5.0/1024/6;
 float phValue = -5.70 * pHVol + 21.34;
 Serial.print("sensor = ");

Comments are disabled