The TDS (Total Dissolved Solids) Sensor WPM356 by Whadda is an electronic device designed to measure the total dissolved solids in water, which indicates the water quality. It is commonly used in water purification systems, aquariums, hydroponics, and environmental water testing.
Pin Number | Name | Description |
---|---|---|
1 | VCC | Power supply (3.3V to 5.5V) |
2 | GND | Ground connection |
3 | AOUT | Analog output voltage |
4 | TEMP | Temperature sensor output (optional) |
// TDS Sensor Reading for Arduino UNO
const int TdsSensorPin = A0; // Analog input pin that the sensor is attached to
const float Vref = 5.0; // Analog reference voltage(Volt) of the ADC
const float SCOUNT = 30; // Number of samples for calibration
float analogBuffer[SCOUNT]; // Store the analog samples
int analogBufferTemp[SCOUNT];
int analogBufferIndex = 0, copyIndex = 0;
void setup() {
Serial.begin(9600);
pinMode(TdsSensorPin, INPUT);
}
void loop() {
static unsigned long analogSampleTimepoint = millis();
if (millis() - analogSampleTimepoint > 40U) { // Every 40 milliseconds, collect a sample
analogSampleTimepoint = millis();
analogBuffer[analogBufferIndex] = analogRead(TdsSensorPin); // Read the analog value
analogBufferIndex++;
if (analogBufferIndex == SCOUNT) {
analogBufferIndex = 0;
}
}
static unsigned long printTimepoint = millis();
if (millis() - printTimepoint > 800U) {
printTimepoint = millis();
for (copyIndex = 0; copyIndex < SCOUNT; copyIndex++) {
analogBufferTemp[copyIndex] = analogBuffer[copyIndex];
}
float averageVoltage = getMedianNum(analogBufferTemp, SCOUNT) * (float)Vref / 1024.0; // Convert analog reading to voltage
float tdsValue = (133.42 * averageVoltage * averageVoltage * averageVoltage - 255.86 * averageVoltage * averageVoltage + 857.39 * averageVoltage) * 0.5; // Convert voltage to TDS value
Serial.print("TDS Value = ");
Serial.print(tdsValue, 0);
Serial.println(" ppm");
}
}
int getMedianNum(int bArray[], int iFilterLen) {
int bTab[iFilterLen];
for (byte i = 0; i < iFilterLen; i++) {
bTab[i] = bArray[i];
}
int i, j, bTemp;
for (j = 0; j < iFilterLen - 1; j++) {
for (i = 0; i < iFilterLen - j - 1; i++) {
if (bTab[i] > bTab[i + 1]) {
bTemp = bTab[i];
bTab[i] = bTab[i + 1];
bTab[i + 1] = bTemp;
}
}
}
if ((iFilterLen & 1) > 0) {
bTemp = bTab[(iFilterLen - 1) / 2];
} else {
bTemp = (bTab[iFilterLen / 2] + bTab[iFilterLen / 2 - 1]) / 2;
}
return bTemp;
}
Q: Can the sensor be used in saltwater? A: Yes, but the measurement range and calibration may differ from freshwater applications.
Q: How often should the sensor be calibrated? A: Calibration frequency depends on usage, but typically once every month or after any maintenance.
Q: Is the sensor waterproof? A: The sensor is water-resistant up to the indicated water level line, but the entire sensor should not be submerged.
Q: What is the lifespan of the sensor? A: With proper maintenance and use, the sensor can last several years, but it may need to be replaced if the readings become consistently inaccurate or erratic.