Projects / Drinking water TDS and pH meter

Drinking water TDS and pH meter

Intermediate2 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. NANO

    Test the temperature

    Print the water temperature.

  2. NANOTDSDS18B2022.6°C

    Read the TDS probe

    Print the voltage in a known solution.

  3. NANODS18B2022.6°C

    Calibrate the pH probe

    Use pH 4 and pH 7 buffers.

  4. NANO

    Enter the voltages

    Update V_PH7 and V_PH4.

  5. NANO

    Add the compensation

    Apply the temperature formula.

  6. NANOHelloPCF8574

    Show the result

    Put the numbers and the range flag on the LCD.

  7. NANO

    Compare

    Check against a borrowed meter.

In short

How do you build a drinking water TDS and pH meter?

A TDS probe and a pH probe check drinking water, show the values and say whether they are inside the BIS 10500 limits. You need Arduino Nano, TDS sensor module, pH sensor kit (analog), DS18B20 waterproof probe, Resistor 4.7 kΩ and 16x2 LCD with I2C backpack (PCF8574). It takes 7 steps and about 120 minutes.

Level
Intermediate
Time
About 120 min
Parts
6

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
TDS module VCC and GNDNano 5V and GNDPower
TDS module signalNano A0Analogue reading
pH board VCC and GNDNano 5V and GNDPower
pH board PO (analogue output)Nano A1Analogue reading
DS18B20 red, blackNano 5V, GNDPower
DS18B20 yellow (data)Nano D2, with 4.7 kΩ to 5VTemperature
LCD SDA and SCLNano A4 and A5Display

Code

A TDS probe measures how well water conducts electricity and converts that to an estimate of dissolved solids in ppm; a pH probe makes a small voltage that changes with acidity. Both change with temperature, so the DS18B20 supplies the water temperature for compensation. Calibrate the pH probe with two buffer solutions at pH 4 and 7, write down the voltages it prints and enter them in the code; probes drift and need recalibrating every few weeks, and must be kept wet in storage solution. The limits used here (TDS up to 500 ppm and pH 6.5 to 8.5) follow the acceptable limits of BIS 10500 for drinking water. This is an indicative hobby meter: it does not detect bacteria, heavy metals, pesticides or many other hazards, so never use it to decide that water is safe to drink; use an accredited laboratory test for that. Rinse probes in clean water between samples and do not put the pH board's probe in strong acids or bases. Arduino IDE, board "Arduino Nano" (try the Old Bootloader option if the upload fails).

Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

// TDS and pH meter. Libraries: OneWire, DallasTemperature, LiquidCrystal_I2C. Board: Arduino Nano.
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

OneWire ow(2); DallasTemperature ds(&ow);
LiquidCrystal_I2C lcd(0x27, 16, 2);
const float VREF = 5.0;
// pH two-point calibration: put the probe in pH 7 and pH 4 buffer, read the printed voltages, and enter them here.
float V_PH7 = 2.50, V_PH4 = 3.05;                // placeholders, replace with your own readings
float TDS_FACTOR = 1.00;                          // adjust against a borrowed meter and a known solution

float readVolts(int pin) {                        // average 30 readings, drop none for simplicity
  long s = 0; for (int i = 0; i < 30; i++) { s += analogRead(pin); delay(5); }
  return (s / 30.0) * VREF / 1023.0;
}

void setup() {
  Serial.begin(115200); ds.begin(); lcd.init(); lcd.backlight();
}

void loop() {
  ds.requestTemperatures(); float t = ds.getTempCByIndex(0);
  if (t < -50) t = 25;                             // sensor missing: assume 25 C

  float vT = readVolts(A0);
  float comp = vT / (1.0 + 0.02 * (t - 25.0));     // temperature compensation of the conductivity reading
  float tds = (133.42 * comp * comp * comp - 255.86 * comp * comp + 857.39 * comp) * 0.5 * TDS_FACTOR;   // ppm

  float vP = readVolts(A1);
  float slope = (7.0 - 4.0) / (V_PH7 - V_PH4);     // pH units per volt from the two buffers
  float ph = 7.0 + (vP - V_PH7) * slope;

  Serial.print("T "); Serial.print(t); Serial.print(" TDS "); Serial.print(tds); Serial.print(" V "); Serial.print(vT);
  Serial.print(" pH "); Serial.print(ph); Serial.print(" V "); Serial.println(vP);

  lcd.clear();
  lcd.setCursor(0, 0); lcd.print("TDS "); lcd.print((int)tds); lcd.print(" T "); lcd.print(t, 0);
  lcd.setCursor(0, 1); lcd.print("pH "); lcd.print(ph, 1); lcd.print((tds <= 500 && ph >= 6.5 && ph <= 8.5) ? " in range" : " CHECK");
  delay(2000);
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

T 24.50 TDS 1343.11 V 2.50 pH 6.99 V 2.50
T 24.50 TDS 1343.46 V 2.50 pH 6.99 V 2.50
T 24.50 TDS 1343.98 V 2.50 pH 6.99 V 2.50

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Tap waterTDS and pH in a plausible range
Distilled waterTDS near 0
Buffer solution pH 7Reads 7.0 within 0.2
Warm and cold samplesTDS stays steady after compensation

If it does not work

pH reading drifts

Recalibrate and keep the probe wet.

TDS jumps

Keep the probe away from the sides of the glass and stir gently.

Temperature reads -127

Check the DS18B20 wiring and pull-up resistor.

Always CHECK

Re-run the calibration and check the limits.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the drinking water TDS and pH meter?

Arduino Nano, TDS sensor module, pH sensor kit (analog), DS18B20 waterproof probe, Resistor 4.7 kΩ and 16x2 LCD with I2C backpack (PCF8574).

How long does the drinking water TDS and pH meter take to build?

About 120 minutes for a intermediate maker, in 7 steps.

How do I know the drinking water TDS and pH meter works?

Tap water: TDS and pH in a plausible range. Distilled water: TDS near 0. Buffer solution pH 7: Reads 7.0 within 0.2.

pH reading drifts: what should I check?

Recalibrate and keep the probe wet.

TDS jumps: what should I check?

Keep the probe away from the sides of the glass and stir gently.

Temperature reads -127: what should I check?

Check the DS18B20 wiring and pull-up resistor.

Always CHECK: what should I check?

Re-run the calibration and check the limits.