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.

TDS Sensor Arduino: Complete Water Quality Measurement Guide

Monitoring water quality used to require expensive lab equipment and specialized training. Today, a TDS sensor Arduino setup costing under $15 can measure dissolved solids in your aquarium, hydroponics system, or drinking water with reasonable accuracy.

I’ve deployed TDS monitoring systems in aquaculture facilities and home brewing setups over the past few years. This guide covers the practical knowledge you need to get reliable readings from these sensors, including the temperature compensation and calibration steps that most tutorials skip.

What Is TDS and Why Measure It?

TDS stands for Total Dissolved Solids. It represents the combined concentration of all inorganic and organic substances dissolved in water, including minerals, salts, metals, and ions. TDS is measured in parts per million (ppm) or milligrams per liter (mg/L), which are equivalent units.

When you measure TDS, you’re essentially measuring how “pure” the water is. Pure distilled water has near-zero TDS. Tap water typically ranges from 200-400 ppm. Seawater exceeds 30,000 ppm.

TDS Levels and Water Quality Classifications

TDS Level (ppm)ClassificationTypical Sources
0-50Very lowDistilled water, RO filtered
50-150Ideal drinkingQuality filtered water
150-300AcceptableMost tap water
300-500FairHard tap water
500-1000PoorWell water, some municipal
>1000UnsafeBrackish, contaminated

The EPA sets a secondary standard of 500 ppm as the maximum recommended TDS for drinking water. This isn’t a health-based limit but rather an aesthetic guideline, as high TDS water often tastes metallic or salty.

Common Applications for TDS Monitoring

Water quality monitoring with a TDS sensor Arduino system serves numerous practical purposes:

Aquarium and fish tank maintenance requires stable TDS levels. Most freshwater fish thrive between 100-300 ppm, while marine setups need much higher values.

Hydroponics systems depend on precise nutrient concentrations. Growers use TDS to ensure plants receive optimal mineral levels without over-fertilization.

Reverse osmosis filter performance monitoring shows when membranes need replacement. A functioning RO system should reduce TDS by 90-99%.

Drinking water quality assessment provides peace of mind about tap water or well water safety.

How TDS Sensors Work

TDS sensors don’t directly measure dissolved solids. Instead, they measure electrical conductivity (EC) and convert it to a TDS estimate.

Pure water conducts electricity poorly. As minerals and salts dissolve, they dissociate into ions that carry electrical charge. More dissolved solids means higher conductivity.

The sensor applies a small voltage across two electrodes immersed in the water. By measuring the resulting current, the sensor determines conductivity. An algorithm then converts conductivity to TDS using this relationship:

TDS (ppm) = EC (µS/cm) × 0.5

This conversion factor assumes typical mixed mineral content. Different water sources may require adjusted factors (0.5 to 0.7 range).

Why Temperature Matters

Conductivity changes significantly with temperature. Warmer water conducts electricity better because ions move faster. A 1°C temperature increase causes roughly 2% conductivity increase.

Without temperature compensation, a TDS reading at 35°C could be 20% higher than the same water at 25°C. Quality TDS systems include temperature sensors or manual temperature input to correct for this effect.

Gravity Analog TDS Sensor Specifications

The DFRobot Gravity TDS Sensor is the most common module for Arduino projects. Understanding its specifications helps you work within its limitations.

ParameterSpecification
Input Voltage3.3V to 5.5V
Output Voltage0V to 2.3V (analog)
Working Current3-6 mA
TDS Range0-1000 ppm
Accuracy±10% full scale (at 25°C)
Probe Type2-electrode, waterproof
Maximum Water Temperature55°C
Signal TypeAC excitation

The AC excitation is crucial for long-term reliability. DC signals cause electrolysis and electrode polarization, rapidly degrading the probe. AC signals reverse polarity continuously, preventing this buildup.

TDS Sensor Module Pinout

PinFunctionArduino Connection
+ (VCC)Power supply5V or 3.3V
– (GND)GroundGND
A (Signal)Analog outputAny analog pin (A0-A5)

