DIY IoT Water pH Meter using pH Sensor & ESP32

In this blog, we’ll make our own DIY IoT-based water pH meter using a pH sensor and an ESP32 WiFi module to check the pH level of water thereby determining water quality.

What is pH?

It is a unit of measurement for alkalinity or acidity of a solution; more specifically, the pH measures the number of hydrogen ions in a solution; the acronym pH stands for potential of hydrogen ions; this has become a practical way of handling alkalinity figures, rather than other slightly more complicated methods. It may be carefully determined with a pH meter, which measures the potential difference between two electrolytes.

The hydrogen ion potential scale runs from 1 to 14, with 1 to 6 indicating a more acidic substance, 7 indicating distilled water, which has a neutral value, and 8 to 14 indicating a more alkaline substance.

The pH scale contains a logarithmic progression, which implies that the difference between one numerical unit and the next can be ten times more basic or acidic depending on the situation.

Proposed System

This is a unique tutorial because we will be utilizing a more sophisticated pH Sensor. The pH Sensor utilized here is an analog pH Sensor that provides a linear pH measurement in the range of 0 to 14 pH. We’ll transfer the data to ThingSpeak Server instead of displaying it on an OLED panel. ThingSpeak provides real-time visualization of data sent by our ESP32 device. Because the ESP32 has a 12-bit controller with an integrated ADC, it can measure data more precisely than the Arduino, which only has a 10-bit ADC.

It has a high-resolution pH probe that takes liquid pH readings at user-defined intervals and sends the data to remote servers. The pH probe has a five-foot cable and can be dipped in any liquid. It takes less than a minute for a response. This IoT-based pH meter can be used in aquariums, hydroponics, laboratories, and other applications. So, let’s see how we can connect a pH sensor to an ESP32 and create our own pH meter. The pH Sensor Calibration technique is also covered in the tutorial.

Components Required:

  • ESP32 ESP-32S Development Board (ESP-WROOM-32)
  • PH SENSOR KIT for Water
  • 9V Battery or DC Adapter
  • Connecting Wires
  • Breadboard

PH Sensor KIT for Water

pH Sensor Kit

This Analog pH Meter Kit for Arduino, ESP8266, ESP32, and other Microcontrollers features an industrial real-time electrode. It has a built-in simple, convenient, and practical connection and employs an industry electrode. It has a long battery life (up to a year), making it ideal for long-term internet monitoring.

An LED on the signal connector board serves as a power indicator. A BNC-type connector and a PH sensor interface are also included on the board. To use it, simply attach the pH sensor to a BNC connection, then plug the PH interface into any microcontroller’s analog input port. You can quickly determine the pH value if it is configured. A multimeter can also be used to determine the output voltage.

The sensitive glass membrane of this industrial pH electrode has a low impedance. It has a fast response time and great temperature stability, making it suitable for a wide range of PH tests. It has a high level of repeatability, is difficult to hydrolyze, and can eliminate basic alkali mistakes.

The output voltage is linear from 0 to 14 pH. The Ag/AgCl gel electrolyte salt bridge, which serves as the reference system, has a steady half-cell potential and outstanding anti-pollution performance. Because the ring PTFE membrane is difficult to clog, the electrode can be used for long-term online detection.


PH Sensor Specifications

  • Module Power: DC 9.00V 1A
  • Measuring Range: 0-14PH
  • Accuracy: ± 0.1pH (24 )
  • Response Time: 1min
  • Industry pH Electrode with BNC Connector
  • Power Indicator LED
  • Output: Analog values in the range of (0.5V to 3V)
  • Alkali Error: 0.2PH
  • Internal Resistance: 250MO

Calibration Instruction

This instrument has been calibrated to work with the PH sensor that comes with the kit. If the PH sensor probe is changed, the results may not be correct. If the PH sensor Probe is changed, calibration is required. The temperature of the solution has a direct relationship with the results.

PH4 = 1.5V, PH7 = 2.0V, and PH9 = 2.5V are the calibration values for the sensor. To utilise this sensor, place the PH Sensor probe vertically and store it for a long time. If the sensor probe is used several times over the course of two to three days, great results will be obtained.

Before inserting the sensor prove tube in the test solution, rinse it in deionized water and dab it with tissue paper. The findings will take about 30 to 40 seconds to stabilize. Before inserting the probe into the storage solution, rinse it again in deionized water, dab it with dry tissue paper, and then place the storage lid.


