Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » DIY Ph Meter using PH Sensor & Arduino with OLED Display
Arduino Projects

DIY Ph Meter using PH Sensor & Arduino with OLED Display

Mamtaz AlamBy Mamtaz AlamUpdated:August 21, 20227 Comments9 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
Ph Sensor Arduino
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

In this project we will design a Ph Meter by Interfacing Analog Ph Sensor with Arduino.


Overview

In chemistry, pH is a scale used to specify how acidic or basic a water-based solution is. Acidic solutions have a lower pH, while basic solutions have a higher pH. Thus Ph sensor has the ability to determine the Ph of any solution, i.e it tells whether the substance is acidic, basic or neutral in nature. By knowing the Ph, we can monitor the water quality in Agricultural Farm and also in Fish Farming. Similarly, Ph Sensor has a wide range of applications like wastewater treatment, pharmaceuticals, chemicals & petrochemicals.

In this basic tutorial, we will learn how to interface Gravity Ph Sensor with Arduino. We will design a simple Ph Meter and display the Ph value on OLED/LCD Display. We will also learn about the construction & working of the Ph Sensor. Finally, we will learn the calibration method which will determine the correctness and accuracy of the sensor. The Ph Sensor can also be interfaced with other higher-level microcontrollers like NodeMCU ESP8266 & STM32 which I will discuss in future.

You can add a few more extra sensors to this project like TDS Sensor, Turbidity Sensor & Dissolved Oxygen Sensor for Water Quality Monitoring.




Bill of Materials

Following are the components required for making this project. All the components can be easily purchased from Amazon. The components purchased link is given.

S.N.Components QuantityPurchase Links
1Arduino UNO1Amazon | AliExpress
2Ph Sensor Kit1DfRobot
3OLED Display1Amazon | AliExpress
4Connecting Wires10Amazon | AliExpress
4Breadboard1Amazon | AliExpress

What is Ph?

The term PH is a quantitative measure of the acidity or basicity of aqueous or other liquid solutions. The term, widely used in chemistry, biology, and agronomy, translates the values of the concentration of the hydrogen ion which ordinarily ranges between about 1 and 10−14 gram-equivalents per liter—into numbers between 0 and 14.

Ph Scale

In pure water, which is neutral (neither acidic nor alkaline), the concentration of the hydrogen ion is 10−7 gram-equivalents per liter, which corresponds to a pH of 7. A solution with a pH less than 7 is considered acidic; a solution with a pH greater than 7 is considered basic, or alkaline.


What is Ph Meter?

A pH meter is a scientific instrument that measures the hydrogen-ion activity in water-based solutions, indicating its acidity or alkalinity expressed as pH. The pH meter measures the difference in electrical potential between a pH electrode and a reference electrode, and so the pH meter is sometimes referred to as a “potentiometric pH meter“. The difference in electrical potential relates to the acidity or pH of the solution.


Ph Meter Construction & Working

The Ph Sensor has a rod-like structure usually made of glass, with a bulb containing the sensor at the bottom. The glass electrode for measuring the pH has a glass bulb specifically designed to be selective to hydrogen-ion concentration. On immersion in the solution to be tested, hydrogen ions in the test solution exchange for other positively charged ions on the glass bulb, creating an electrochemical potential across the bulb. The electronic amplifier detects the difference in electrical potential between the two electrodes generated in the measurement and converts the potential difference to pH units. The magnitude of the electrochemical potential across the glass bulb is linearly related to the pH according to the Nernst equation.

Ph Sensor Construction & Working

The reference electrode is insensitive to the pH of the solution, being composed of a metallic conductor, which connects to the display. This conductor is immersed in an electrolyte solution, typically potassium chloride, which comes into contact with the test solution through a porous ceramic membrane. The display consists of a voltmeter, which displays voltage in units of pH.


Gravity Analog Ph Sensor/Meter Kit

DFRobot Ph Sensor

DFRobot Gravity: Analog pH meter V2 is specifically designed to measure the pH of the solution and reflect the acidity or alkalinity. As an upgraded version of pH meter V1, the sensor greatly improves the precision and user experience. The onboard voltage regulator chip supports the wide voltage supply of 3.3~5.5V. The output signal filtered by hardware has low jitter. With this Ph Sensor, you can quickly build the pH meter to measure the Ph value of the different aqueous solutions.

