Contact Sales & After-Sales Service

Contact & Quotation

  • Inquire: Call 0086-755-23203480, or reach out via the form below/your sales contact to discuss our design, manufacturing, and assembly capabilities.
  • Quote: Email your PCB files to Sales@pcbsync.com (Preferred for large files) or submit online. We will contact you promptly. Please ensure your email is correct.
Drag & Drop Files, Choose Files to Upload You can upload up to 3 files.

Notes:
For PCB fabrication, we require PCB design file in Gerber RS-274X format (most preferred), *.PCB/DDB (Protel, inform your program version) format or *.BRD (Eagle) format. For PCB assembly, we require PCB design file in above mentioned format, drilling file and BOM. Click to download BOM template To avoid file missing, please include all files into one folder and compress it into .zip or .rar format.

pH Sensor Arduino: Complete Water Acidity Measurement Guide

Building a reliable pH sensor Arduino system took me several failed attempts before I understood what actually matters. The probe generates millivolt signals that drift with temperature, the signal conditioning board needs proper calibration, and those cheap pH electrodes from online marketplaces degrade faster than you’d expect.

This guide covers the practical knowledge I’ve accumulated from deploying pH monitoring in aquariums, hydroponics setups, and water quality testing applications. You’ll learn how pH electrodes actually work, how to wire them correctly to Arduino, and the calibration procedures that separate accurate readings from useless numbers.

Understanding pH Measurement Fundamentals

pH measures the hydrogen ion concentration in a solution on a logarithmic scale from 0 to 14. A pH of 7 represents neutrality, where pure water exists. Values below 7 indicate acidic solutions with higher hydrogen ion concentrations, while values above 7 indicate alkaline or basic solutions.

The logarithmic nature means each pH unit represents a tenfold change in hydrogen ion activity. A solution with pH 4 contains ten times more hydrogen ions than pH 5, and one hundred times more than pH 6. This exponential relationship explains why small pH changes can have significant effects in biological and chemical systems.

The pH Scale and Common Reference Points

pH ValueClassificationCommon Examples
0-1Strongly AcidicBattery acid, hydrochloric acid
2-3AcidicLemon juice, vinegar
4-5Mildly AcidicTomato juice, beer
6-7Near NeutralMilk, pure water
7-8Near NeutralBlood, seawater
9-10Mildly AlkalineBaking soda solution
11-12AlkalineAmmonia, soapy water
13-14Strongly AlkalineBleach, drain cleaner

Why Measure pH with Arduino?

Traditional handheld pH meters work fine for spot checks, but they can’t provide continuous monitoring or automated responses. A pH sensor Arduino system enables real-time data logging, automated dosing in hydroponics, aquarium alerts when pH drifts outside safe ranges, and integration with larger environmental monitoring systems.

Common applications include aquarium and fish tank water quality monitoring, hydroponic nutrient solution management, swimming pool maintenance automation, wastewater treatment monitoring, laboratory experiments and educational projects, and agricultural soil testing when combined with appropriate probes.

How pH Sensors Work

A pH electrode is essentially a specialized voltmeter that measures the electrical potential difference created by hydrogen ions interacting with a glass membrane.

The Glass Electrode Principle

The sensing element consists of a special glass membrane, typically made from lithium-doped silicate glass. When immersed in solution, hydrogen ions in the liquid interact with the hydrated outer layer of this glass, creating an electrical potential.

Inside the glass electrode sits a reference solution (usually potassium chloride) with a known, stable pH of 7. A silver wire coated with silver chloride connects to this internal solution, providing the electrical connection.

The voltage generated across the glass membrane follows the Nernst equation and changes by approximately 59.16 millivolts per pH unit at 25°C. This means a pH 4 solution produces roughly +177 mV compared to pH 7, while pH 10 produces approximately -177 mV.

pH Electrode Voltage Output

pH ValueTheoretical Voltage (at 25°C)
0+414 mV
4+177 mV
70 mV
10-177 mV
14-414 mV

The reference electrode provides a stable zero-voltage point for comparison. Most modern pH probes combine both measuring and reference electrodes in a single combination electrode connected via BNC connector.

Temperature Effects on pH Measurement

Temperature affects pH readings in two ways. First, the electrode’s voltage response changes with temperature (the 59.16 mV/pH value varies). Second, the actual pH of solutions changes with temperature independent of measurement effects.

