TDS Sensor & Arduino Interfacing for Water Quality Monitoring

In this tutorial, we will learn how to interface Gravity Analog TDS Sensor with Arduino and design a simple TDS Meter.

Overview

TDS (Total Dissolved Solids) indicates how many milligrams of soluble solids are dissolved in one liter of water. In general, the higher the TDS value, the more soluble solids are dissolved in water, and the less clean the water is. Therefore, the TDS value can be used as one reference point for reflecting the cleanliness of the water. This can be applied to domestic water, hydroponic and other fields of water quality testing and monitoring.

So, in this project, we will interface Gravity Analog TDS Sensor with Arduino Microcontroller and read the value in 16×2 LCD Display. Since TDS Value depends upon the temperature. So will also add DS18B20 Waterproof Temperature Sensor to measure Water Temperature. The measured temperature is used with TDS Sensor to compensate for the reading with high calibration and high accuracy. The code, circuit diagram, and all other procedure is given below.

In order to know more about water quality, you can add Ph Sensor, Turbidity Sensor & DO Sensor to this circuit as well.

Bill of Materials

Following are the components required for making this project. All the components can be easily purchased from Amazon. The components purchased link is given.

S.N.Components QuantityPurchase Links

1Arduino UNO Board1Amazon | AliExpress

2TDS Sensor1Amazon | AliExpress

3DS18B20 Temperature Sensor1Amazon | AliExpress

416×2 LCD Display1Amazon | AliExpress

5Potentiometer 10K1Amazon | AliExpress

6Resistor 4.7K1Amazon | AliExpress

7Connecting Wires10Amazon | AliExpress

8Breadboard1Amazon | AliExpress

What is “TDS”?

TDS is an abbreviation for Total Dissolved Solids in a liquid, including organic and inorganic substances in a molecular, ionic, or micro-granular suspended form. TDS is generally expressed in parts per million (ppm) or as milligrams per liter (mg/L). TDS is directly related to the quality of water i.e., the lower a TDS figure, the purer the water. As an example, reverse osmosis purified water will have a TDS between 0 and 10, whereas tap water will vary between 20 and 300, depending on where you live in the world.

The materials that constitute dissolved solids in water include materials such as minerals, salts, anionic and cationic substances. They can also include pollutants such as heavy metals, and other substances such as organic materials that may have leaked into your water supply system.

What is a TDS meter and how does it work?

A TDS meter is basically an electrical charge (EC) meter whereby two electrodes equally spaced apart are inserted into water and used to measure charge. The result is interpreted by the TDS meter and converted into a ppm figure.

TDS Sensor WorkingTDS Sensor Working

If the water contains no soluble materials and is pure, it will not conduct a charge and will, therefore, have a 0 ppm figure. Conversely, if the water is full of dissolved materials, it will conduct a charge, with the resulting ppm figure being proportional to the number of dissolved solids. This is because all dissolved solids have an electrical charge, which allows conduction of electrical charge between the electrodes.

What can a TDS meter be used for?

As well as measuring the TDS of our drinking water supplies, a TDS meter can be used for measuring:
1. Fish tanks and aquariums

Fish require a specific TDS and pH similar to the natural environment in which they live. Freshwater fish require less than 400ppm, with some other freshwater fish requiring less. Saltwater fish require TDS readings of between 5000 and 50000ppm.

2. Hydroponics

A TDS meter is a useful aid for quickly measuring the nutrient concentration of a hydroponic solution.

3. Pools and spas

A low TDS reading can help prevent maintenance issues, skin irritation, and algal blooms.

4. Colloidal silver

There are many consumers of colloidal silver today using a TDS meter to measure their colloidal silver concentration in parts per million (ppm). The TDS meter gives a relatively accurate measurement.

Gravity Analog TDS Sensor

Gravity Analog TDS Sensor is an Arduino-compatible TDS sensor/Meter Kit for measuring TDS value of the water. It can be applied to domestic water, hydroponic and other fields of water quality testing. This product supports 3.3 ~ 5.5V wide voltage input, and 0 ~ 2.3V analog voltage output, which makes it compatible with 5V or 3.3V control systems or boards.

TDS SensorTDS Sensor

The excitation source is an AC signal, which can effectively prevent the probe from polarization and prolong the life of the probe, meanwhile, it can help increase the stability of the output signal. The TDS probe is waterproof, it can be immersed in water for long time measurement.

Specification