The sensor module includes an interface board that handles signal conditioning. The probe connects to the interface board via a proprietary connector.

TDS Sensor Arduino Wiring Diagram

Connecting the TDS sensor to Arduino requires only three wires for basic operation.

Basic Connections

TDS Module PinArduino Uno Pin
VCC (+)5V
GND (-)GND
Signal (A)A0

For accurate readings, add a DS18B20 temperature sensor:

With Temperature Compensation

ComponentArduino Pin
TDS SignalA0
DS18B20 DataD7
DS18B20 VCC5V
DS18B20 GNDGND
4.7kΩ PullupBetween Data and VCC

Position the temperature sensor probe close to the TDS probe so both measure the same water temperature.

Basic TDS Sensor Arduino Code

This sketch reads the TDS sensor and displays values on the Serial Monitor:

#define TdsSensorPin A0

#define VREF 5.0              // Arduino ADC reference voltage

#define SCOUNT 30             // Number of samples for filtering

int analogBuffer[SCOUNT];

int analogBufferIndex = 0;

float averageVoltage = 0;

float tdsValue = 0;

float temperature = 25.0;     // Default temperature for compensation

void setup() {

  Serial.begin(115200);

  pinMode(TdsSensorPin, INPUT);

}

void loop() {

  static unsigned long analogSampleTimepoint = millis();

  // Sample every 40ms

  if (millis() – analogSampleTimepoint > 40U) {

    analogSampleTimepoint = millis();

    analogBuffer[analogBufferIndex] = analogRead(TdsSensorPin);

    analogBufferIndex++;

    if (analogBufferIndex == SCOUNT)

      analogBufferIndex = 0;

  }

  static unsigned long printTimepoint = millis();

  // Calculate and print every 800ms

  if (millis() – printTimepoint > 800U) {

    printTimepoint = millis();

    // Get median value for stability

    int tempBuffer[SCOUNT];

    for (int i = 0; i < SCOUNT; i++)

      tempBuffer[i] = analogBuffer[i];

    averageVoltage = getMedianNum(tempBuffer, SCOUNT) * VREF / 1024.0;

    // Temperature compensation formula

    float compensationCoefficient = 1.0 + 0.02 * (temperature – 25.0);

    float compensationVoltage = averageVoltage / compensationCoefficient;

    // Convert voltage to TDS

    tdsValue = (133.42 * compensationVoltage * compensationVoltage * compensationVoltage

                – 255.86 * compensationVoltage * compensationVoltage

                + 857.39 * compensationVoltage) * 0.5;

    Serial.print(“TDS Value: “);

    Serial.print(tdsValue, 0);

    Serial.println(” ppm”);

  }

}

int getMedianNum(int bArray[], int iFilterLen) {

  int bTab[iFilterLen];

  for (int i = 0; i < iFilterLen; i++)

    bTab[i] = bArray[i];

  // Sort array

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

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

      if (bTab[i] > bTab[i + 1]) {

        int bTemp = bTab[i];

        bTab[i] = bTab[i + 1];

        bTab[i + 1] = bTemp;

      }

    }

  }

  // Return median

  if ((iFilterLen & 1) > 0)

    return bTab[(iFilterLen – 1) / 2];

  else

    return (bTab[iFilterLen / 2] + bTab[iFilterLen / 2 – 1]) / 2;

}

The median filtering algorithm removes noise and outliers from the readings, producing more stable output.

Adding Temperature Compensation with DS18B20

For accurate measurements across varying water temperatures, add a DS18B20 sensor:

#include <OneWire.h>

#include <DallasTemperature.h>

#define ONE_WIRE_BUS 7

#define TdsSensorPin A0

#define VREF 5.0

#define SCOUNT 30

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature tempSensor(&oneWire);

int analogBuffer[SCOUNT];

int analogBufferIndex = 0;

float temperature = 25.0;

float tdsValue = 0;