Features

  1. Input Voltage: 3.3~5.5V
  2. Hardware filtered output signal, low jitter
  3. Gravity connector and BNC connector
  4. Easy Calibration
  5. Uniform size of sensor & connector for easy Mechanical Fitting.


Specifications

The Ph Sensor Kit has Signal Conversion Board (Transmitter) V2 and also pH Probe. Both of them are connected with each other. The features of both of these parts are as follows.

Signal Conversion Board (Transmitter) V2
  1. Supply Voltage: 3.3~5.5V
  2. Output Voltage: 0~3.0V
  3. Probe Connector: BNC
  4. Signal Connector: PH2.0-3P
  5. Measurement Accuracy: ±0.1@25℃
  6. Dimension: 42mm32mm/1.661.26in
pH Probe
  1. Probe Type: Laboratory Grade
  2. Detection Range: 0~14
  3. Temperature Range: 5~60°C
  4. Zero Point: 7±0.5
  5. Response Time: <2min
  6. Internal Resistance: <250MΩ
  7. Probe Life: >0.5 years (depending on the frequency of use)
  8. Cable Length: 100cm

To learn more about the Ph Sensor you can check the DfRobot official article here: Gravity: Analog pH Sensor/Meter Kit V2


Interfacing Gravity Analog Ph Sensor with Arduino

Now let us interface Ph Sensor with Arduino using Simple Arduino Code. The connection is fairly simple and circuit/schematic is given below.

Interfacing Ph Sensor with Arduino

Ph Sensor has 3 pins that need to be connected to Arduino. So, connect the VCC pin to 5V of Arduino and GND to GND. Connect its analog pin to A0 of Arduino as shown in image above.

Ph Sensor Arduino Connection




Source Code/Program

The source code for Interfacing DFRobot Gravity Ph Sensor with Arduino is given below. Simply copy the code and upload it to the Arduino Board.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#define SensorPin A0          // the pH meter Analog output is connected with the Arduino’s Analog
unsigned long int avgValue;  //Store the average value of the sensor feedback
float b;
int buf[10],temp;
void setup()
{
  pinMode(13,OUTPUT);  
  Serial.begin(9600);  
  Serial.println("Ready");    //Test the serial monitor
}
void loop()
{
  for(int i=0;i<10;i++)       //Get 10 sample value from the sensor for smooth the value
  {
    buf[i]=analogRead(SensorPin);
    delay(10);
  }
  for(int i=0;i<9;i++)        //sort the analog from small to large
  {
    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++)                      //take the average value of 6 center sample
    avgValue+=buf[i];
  float phValue=(float)avgValue*5.0/1024/6; //convert the analog into millivolt
  phValue=3.5*phValue;                      //convert the millivolt into pH value
  Serial.print("    pH:");  
  Serial.print(phValue,2);
  Serial.println(" ");
  digitalWrite(13, HIGH);      
  delay(800);
  digitalWrite(13, LOW);
}


Aqueous Solution for Testing the Ph of different Solutions

For testing the Ph meter designed above, I used 4 different solutions with different Ph value. I took the following solutions

1. Soap Water: Ph value is around 9-10
2. Milk: Ph Value is around 6.5 to 6.7
3. Tap Water: Ph Value is around 6.5 to 8.5
4. Lemon Juice: Ph Value is in between 2 to 3

PH Solutions


Testing & Results

Once the code is uploaded to Arduino Board, you can open serial monitor and start testing the Ph Sensor. I tested the Ph Sensor with All 4 solutions given above and found the following results

  • 1 Soap
  • 2 milk
  • 3 water
  • 4 lemon

  • 1 Soap
  • 2 milk
  • 3 water
  • 4 lemon


Interfacing Ph Sensor with Arduino & OLED Display

Now Let us display the Ph Value on OLED Display instead of Serial Monitor. To do that we need to add a 0.96″ I2C OLED Display to Arduino Uno. Hence the connection diagram is shown below.

