You are on page 1of 7

Water Monitoring System

Within this manual, you will acquire knowledge on employing a TDS Sensor ESP8266 NodeMCU board.
The TDS meter gauges the aggregate of dissolved solids, such as salts, minerals, and metals, within a
solution. This metric serves as a means to assess water quality and facilitate comparisons between
water obtained from various origins. A primary application of the TDS meter is the monitoring of
aquarium water quality.

We will utilize the TDS meter from key studio and provide a straightforward illustration demonstrating
how to measure TDS in parts per million (ppm) using the Arduino IDE.

Step 1 : Introducing the TDS meter


A TDS meter is designed to quantify the total dissolved solids, including salts, minerals, and metals,
present in water. As the quantity of dissolved solids in water rises, so does the water’s conductivity,
enabling us to compute the total dissolved solids in parts per million (ppm) or milligrams per liter (mg/L).

While this serves as a valuable gauge for monitoring water quality, it’s crucial to note that it doesn’t
assess contaminants in the water. Therefore, relying solely on this indicator is insufficient to determine
the suitability of water for consumption.

TDS meters find utility in various applications such as monitoring water quality in pools, aquariums, fish
tanks, hydroponic systems, water purifiers, and more.

In this tutorial, we will employ the keystudio TDS meter, which includes an interface module and an
electrode probe (as depicted in the image above).

For additional details about the TDS meter, we recommend consulting the official documentation.

Step 2 : Features and Specifications


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:
 Number of Needles: 2
 Total Length: 60cm

 Connection Interface: XH2.54-2P

 Color: White

 Waterproof Probe

Step 3 : Reading code

As mentioned earlier, the sensor generates an analog signal that can be translated into TDS in parts per
million (ppm). We are utilizing the code outlined in the sensor documentation with certain adjustments.

For enhanced precision, it is advisable to calibrate your sensor against a solution with a known TDS
value. Nevertheless, calibration may not be necessary if your focus is on a qualitative assessment of TDS
rather than specific values.

Proceed to upload the subsequent code to your ESP8266.


#define TdsSensorPin A0
#define VREF 3.3 // analog reference voltage(Volt) of the ADC
#define SCOUNT 30 // sum of sample point

int analogBuffer[SCOUNT]; // store the analog value in the array, read from ADC
int analogBufferTemp[SCOUNT];
int analogBufferIndex = 0;
int copyIndex = 0;

float averageVoltage = 0;
float tdsValue = 0;
float temperature = 23; // current temperature for compensation

// median filtering algorithm


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;
}

void setup(){
Serial.begin(115200);
pinMode(TdsSensorPin,INPUT);
}

void loop(){
static unsigned long analogSampleTimepoint = millis();
if(millis()-analogSampleTimepoint > 40U){ //every 40 milliseconds,read the analog value from the ADC
analogSampleTimepoint = millis();
analogBuffer[analogBufferIndex] = analogRead(TdsSensorPin); //read the analog value and store into the
buffer
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];

// read the analog value more stable by the median filtering algorithm, and convert to voltage value
averageVoltage = getMedianNum(analogBufferTemp,SCOUNT) * (float)VREF / 1024.0;

//temperature compensation formula: fFinalResult(25^C) = fFinalResult(current)/(1.0+0.02*(fTP-25.0));


float compensationCoefficient = 1.0+0.02*(temperature-25.0);
//temperature compensation
float compensationVoltage=averageVoltage/compensationCoefficient;

//convert voltage value to tds value


tdsValue=(133.42*compensationVoltage*compensationVoltage*compensationVoltage -
255.86*compensationVoltage*compensationVoltage + 857.39*compensationVoltage)*0.5;

//Serial.print("voltage:");
//Serial.print(averageVoltage,2);
//Serial.print("V ");
Serial.print("TDS Value:");
Serial.print(tdsValue,0);
Serial.println("ppm");
}
}
}

Water Purification system


A pool a dream come true. But how to keep your
water clean it’s often an annoying job. Therefore, a thought of this project: an automatic purification
system. It checks the ORP value and pH value, if the values are below the standard values of a pool, it
automatically corrects them by injecting chloride or pH until the standard values are met.

Supplies
*Raspberry pi 4B

*T-cobbler + flat cable

*1 X breadbord

*1 X breadbord power supply

*1 X 4 channel relais board

*1 X DS18B20 temperature sensor

*2 X waterflow sensor

*1 X orp sensor

*1 X pH sensor

* 1 X LCD 16x2

*1 X MCP3008

* 1 X potentiometer 10KΩ
Step 1: Building the Circuit

We start by connecting all components.

The schematics above show how to connect all the components.

Some components use 3.3V and some use 5V.

The pumps have there own circuit that works on 230V.

This separate circuit is controlled by 4 relays.

I use four because my project has water near it and it’s safer.
Step : Code
For our project we will use python. On our webserver we will show the orp, pH and the temperature
values. And we will also show graphs of the values in the last 10 minutes.

In our code we will also send my values to a MariaDB server hosted on the raspberry pi. We will use
threading to separate these tasks.

Step 3 :Building the House


For the housing we will chose for plastic boxes.

We will create two boxes 1 with all the sensors and electronics and one with the Ph and chloride tanks.

It’s important that the tanks are perfectly sealed because of the toxic gasses of the liquids.

In the second box is a small box with the 4 relays too control the pumps.

You might also like