Arduino with TDS Sensor (Water Quality Sensor)

Arduino with TDS Sensor (Water Quality Sensor)

How to measure TDS in ppm units with Arduino IDE

In this article, you can learn how to use a TDS sensor (Total Dissolved Solids) with an Arduino board. A TDS meter specifies the total dissolved solids like salts, minerals, and metals in a mixture. This framework can be used to provide an idea of water conditions and differentiate water from other sources. TDS meter application is mainly used for aquarium water quality checking.

We are using the TDS sensor from the key studio and give you examples to measure TDS in ppm units using Arduino IDE.

Table of Contents

Then let’s see the below topics covered in this article.

  • Introducing the TDS Meter
  • Interfacing the TDS Meter with the Arduino
  • Reading TDS with the Arduino – Code

Introducing the TDS Meter

Using the TDS meter the count of total dissolved solids like salts, minerals, and metals in water can be measured. As the dissolved solids quantity increases in the water, the resistivity of the water goes high. And it helps us to count the total ended-up solids in ppm.

TDS Meter

Though it is a good measure to check the condition of the water, it does not check the impurity of the water. Hence you cannot come to decisions with the results of the check. It can even be good or bad for users.

A TDS meter is very important to check the water quality using numerous applications like pools, fish bowls/tanks, aquaculture, and water cleaners.

In this article, we are using the TDS meter from the key studio that is with an interface module and an electrode probe as in the above image.

If you are fond of more information about TDS meters, have a look at the official documents.

Features and Specifications

This article is touching on the TDS Meter V1.0 from the key studio. There are given the sensor parameters.

TDS Meter:

  • Input Voltage: DC 3.3 ~ 5.5V
  • Output Voltage: 0 ~ 2.3V
  • Working Current: 3 ~ 6mA
  • TDS Measurement Range: 0 ~ 1000ppm
  • TDS Measurement Accuracy: ± 10% F.S. (25 ℃)
  • Module Interface: XH2.54-3P
  • Electrode Interface: XH2.54-2P

TDS Probe:

  • 2 Needles
  • 60cm length
  • XH2.54-2P connection interface
  • White color
  • Waterproof probe.

Where to Buy TDS Sensor?

TDS sensors are available for the best prices on Maker Advisor. Check and find as you fit.

Use the above link or go directly to MakerAdvisor.com/tools to et all the pasts required for your projects for the best price.

Interfacing the TDS Meter with the Arduino

The Analog signals return from the TDS meter and we can measure them using the Arduino analog pins (A0 to A5).

Refer to the below table and connect the sensors.

TDS Meter

Reading TDS (water quality) with the Arduino- Code

As said before, the analog signal comes from the sensor converted to TDS in ppm. We use the code of the sensor documentation with some moderations.

TDS Sensor

To get the correct outputs, you may need to set the sensors in case of a solution with a known TDS value. Anyhow it is not essential to think about the particular values but a comparative value of TDS.

Try the below code, and upload it to your Arduino.

How the Code Works

Let’s have a look at the code. You are able to skip directly to the Demonstration part.

The variable TdsSensorPin saves the GPIO where you need to have the readings. The ESP8266 has got only one analog pin, A0.

#define TdsSensorPin A0

After that, enter the analog voltage for the ADC. For the Arduino, it is 5V.

#define VREF 5.0 // analog reference voltage(Volt) of the ADC

Before getting the values of the measurement, we can include an average filtering algorithm to get more sold value.

#define SCOUNT 30 // sum of the sample point

Then some arrays are required to keep the data and the index variables that let us use the arrays.

TDS Meter

Format the averageVoltage variable and tsdValue as floating variables.

float averageVoltage = 0;

float tdsValue = 0;

The temperature variables store the existing temperature values. The temperature affects the readings, so an algorithm is available that repays the variation of temperature. In the example, the recommended temperature is 25ºC, but it can be changed according to the environmental condition. To get the correct results, add a temperature sensor and get the original temperature when reading the sensor.

float temperature = 25; // current temperature for compensation

Use the below function to receive a solid TDS value using an array of readings.

In the setup(), format the Serial Monitor at a baud rate of 115200.

Serial.begin(115200);

Set the TDS sensor pin for input.

pinMode(TdsSensorPin,INPUT);

In the loop(), receive new TDS readings every 40 milliseconds and store them in the buffer.

And within every 800 milliseconds, it receives the new readings and the average voltage using the filtering algorithm made up before:

Then it checks the temperature damage numbers and measures the TDS value considering the values taken by the account.

Final value

And at last, it prints the TDS value in ppm.

TDS Meter

Demonstration

After you have copied the code into the Arduino IDE, upload it to the board. You should select the correct board in Tools > Board and the COM port in Tools > Port.

After finishing the uploading, open the Serial Monitor under a baud rate of 115200.

TDS Meter

It will display a value around 0 if the research is not overflown. Solve the results of the research to check in TDS. Try it with some tap water and add some salt to check the values increasing.

I checked the TDS value using tap water at my home. After that, I got a value around 100ppm, which seems to be good for drinking.

I checked a tea, and the TDS value went up to 230ppm and it is a sensible value.

At last, I checked the value of TDS  in a water bottle and it was around 25ppm same value as the ESP8266

Wrapping Up

A TDS meter can count the total solids in a solution that are unsolved. It is able used as an indicator of water and lets you mark the water. The values return in ppm in the TDS. The TDS value has got lots of applications but can’t use by itself to ensure that water can be drunk or not. 

At last, you got to know a good application of this kind of sensor is a fish tank water condition monitor. This sensor is usable along with a  waterproof  DS18B20 temperature sensor to check the fish tank.

Frequently asked questions.

Can we set TDS in RO?

Lead and arsenic-contaminated water can be treated with RO purifiers built up with the Mineralizer feature, but these purifiers reduce the ability to change the TDS level to suit your needs.

Recommendations:

Arduino with Load Cell and HX711 Amplifier (Digital Scale)

Leave a Reply

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