PH sensor probe Tube tip is extremely delicate, and it should not be handled or placed on the ground. When not in use, the bulb-type tip should be stored in the storage solution.

Interfacing & Testing PH Sensor with ESP32

Let’s start with a basic interface and testing of the pH sensor with the ESP32 WiFi Module before moving on to the IoT pH Meter. This is a basic wiring diagram.

Interfacing & Testing PH Sensor with ESP32

Use an external 9V battery or a 9V DC supply to power the pH Sensor. Connect the pH Sensor signal board’s output pin to the ESP32’s VP, which can be used as an A0 pin. Because the sensor’s output ranges from 0.5 to 3 volts, it may be utilized with the ESP32’s analog pins.

IoT Based pH Meter

Basic Test Code

The pH sensor is a traditional analog device. As a result, the analogue output voltage will be converted to a pH value. Here’s a code for an ESP32 with a pH sensor.

Copy the code and paste it into the Arduino IDE’s editor. Select the ESP32 and the COM port from the Board Manager. The code is now ready to be uploaded.

const int potPin=A0;
float ph;
float Value=0;

void setup() {
// put your setup code here, to run once:
void loop(){

Value= analogRead(potPin);
Serial.print(” | “);
float voltage=Value*(3.3/4095.0);

Open the Serial Monitor after uploading the code to see the sensor values.

We analysed lemon juice, which had a pH of 2.8 to 3.0.

A simple detergent solution with a Ph greater than 8 was also tried.

IoT Based pH Meter

If you haven’t changed the probe that came with the Ph sensor Kit, there isn’t any need to calibrate the sensor.

Otherwise, you can do so by setting the Ph module’s 5k resistor as seen in the image below.

Ph Sensor Calibration

IoT Based Water pH Meter using pH Sensor & ESP32

Let’s write some more code to create an IoT-based pH meter. We can monitor the pH value from anywhere in the world with this code. The pH data will be monitored online using the Thingspeak server.

ThingSpeak is an excellent tool for IoT-related applications. We may use the ThingSpeak site to monitor and control our system via the Internet by using the Channels and web pages that ThingSpeak provides. To begin, you must first sign up for ThingSpeak.

. So visit and create an account.

Thingspeak Setup

Then make a new channel and add a pH Value widget to it.

After that, make the API keys. This key is necessary for programming changes and data settings.

Source Code/Program

The code for an IoT-based pH meter employing a pH sensor and an ESP32 may be seen below.

String apiKey = “*************”;
const char *ssid = “*************”;
const char *password = “*************”;

By pasting the API key copied from Thingspeak Dashboard, you must update the API key. Also, update the Wi-Fi credentials, the SSID name for the Wi-Fi, and the password for the Wi-Fi in the password variable.

Now copy and paste the following code into the ESP32 Board.

#include <WiFi.h>
const int potPin=A0;
float ph;
float Value=0;

String apiKey = “*************”; // Enter your Write API key from ThingSpeak
const char *ssid = “*************”; // replace with your wifi ssid and wpa2 key
const char *password = “*************”;
const char* server = “”;// don’t change this

WiFiClient client;

void setup() {
// put your setup code here, to run once:

Serial.print(“Connecting to “);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
// Print local IP address and start web server
Serial.println(“WiFi connected.”);
Serial.println(“IP address: “);


void loop() {
// put your main code here, to run repeatedly:
Value= analogRead(potPin);
Serial.print(” | “);
float voltage=Value*(3.3/4095.0);

if (client.connect(server, 80)) // “” or
String postStr = apiKey;
postStr += “&field1=”;
postStr += String(ph);
postStr += “\r\n”;

client.print(“POST /update HTTP/1.1\n”);
client.print(“Connection: close\n”);
client.print(“X-THINGSPEAKAPIKEY: ” + apiKey + “\n”);
client.print(“Content-Type: application/x-www-form-urlencoded\n”);
client.print(“Content-Length: “);

The ESP32 will attempt to connect to the WiFi network when the code has been uploaded. The data will be uploaded to the Thinkspeak server every 15 seconds.

The uploaded values can be viewed on the Thinkspeak dashboard’s private view section, as shown in the image.

IoT Based pH Meter Thingspeak


I hope all of you understand how to design an IoT Water pH Meter using pH Sensor & ESP32. We MATHA ELECTRONICS will be back soon with more informative blogs.

Leave a Reply

Your email address will not be published.