1. Input Voltage: 3.3 ~ 5.5V
2. Output Voltage: 0 ~ 2.3V
3. Working Current: 3 ~ 6mA
4. TDS Measurement Range: 0 ~ 1000ppm
5. TDS Measurement Accuracy: ± 10% FS (25 ℃)
6. TDS probe with Number of Needle: 2

Attention & Things to Remember

The probe can not to be used in water above 55 degrees centigrade.
The probe can not be too close to the edge of the container, otherwise, it will affect the reading.
The head and the cable of the probe are waterproof, but the connector and the signal transmitter board are not waterproof.

Interfacing Gravity Analog TDS Sensor with Arduino

Now let us learn how to interface TDS Sensor with Arduino. The circuit diagram is given below.

Interfacing Gravity Analog TDS Sensor with ArduinoInterfacing Gravity Analog TDS Sensor with Arduino

The connection of TDS Sensor with Arduino is fairly simple. Connect the VCC to Arduino 5V & GND to GND. Connect its Analog pin to any analog pin of Arduino. In my case, I used Analog pin A1 of Arduino.

Source Code/Program

Here is a simple code for Interfacing TDS Sensor with Arduino. You need a library for it.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

#include <EEPROM.h>

#include “GravityTDS.h”

 

#define TdsSensorPin A1

GravityTDS

gravityTds

;

 

float

temperature

=

25

,

tdsValue

=

0

;

 

void

setup

(

)

{

    

Serial

.

begin

(

115200

)

;

    

gravityTds

.

setPin

(

TdsSensorPin

)

;

    

gravityTds

.

setAref

(

5.0

)

;

  

//reference voltage on ADC, default 5.0V on Arduino UNO

    

gravityTds

.

setAdcRange

(

1024

)

;

  

//1024 for 10bit ADC;4096 for 12bit ADC

    

gravityTds

.

begin

(

)

;

  

//initialization

}

 

void

loop

(

)

{

    

//temperature = readTemperature();  //add your temperature sensor and read it

    

gravityTds

.

setTemperature

(

temperature

)

;

  

// set the temperature and execute temperature compensation

    

gravityTds

.

update

(

)

;

  

//sample and calculate

    

tdsValue

=

gravityTds

.

getTdsValue

(

)

;

  

// then get the value

    

Serial

.

print

(

tdsValue

,

0

)

;

    

Serial

.

println

(

“ppm”

)

;

    

delay

(

1000

)

;

}

Once the code is uploaded, you can simply put the TDS probe in water and check the reading in Serial Monitor.

Interfacing Gravity Analog TDS Sensor with Arduino & LCD Display

Now let us add an extra LCD Display & interface TDS Sensor with Arduino. We will display the TDS Value in LCD Display. The circuit diagram is given below.

TDS Sensor LCD Display ArduinoTDS Sensor LCD Display Arduino

Source Code/Program with LCD Display

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

#include <EEPROM.h>

#include “GravityTDS.h”

#include <LiquidCrystal.h>

 

LiquidCrystal

lcd

(

12

,

11

,

5

,

4

,

3

,

2

)

;

 

#define TdsSensorPin A1

GravityTDS

gravityTds

;

 

float

temperature

=

25

,

tdsValue

=

0

;

 

void

setup

(

)

{

    

Serial

.

begin

(

115200

)

;

    

lcd

.

begin

(

16

,

2

)

;

    

gravityTds

.

setPin

(

TdsSensorPin

)

;

    

gravityTds

.

setAref

(

5.0

)

;

  

//reference voltage on ADC, default 5.0V on Arduino UNO

    

gravityTds

.

setAdcRange

(

1024

)

;

  

//1024 for 10bit ADC;4096 for 12bit ADC

    

gravityTds

.

begin

(

)

;

  

//initialization

}

 

void

loop

(

)

{

    

//temperature = readTemperature();  //add your temperature sensor and read it

    

gravityTds

.

setTemperature

(

temperature

)

;

  

// set the temperature and execute temperature compensation

    

gravityTds

.

update

(

)

;

  

//sample and calculate

    

tdsValue

=

gravityTds

.

getTdsValue

(

)

;

  

// then get the value

    

Serial

.

print

(

tdsValue

,

0

)

;

    

Serial

.

println

(

“ppm”

)

;

    

lcd

.

setCursor

(

0

,

0

)

;

    

lcd

.

print

(

“TDS Value:”

)

;

    

lcd

.

setCursor

(

0

,

1

)

;

    

lcd

.

print

(

tdsValue

,

0

)

;

    

lcd

.

print

(

” PPM”

)

;

    

delay

(

1000

)

;

    

lcd

.

clear

(

)

;

}