The connection is fairly simple again. Connect the Analog pin of Ph Sensor to Arduino A0 pin and supply 5V to it. Also, connect the SDA SCL pin of OLED Display to Arduino A4 & A5 Pin respectively.


Source Code/Program

The source code for Interfacing DFRobot Gravity Ph Sensor with Arduino and OLED Display is given below. Simply copy the code and upload it to the Arduino Board.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
 
#define SensorPin 0          // the pH meter Analog output is connected with the Arduino’s Analog
unsigned long int avgValue;  //Store the average value of the sensor feedback
float b;
int buf[10],temp;
 
#define SCREEN_WIDTH 128  // OLED display width, in pixels
#define SCREEN_HEIGHT 64  // OLED display height, in pixels
#define OLED_RESET    -1  // Reset pin # (or -1 if sharing reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup()
{
  pinMode(13,OUTPUT);  
  Serial.begin(9600);  
  Serial.println("Ready");    //Test the serial monitor
 
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
{
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
}
display.display();
delay(2);
display.clearDisplay();
 
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(0,5);
display.print("PH Sensor");
display.display();
delay(3000);
  
}
void loop()
{
  for(int i=0;i<10;i++)       //Get 10 sample value from the sensor for smooth the value
  {
    buf[i]=analogRead(SensorPin);
    delay(10);
  }
  for(int i=0;i<9;i++)        //sort the analog from small to large
  {
    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++)                      //take the average value of 6 center sample
    avgValue+=buf[i];
  float phValue=(float)avgValue*5.0/1024/6; //convert the analog into millivolt
  phValue=3.5*phValue;                      //convert the millivolt into pH value
  Serial.print("    pH:");  
  Serial.print(phValue,2);
  Serial.println(" ");
  
  display.clearDisplay();
  display.setTextSize(2);
  display.setCursor(20,0);
  display.println("Ph Value");
 
  display.setTextSize(3);
  display.setCursor(30,30);
  display.print(phValue);
 
  display.display();
 
  digitalWrite(13, HIGH);      
  delay(800);
  digitalWrite(13, LOW);
}




Testing & Results

Once the code is uploaded the OLED display will start showing the value of Ph. Dipping the Ph electrode on different solutions will give different value as shown in the images below.

  • 11
  • 12
  • 13

  • 11
  • 12
  • 13


Ph Sensor Calibration

If you worked with PH metering before you will know that PH values range from 0-14. Where PH 0 is very acidic, PH 7 will be neutral and PH 14 very alkaline. The biggest problem while using the Ph Sensor is about the calibration. Since the Ph sensor is an analog sensor so there is a need for calibration as the output is dependent upon the voltage. So we need a solution whose Ph Strength is known to us. There are various buffer solutions available in the market whose PH is fixed.

The simplest method to calibrate the Ph sensor is to dip the ph electrode on the solution of known strength and observe the reading. For example, when the electrode is dipped in a solution whose Ph Value is 7, the reading should show 7. In case it doesn’t show the correct reading, you need to rotate the potentiometer placed on Signal Conversion Board (Transmitter) V2. Once the reading matches, you can stop rotating and hence the sensor is calibrated.

Note: In my case I used Milk for calibrating the sensor as I didn’t have any buffer solutions. The ph of milk is between 6.5 to 6.7. So you can also use Milk for calibration.


Precautions & Things to Follow

  1. The BNC connector and the signal conversion board must be kept dry and clean, otherwise, it will affect the input impedance, resulting in an inaccurate measurement. If it is damp, it needs to be dried.
  2. The signal conversion board cannot be directly placed on a wet or semiconductor surface, otherwise, it will affect the input impedance, resulting in an inaccurate measurement. It is recommended to use the nylon pillar to fix the signal conversion board, allow a certain distance between the signal conversion board and the surface.
  3. The sensitive glass bubble in the head of the pH probe should avoid touching with the hard material. Any damage or scratches will cause the electrode to fail.
  4. After completing the measurement, disconnect the pH probe from the signal conversion board. The pH probe should not be connected to the signal conversion board without the power supply for a long time.