Most pH sensor modules include provisions for temperature compensation. Adding a DS18B20 waterproof temperature sensor to your Arduino project allows automatic correction for electrode response variations.

Gravity Analog pH Sensor Specifications

The DFRobot Gravity pH Sensor V2 has become the standard choice for Arduino pH projects. Understanding its specifications helps you work within its capabilities.

ParameterSpecification
Input Voltage3.3V to 5.5V DC
Output Voltage0V to 3.0V (analog)
Working Current5-10 mA
pH Range0-14 pH
Accuracy±0.1 pH (at 25°C)
Response Time≤1 minute
Temperature Range0-60°C
Probe ConnectorBNC

The signal conditioning board handles the high-impedance electrode signal and converts it to a voltage range suitable for Arduino’s analog inputs. It includes hardware filtering to reduce noise and a potentiometer for offset calibration.

pH Sensor Module Pinout

PinFunctionArduino Connection
V+Power supply5V
GGroundGND
PoAnalog signal outputA0 (or any analog pin)

The probe connects to the signal board via BNC connector. Keep the BNC connection dry and free from contamination.

pH Sensor Arduino Wiring Diagram

Connecting a pH sensor to Arduino requires only three wires for basic operation.

Basic Connection Table

pH Module PinArduino Uno Pin
V+ (VCC)5V
G (GND)GND
Po (Signal)A0

For projects requiring temperature compensation, add a DS18B20 sensor:

With Temperature Compensation

ComponentArduino Pin
pH Signal (Po)A0
DS18B20 DataD2
DS18B20 VCC5V
DS18B20 GNDGND
4.7kΩ PullupBetween Data and VCC

Place both probes in close proximity to measure the same water temperature for accurate compensation.

Basic pH Sensor Arduino Code

This sketch reads pH values and displays them on the Serial Monitor:

#define PH_PIN A0

#define OFFSET 0.00       // Calibration offset

#define SAMPLES 10        // Number of samples for averaging

float voltage, phValue;

void setup() {

  Serial.begin(9600);

  Serial.println(“pH Meter Initialized”);

}

void loop() {

  // Take multiple samples and average

  float totalVoltage = 0;

  for (int i = 0; i < SAMPLES; i++) {

    totalVoltage += analogRead(PH_PIN);

    delay(10);

  }

  voltage = (totalVoltage / SAMPLES) * 5.0 / 1024.0;

  // Convert voltage to pH

  // Linear conversion: pH 7 = 2.5V, slope = -5.7 pH/V

  phValue = 7.0 + ((2.5 – voltage) / 0.18);

  phValue += OFFSET;

  Serial.print(“Voltage: “);

  Serial.print(voltage, 2);

  Serial.print(“V | pH: “);

  Serial.println(phValue, 2);

  delay(1000);

}

The averaging reduces noise from electrical interference. Adjust the OFFSET value during calibration.

Advanced Code with Median Filtering

For more stable readings, use median filtering to reject outliers:

#define PH_PIN A0

#define ARRAY_SIZE 30

int readings[ARRAY_SIZE];

int readIndex = 0;

float calibration = 21.34;  // Adjust during calibration

void setup() {

  Serial.begin(9600);

  pinMode(PH_PIN, INPUT);

}

void loop() {

  // Collect samples

  for (int i = 0; i < ARRAY_SIZE; i++) {

    readings[i] = analogRead(PH_PIN);

    delay(30);

  }

  // Sort array for median

  sortArray(readings, ARRAY_SIZE);

  // Average middle 6 values

  float avgValue = 0;

  for (int i = 12; i < 18; i++) {

    avgValue += readings[i];

  }

  avgValue /= 6;

  // Convert to voltage and pH

  float voltage = avgValue * 5.0 / 1024.0;

  float phValue = -5.70 * voltage + calibration;

  Serial.print(“pH: “);

  Serial.println(phValue, 2);

  delay(800);

}

void sortArray(int arr[], int size) {

  for (int i = 0; i < size – 1; i++) {

    for (int j = 0; j < size – i – 1; j++) {

      if (arr[j] > arr[j + 1]) {

        int temp = arr[j];

        arr[j] = arr[j + 1];

        arr[j + 1] = temp;

      }

    }

  }

}