void setup() {

  Serial.begin(115200);

  tempSensor.begin();

  pinMode(TdsSensorPin, INPUT);

}

void loop() {

  // Read temperature

  tempSensor.requestTemperatures();

  temperature = tempSensor.getTempCByIndex(0);

  // Sample TDS

  static unsigned long sampleTime = millis();

  if (millis() – sampleTime > 40U) {

    sampleTime = millis();

    analogBuffer[analogBufferIndex++] = analogRead(TdsSensorPin);

    if (analogBufferIndex == SCOUNT) analogBufferIndex = 0;

  }

  // Calculate TDS with temperature compensation

  static unsigned long printTime = millis();

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

    printTime = millis();

    float voltage = getMedianNum(analogBuffer, SCOUNT) * VREF / 1024.0;

    float compCoeff = 1.0 + 0.02 * (temperature – 25.0);

    float compVoltage = voltage / compCoeff;

    tdsValue = (133.42 * pow(compVoltage, 3)

                – 255.86 * pow(compVoltage, 2)

                + 857.39 * compVoltage) * 0.5;

    Serial.print(“Temp: “);

    Serial.print(temperature, 1);

    Serial.print(“°C | TDS: “);

    Serial.print(tdsValue, 0);

    Serial.println(” ppm”);

  }

}

Install the OneWire and DallasTemperature libraries through the Arduino Library Manager before compiling.

Calibrating Your TDS Sensor

Factory calibration provides reasonable accuracy for most applications. However, for precise measurements, calibrate against a known standard solution.

Calibration Requirements

You need either a standard calibration solution (1413 µS/cm or 707 ppm) or a calibrated TDS pen meter for reference.

Calibration Procedure

Using the DFRobot GravityTDS library simplifies calibration:

#include <EEPROM.h>

#include “GravityTDS.h”

#define TdsSensorPin A1

GravityTDS gravityTds;

float temperature = 25.0;

float tdsValue = 0;

void setup() {

  Serial.begin(115200);

  gravityTds.setPin(TdsSensorPin);

  gravityTds.setAref(5.0);

  gravityTds.setAdcRange(1024);

  gravityTds.begin();

  Serial.println(“Calibration Commands:”);

  Serial.println(“enter – Start calibration mode”);

  Serial.println(“cal:XXX – Calibrate to XXX ppm”);

  Serial.println(“exit – Save and exit calibration”);

}

void loop() {

  gravityTds.setTemperature(temperature);

  gravityTds.update();

  tdsValue = gravityTds.getTdsValue();

  Serial.print(“TDS: “);

  Serial.print(tdsValue, 0);

  Serial.println(” ppm”);

  delay(1000);

}

To calibrate:

  1. Clean and dry the probe
  2. Immerse in calibration solution at 25°C
  3. Wait for stable readings
  4. Type “enter” in Serial Monitor
  5. Type “cal:707” (or your solution’s ppm value)
  6. Type “exit” to save calibration

The calibration coefficient stores in EEPROM and persists across power cycles.

Displaying TDS on LCD or OLED

For standalone operation, add a display:

16×2 LCD with I2C Connection

LCD ModuleArduino 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(“TDS Meter”);

}

void displayTDS(float tds, float temp) {

  lcd.setCursor(0, 0);

  lcd.print(“TDS: “);

  lcd.print((int)tds);

  lcd.print(” ppm    “);

  lcd.setCursor(0, 1);

  lcd.print(“Temp: “);

  lcd.print(temp, 1);

  lcd.print(“C   “);

}

Troubleshooting TDS Sensor Problems

Common issues and solutions:

Readings Always Zero or Very Low

Possible CauseSolution
Probe not in waterEnsure electrodes submerged
Poor connectionsCheck wiring and connectors
Wrong pin assignmentVerify analog pin in code
Damaged probeTest with multimeter

Unstable or Jumping Readings

