pH Sensor

The pH Sensor project demonstrates how to use an Arduino Nano to interface with a pH sensor. This project reads pH values from the sensor and prints them to the serial monitor. The pH sensor provides an analog voltage output corresponding to the pH level of the solution it is immersed in.

How It Works

A pH probe is an electrochemical cell. A thin glass membrane at its tip develops a potential difference that depends on the hydrogen-ion activity of the solution, measured against a stable internal reference electrode. The relationship follows the Nernst equation: about 59.16 mV per pH unit at 25 °C, with 0 mV at pH 7.

That signal cannot be read directly. The probe's source impedance is enormous — on the order of 100 MΩ — so any ordinary input loads it down to nothing. A signal-conditioning board such as the PH-4502C provides the required high-impedance buffer amplifier and shifts the ±414 mV range up into something an ADC can sample.

The Arduino Nano samples with a 10-bit ADC, so analogRead() returns 0–1023 across 5 V. Because the useful span is only a few hundred millivolts spread over the full ADC range, a stable supply and careful averaging matter more here than with most sensors.

Calibration is mandatory and perishable. Probes drift as the glass membrane ages, so a two-point calibration with pH 6.86 and pH 4.00 buffer solutions should be repeated regularly — monthly for continuous use.

Components Needed

  • Arduino Nano
  • pH Sensor
  • Jumper Wires
  • pH Buffer Solutions (pH 4.0 and pH 7.0)
  • pH Probe Storage Solution (KCl Solution)

Wiring to the Arduino Nano

Connect Po to A0, V+ to 5 V and GND to ground, then screw the probe onto the BNC connector. Output and supply both sit inside the 5 V domain of this board, so no level shifting is needed.

The two trimmers on the PH-4502C are not interchangeable. The one nearest the BNC sets the offset — adjust it with the probe in pH 7 buffer until the output reads mid-scale. The other sets the alarm threshold and is irrelevant for analog reading.

Keep the probe cable away from mains wiring, motors and relays. The signal is tiny and high-impedance, which makes it an excellent antenna for electrical noise.

Board pinArduino Nano pinFunction
Po (analog out)A0Buffered pH voltage
V+ 5VSupply — the PH-4502C expects 5 V
G / GNDGNDCommon ground
BNC—Probe connection

Build and Upload

Open the Arduino IDE and paste the provided code.

Upload the code to the Arduino Nano.

Once the code is uploaded, open the serial monitor.

The serial monitor will display pH values read from the sensor periodically.

Example Code

Two-point calibrated pH reading with median filtering. Upload it with the board set to Arduino Nano and open the Serial Monitor at 9600 baud.

Two-point calibrated pH reading with median filtering
const int PH_PIN = A0;
const float VREF = 5.0;
const int   ADC_MAX = 1023;

// From two-point calibration — replace with your own measured values
const float V_PH7  = 2.50;    // volts measured in pH 6.86 buffer
const float V_PH4  = 3.04;    // volts measured in pH 4.00 buffer

float slope() { return (7.0 - 4.0) / (V_PH7 - V_PH4); }

float readVolts() {
  int s[9];
  for (int i = 0; i < 9; i++) { s[i] = analogRead(PH_PIN); delay(10); }
  for (int i = 0; i < 8; i++)
    for (int j = i + 1; j < 9; j++)
      if (s[j] < s[i]) { int t = s[i]; s[i] = s[j]; s[j] = t; }
  return s[4] * VREF / ADC_MAX;        // median of nine
}

void setup() { Serial.begin(9600); }

void loop() {
  float v  = readVolts();
  float ph = 7.0 + (v - V_PH7) * slope();

  Serial.print("V=");
  Serial.print(v, 3);
  Serial.print("  pH=");
  Serial.println(ph, 2);
  delay(1000);
}

Applications

A ph sensor turns up in a wide range of projects. These are the uses where it is the right choice rather than a compromise:

  • Hydroponic and aquaponic nutrient monitoring, where pH drives nutrient uptake
  • Aquarium and pond water-quality logging
  • Swimming pool chemistry management
  • Soil slurry testing in agriculture
  • Process control in brewing, fermentation and small-scale chemistry

Working with the Arduino Nano

The Arduino Nano is built around the ATmega328P and runs on 5 V logic with 2 KB of SRAM and 32 KB of program flash. These details change how this circuit is wired and what the sketch can do, so they are worth stating plainly before you build.

The Nano shares the Uno’s ATmega328P but adds A6 and A7, which are analog-input only and cannot be used as digital pins.

Its DIP footprint drops straight into a breadboard, which suits permanent sensor builds.

Older clones use the CH340 USB bridge and may need that driver plus the "ATmega328P (Old Bootloader)" processor option.

Arduino Nano characteristicValueWhy it matters here
Logic voltage5 VMatches most hobby modules directly
ADC resolution10-bit (0–1023)Sets how finely an analog reading can be resolved
Analog inputsA0–A7 (eight channels, two more than the Uno)Determines how many analog sensors can share the board
PWM outputsD3, D5, D6, D9, D10 and D11Needed for brightness, speed and tone control
I²C pinsA4 (SDA) and A5 (SCL)Fixed by hardware — wiring copied from another board may not match
Interrupt pinsD2 and D3 onlyRequired for counting fast or asynchronous events
Seriala single hardware UART shared with USBMonitor runs at 9600 baud by default

Troubleshooting

Most problems with this module fall into a handful of categories. Work through these before suspecting the part itself:

  • The reading barely moves between buffers — the probe is dead or the BNC is not seated. A healthy probe shows a clear difference between pH 4 and pH 7.
  • Readings drift steadily upward or downward — the probe needs recalibration, or it has dried out.
  • Values jump when a pump or heater switches — electrical noise is coupling in. Ground the solution with a stainless probe and separate the cable from power wiring.
  • pH reads correctly at room temperature but not when hot — the Nernst slope is temperature dependent. Add a temperature sensor and compensate.
  • The probe was stored dry — glass electrodes must be kept in storage solution. A dried probe may never recover.
  • Code written for an ESP board gives odd analog values — the Arduino Nano uses a 10-bit ADC returning 0–1023; rescale any constant taken from a 12-bit example.
  • An I²C sensor is not found after copying wiring from another Arduino — on the Arduino Nano I²C is on A4 (SDA) and A5 (SCL).

Taking It Further on the Arduino Nano

Once the basic reading works, where you go next depends very much on which board you are using. These are the directions that suit the Arduino Nano specifically:

The Nano’s DIP footprint makes it the natural choice once a breadboard prototype becomes a soldered build. Mount it on female headers rather than soldering it down, so the board can be recovered if the project is retired.

With A6 and A7 available in addition to A0–A5, the Nano can read two more analog sensors than an Uno. Remember that those two pins are analog-input only — they cannot be used with digitalWrite or as digital inputs.

For battery-powered builds, the Nano’s regulator and USB bridge dominate idle current. Powering the 5V pin directly from a regulated supply and removing the power LED substantially extends runtime.

Notes and Practical Limits

Never store a pH probe in distilled water. It leaches ions out of the glass membrane and ruins it. Use the manufacturer's storage solution, or failing that, pH 4 buffer.

Temperature compensation is not optional for accurate work. At 50 °C the Nernst slope is about 64 mV per pH unit rather than 59 mV, which is a significant error if ignored.