The median filtering algorithm discards extreme readings that might result from electrical noise or measurement glitches.

Calibrating Your pH Sensor

Calibration is mandatory for accurate pH measurement. Without it, readings may be off by several pH units.

Calibration Requirements

You need standard buffer solutions for calibration. These come as premixed liquids or powder packets that you dissolve in distilled water.

Buffer SolutionPurpose
pH 7.00Zero point (neutral) calibration
pH 4.01Acid slope calibration
pH 10.01Optional, for alkaline verification

Two-Point Calibration Procedure

Step 1: Prepare the probe. Rinse with distilled water and gently blot dry with a soft cloth or paper towel. Never wipe the glass bulb, as this can create static charges affecting readings.

Step 2: Calibrate pH 7 first. Immerse the probe in pH 7 buffer solution. Wait 1-2 minutes for readings to stabilize. Use the potentiometer on the signal board or adjust the offset value in your code until the display shows 7.00.

Step 3: Calibrate pH 4 second. Rinse the probe with distilled water, blot dry, and immerse in pH 4 buffer. Wait for stabilization. If using the DFRobot library, the software automatically recognizes and calibrates this point.

Step 4: Verify with pH 10 (optional). Repeat the rinse and immerse process with pH 10 buffer to verify the alkaline range accuracy.

Using DFRobot Library for Calibration

The DFRobot_PH library simplifies calibration with serial commands:

#include “DFRobot_PH.h”

#include <EEPROM.h>

#define PH_PIN A0

float voltage, phValue, temperature = 25;

DFRobot_PH ph;

void setup() {

  Serial.begin(115200);

  ph.begin();

  Serial.println(“Commands: enterph, calph, exitph”);

}

void loop() {

  static unsigned long timepoint = millis();

  if (millis() – timepoint > 1000U) {

    timepoint = millis();

    voltage = analogRead(PH_PIN) / 1024.0 * 5000;

    phValue = ph.readPH(voltage, temperature);

    Serial.print(“pH: “);

    Serial.println(phValue, 2);

  }

  ph.calibration(voltage, temperature);

}

Serial commands include “enterph” to enter calibration mode, “calph” to calibrate current buffer (auto-detected), and “exitph” to save and exit calibration mode.

Displaying pH on LCD or OLED

For standalone operation without a computer, add a display:

16×2 I2C LCD Connections

LCD PinArduino Pin
VCC5V
GNDGND
SDAA4
SCLA5

#include <Wire.h>

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {

  lcd.init();

  lcd.backlight();

  lcd.setCursor(0, 0);

  lcd.print(“pH Meter v1.0”);

}

void displayPH(float ph) {

  lcd.setCursor(0, 0);

  lcd.print(“pH Value:       “);

  lcd.setCursor(10, 0);

  lcd.print(ph, 2);

  lcd.setCursor(0, 1);

  if (ph < 6.5) {

    lcd.print(“Status: Acidic  “);

  } else if (ph > 7.5) {

    lcd.print(“Status: Alkaline”);

  } else {

    lcd.print(“Status: Neutral “);

  }

}

Troubleshooting Common pH Sensor Problems

pH sensors are more temperamental than most Arduino sensors. Here are solutions to common issues:

Unstable or Drifting Readings

Possible CauseSolution
Air bubbles on glass bulbGently tap probe to dislodge bubbles
Dry or contaminated probeSoak in pH 4 buffer for several hours
Electrical interferenceShield cables, add 100nF capacitor
Temperature fluctuationsAdd temperature compensation
Old or damaged probeReplace probe (typically 1-2 year lifespan)

Readings Stuck at One Value

Possible CauseSolution
Broken glass membraneInspect for cracks, replace if damaged
Disconnected BNC cableCheck all connections
Shorted circuit boardInspect for solder bridges or moisture
Wrong pin assignmentVerify analog pin in code

Inaccurate After Calibration

Possible CauseSolution
Expired buffer solutionsUse fresh buffers (check expiration)
Contaminated probeClean with distilled water
Temperature differenceCalibrate at same temperature as measurement
Buffer on probe surfaceRinse thoroughly between buffers

Probe Care and Maintenance

The glass electrode requires proper care to maintain accuracy and extend its lifespan. Store the probe in pH 4 buffer or electrode storage solution when not in use for extended periods. Never let the glass membrane dry out completely.