Once the code is uploaded you can now measure the TDS of water and display in 16×2 LCD Display.

Temperature Compensated TDS Sensor with Arduino

The above two codes are valid only if the temperature of the water is 25 degrees Celcius. If there is an increase or decrease in temperature the reading will be false as Conductivity changes as per temperature.

So, in order to fix this issue we need to include the temperature coefficient in the code. This sensor doesn’t have any temperature sensor. So we need to add an external temperature sensor. The DS18B20 Waterproof Temperature Sensor is a suitable option for that because of the easy interface and high accuracy. Hence the new circuit diagram becomes something like the below.

TDS Sensor DS18B20 Temperature ArduinoTDS Sensor DS18B20 Temperature Arduino

Connect the output pin of DS18B20 Waterproof Temperature sensor to any digital pin. In my case, I used Digital Pin 7 of Arduino. Pull the Output pin via 4.7K resistor to 5V Supply as shown in the image above.

Source Code/Program with Temperature Compensation

Here is the source code for TDS Sensor with temperature compensation. We need two extra library for this code as DS18B20 requires one wire and Dallas library. So download it from below and add it to the libray folder.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

#include <EEPROM.h>

#include “GravityTDS.h”

#include <LiquidCrystal.h>

#include <OneWire.h>

#include <DallasTemperature.h>

LiquidCrystal

lcd

(

12

,

11

,

5

,

4

,

3

,

2

)

;

 

#define ONE_WIRE_BUS 7

#define TdsSensorPin A1

 

OneWire

oneWire

(

ONE_WIRE_BUS

)

;

GravityTDS

gravityTds

;

 

DallasTemperature

sensors

(

&oneWire);

 

float

tdsValue

=

0

;

 

void

setup

(

)

{

    

Serial

.

begin

(

115200

)

;

    

lcd

.

begin

(

16

,

2

)

;

    

sensors

.

begin

(

)

;

    

gravityTds

.

setPin

(

TdsSensorPin

)

;

    

gravityTds

.

setAref

(

5.0

)

;

  

//reference voltage on ADC, default 5.0V on Arduino UNO

    

gravityTds

.

setAdcRange

(

1024

)

;

  

//1024 for 10bit ADC;4096 for 12bit ADC

    

gravityTds

.

begin

(

)

;

  

//initialization

}

 

void

loop

(

)

{

    

sensors

.

requestTemperatures

(

)

;

 

    

gravityTds

.

setTemperature

(

sensors

.

getTempCByIndex

(

0

)

)

;

  

// set the temperature and execute temperature compensation

    

gravityTds

.

update

(

)

;

  

//sample and calculate

    

tdsValue

=

gravityTds

.

getTdsValue

(

)

;

  

// then get the value

    

    

Serial

.

print

(

tdsValue

,

0

)

;

    

Serial

.

println

(

“ppm”

)

;

    

Serial

.

print

(

“Temperature is: “

)

;

    

Serial

.

print

(

sensors

.

getTempCByIndex

(

0

)

)

;

    

    

lcd

.

setCursor

(

0

,

0

)

;

    

lcd

.

print

(

“TDS: “

)

;

    

lcd

.

print

(

tdsValue

,

0

)

;

    

lcd

.

print

(

” PPM”

)

;

 

    

lcd

.

setCursor

(

0

,

1

)

;

    

lcd

.

print

(

“Temp: “

)

;

    

lcd

.

print

(

sensors

.

getTempCByIndex

(

0

)

)

;

    

lcd

.

print

(

” C”

)

;

    

    

delay

(

1500

)

;

    

lcd

.

clear

(

)

;

}

Now once the code is uploaded you can read the precise and correct value of TDS in PPM along with Temperature.

This is the reading when both the sensor are placed in air.

When some soluble ion solute like salt is added the conductivity of solution increases and hence we can get the value of TDS higher. In the image below I have added 2 spoon of salt and stired it. The value of TDS increased immediately.

Video Tutorial

TDS Meter using TDS & Temperature Sensor with Arduino || Measure Water Quality in PPM

TDS Meter using TDS &amp; Temperature Sensor with Arduino || Measure Water Quality in PPM

If you want to monitor the Water Quality Parameters like TDS, EC & Temperature, you can follow the projects here: IoT Based TDS Meter using ESP8266.