Possible CauseSolution
Air bubbles on probeGently agitate probe
Probe too close to container edgePosition in center of water
Electrical interferenceAdd 0.1µF capacitor on signal line
Insufficient samplingIncrease SCOUNT value

Readings Don’t Match Reference Meter

Possible CauseSolution
No temperature compensationAdd DS18B20 sensor
Calibration driftRecalibrate with standard solution
Different conversion factorsAdjust the 0.5 multiplier
Contaminated probeClean with distilled water

Probe Maintenance Tips

Clean the probe electrodes monthly with distilled water and a soft brush. Never use abrasives or solvents.

Store the probe dry when not in use for extended periods. For continuous monitoring, replace probes annually as electrode degradation affects accuracy over time.

Useful Resources and Downloads

ResourceDescription
DFRobot GravityTDS LibraryOfficial Arduino library with calibration
DFRobot WikiComplete documentation
OneWire LibraryFor DS18B20 temperature sensor
DallasTemperature LibraryTemperature sensor support
Arduino IDEDevelopment environment

Component Sources

ComponentTypical PriceSuppliers
Gravity TDS Sensor$10-15DFRobot, Amazon, AliExpress
DS18B20 Waterproof$3-5Amazon, Adafruit
Arduino Uno$20-25Arduino Store, SparkFun
16×2 I2C LCD$5-8Amazon, eBay

Important Limitations to Understand

TDS meters measure total dissolved solids but cannot identify what those solids are. A reading of 300 ppm could be harmless calcium or dangerous lead, and the sensor cannot distinguish between them.

High TDS doesn’t necessarily mean unsafe water. Mineral water often has TDS above 500 ppm by design. Conversely, low TDS doesn’t guarantee safety, as biological contamination doesn’t affect conductivity measurements.

For drinking water safety assessment, TDS should be one data point among many, not the sole determinant. Laboratory testing remains necessary for detecting specific contaminants.

Frequently Asked Questions

Can I leave the TDS probe submerged continuously?

Yes, the probe is designed for long-term immersion. However, continuous exposure accelerates electrode wear. For monitoring applications, consider periodic rather than constant measurement. The sensor module and connector must stay dry, only the probe itself is waterproof.

Why do my readings differ from a commercial TDS pen?

Several factors cause discrepancies: different temperature compensation algorithms, different conversion factors (EC to TDS), calibration differences, and measurement timing. Commercial pens often average readings over several seconds, while Arduino readings may be instantaneous. Calibrate both devices against the same reference solution for meaningful comparison.

What’s the difference between TDS and EC measurements?

TDS (Total Dissolved Solids) and EC (Electrical Conductivity) measure related but distinct properties. EC measures how well water conducts electricity, expressed in microsiemens per centimeter (µS/cm). TDS estimates the mass of dissolved solids, expressed in ppm. The conversion TDS = EC × 0.5 is an approximation that assumes typical mixed-mineral content.

How often should I calibrate the sensor?

For casual monitoring, factory calibration suffices for months. For precise applications like hydroponics nutrient management, calibrate monthly or whenever readings seem inconsistent. Always recalibrate after replacing the probe or if the sensor has been stored dry for extended periods.

Can this sensor measure saltwater or pool water?

The standard 0-1000 ppm range sensor cannot accurately measure high-TDS water like pools (1500-3000 ppm) or saltwater (30,000+ ppm). The sensor saturates and gives maximum readings. DFRobot offers higher-range sensors for these applications, or you can dilute samples with distilled water and multiply the result.

Building Practical Water Monitoring Systems

The TDS sensor Arduino combination provides an accessible entry point into water quality monitoring. While not a replacement for laboratory analysis, it offers valuable real-time feedback for aquarium keepers, hydroponic growers, and anyone curious about their water quality.

Start with the basic circuit and code, verify operation with known water samples, then add temperature compensation for improved accuracy. For critical applications, invest time in proper calibration against standard solutions.

The insights gained from continuous monitoring often prove more valuable than occasional spot measurements, revealing trends and changes that single readings miss.

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.