Clean the probe by soaking in 0.1M HCl for 30 minutes if response becomes sluggish, then rinse with distilled water. Never touch the glass bulb with your fingers, as oils can contaminate the surface.

Replace probes when response time becomes excessively slow (more than 5 minutes to stabilize), when readings no longer calibrate properly, or when visible damage exists on the glass membrane.

Useful Resources and Downloads

ResourceDescription
DFRobot_PH LibraryOfficial Arduino library with calibration
DFRobot WikiComplete sensor documentation
OneWire LibraryFor DS18B20 temperature sensor
LiquidCrystal_I2C LibraryFor I2C LCD displays
Arduino IDEDevelopment environment

Component Sources

ComponentTypical PriceSuppliers
Gravity pH Sensor V2$30-40DFRobot, Amazon
Replacement pH Probe$15-25DFRobot, AliExpress
pH Buffer Set (4, 7, 10)$10-15Amazon, laboratory suppliers
DS18B20 Waterproof$3-5Amazon, Adafruit
Arduino Uno$20-25Arduino Store, SparkFun

Frequently Asked Questions

How often should I calibrate my pH sensor?

For casual use, monthly calibration maintains reasonable accuracy. For critical applications like hydroponics nutrient management, calibrate weekly or whenever readings seem inconsistent. Always calibrate after the probe has been stored dry or unused for extended periods. The probe’s response characteristics change over time, and regular calibration compensates for this drift.

Why do my readings jump around even with averaging?

Electrical noise from nearby motors, switching power supplies, or long unshielded cables causes unstable readings. Add a 100nF capacitor between the signal pin and ground close to the Arduino. Use twisted pair cables for longer runs. Keep the pH sensor away from high-current devices. If problems persist, try a separate regulated power supply instead of USB power.

Can I measure pH in soil directly with this sensor?

Standard glass pH electrodes are designed for aqueous solutions, not direct soil measurement. For soil testing, create a slurry by mixing soil with distilled water (1:1 ratio by volume), let it settle, then measure the liquid portion. Specialized soil pH probes with spear-tip designs exist for direct insertion but require different interfacing considerations.

How long do pH probes last?

Consumer-grade pH probes typically last 1-2 years with proper care. Signs of a dying probe include slow response time (more than 2-3 minutes to stabilize), inability to calibrate correctly, and readings that drift continuously. Laboratory-grade probes may last longer but cost significantly more. Always store probes wet in proper storage solution to maximize lifespan.

What’s the difference between pH sensors and ORP sensors?

pH measures hydrogen ion concentration (acidity/alkalinity), while ORP (Oxidation-Reduction Potential) measures electron activity, indicating a solution’s ability to oxidize or reduce other substances. Swimming pools often use both: pH for comfort and safety, ORP for disinfection effectiveness. The sensors look similar and use comparable interfacing methods, but they measure fundamentally different properties and aren’t interchangeable.

Building Reliable pH Monitoring Systems

A well-designed pH sensor Arduino system provides valuable data for numerous applications. The key to success lies in understanding the electrode’s limitations, implementing proper calibration procedures, and maintaining the probe correctly.

Start with the basic wiring and code examples, verify operation with known buffer solutions, then expand functionality with displays, data logging, or network connectivity. For critical applications, consider adding redundancy with multiple probes or regular cross-checks against a calibrated reference meter.

The combination of Arduino’s flexibility and affordable pH sensors makes automated water chemistry monitoring accessible to hobbyists and professionals alike.

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Sales & After-Sales Service

Contact & Quotation

  • Inquire: Call 0086-755-23203480, or reach out via the form below/your sales contact to discuss our design, manufacturing, and assembly capabilities.

  • Quote: Email your PCB files to Sales@pcbsync.com (Preferred for large files) or submit online. We will contact you promptly. Please ensure your email is correct.

Drag & Drop Files, Choose Files to Upload You can upload up to 3 files.

Notes:
For PCB fabrication, we require PCB design file in Gerber RS-274X format (most preferred), *.PCB/DDB (Protel, inform your program version) format or *.BRD (Eagle) format. For PCB assembly, we require PCB design file in above mentioned format, drilling file and BOM. Click to download BOM template To avoid file missing, please include all files into one folder and compress it into .zip or .rar format.