Video Tutorial & Explanation

Ph Senor Arduino Interfacing Tutorial | Working, Calibration Method & Code
Watch this video on YouTube.

If you want an IoT Based Ph Meter, you can follow the IoT pH Meter Tutorial and make it work with ESP32 & Thingspeak Server.

Incase if you are not satisfied with the Analog Ph Sensor, then you can use Atlas Scientific Ph Sensor which has better accuracy & result due to I2C & UART interface.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleMeasure Tilt Angle with MPU6050 & STM32 Microcontroller
Next Article Wireless Bluetooth Controlled Robot using Arduino

Related Posts

DC Energy Meter using Arduino

Build a DC Energy Meter using Arduino – 32V/5A

Updated:August 26, 20252K
Interfacing ADXL375 Accelerometer with Arduino

Interfacing ADXL375 Accelerometer with Arduino (±200g)

Updated:June 28, 2025
PZEM-004T Arduino Energy Meter

DIY AC Energy Meter using PZEM-004T & Arduino

Updated:March 6, 20258K
Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Updated:February 2, 20259K
Password Based Door Lock Security System Using Arduino & Keypad

Password Based Door Lock Security System Using Arduino & Keypad

Updated:February 2, 20252436K
Earthquake Detector Alarm with with Accelerometer & Arduino

Earthquake Detector Alarm with Accelerometer & Arduino

Updated:February 2, 2025661K
View 7 Comments

7 Comments

  1. Riccardo on March 3, 2020 1:36 AM

    Hi, I can’t find the code, haven’t you entered it yet? Thank you very much

    Reply
    • Mr. Alam on March 3, 2020 1:43 AM

      Hey the code is already there.
      Please try viewing the page through computer. Sometimes code is not visible to smart phone users.

      Reply
  2. Mac on October 7, 2020 4:42 AM

    Hi, thank you for the diagram and code. My pH meter is a Gravity pH Meter V2.0 and doesn’t have a potentiometer screw to turn. How would I calibrate my pH sensor in this case?

    Reply
  3. karlos on November 5, 2020 1:30 AM

    hello sir .. I want to learn how to combine the tds sensor with the ph sensor at the same time and then connect to the IOT
    Help me
    thank you

    Reply
  4. cem on December 9, 2020 9:16 PM

    Hi Mr. Alam,

    Thanks for sharing. Do you have code for v2? Current code doesn’t work for that. I believe because of change in calibration procedure. Not sure. I found a code for v2 in dfrobot forum but it has no oled display. Nevertheless, I am sharing for whom anyone proceed it without display.

    https://wiki.dfrobot.com/Gravity__Analog_pH_Sensor_Meter_Kit_V2_SKU_SEN0161-V2

    Reply
  5. Jeff on December 26, 2020 11:18 AM

    Hi. I note in the introduction to your great video at https://www.youtube.com/watch?v=eCxrU_tfb9w you mention “. . . .The Ph Sensor can also be interfaced with other higher-level microcontrollers like NodeMCU ESP8266 & STM32 which I will discuss in the future.”

    Is the video showing how to connect using the Esp8266 (or even Esp32?) coming or is it already available?

    Reply
  6. Shania Kyle Sioson on April 2, 2023 8:36 AM

    Hello, do you have a code that I can use in ph sensor with LCD & data storing code?

    Reply

CommentsCancel reply

Latest Posts
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

May 31, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

February 1, 2026
Top Posts & Pages
  • IoT Based PM & Air Quality Monitoring System using ESP32
    IoT Based PM & Air Quality Monitoring System using ESP32
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
  • LD2410 Sensor with ESP32 - Human Presence Detection
    LD2410 Sensor with ESP32 - Human Presence Detection
  • ECG Graph Monitoring with AD8232 ECG Sensor & Arduino
    ECG Graph Monitoring with AD8232 ECG Sensor & Arduino
  • ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
    ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
  • L293D Dual H-Bridge Motor Driver IC Pins, Circuit, Working
    L293D Dual H-Bridge Motor Driver IC Pins, Circuit, Working
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (204)
    • ESP32 MicroPython (7)
    • ESP32 Projects (81)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.