ESP8266/IoT B.Tech/Diploma Beginner

IoT Based TDS Meter using ESP8266 for Water Quality Monitoring

IoT Based TDS Meter using NodeMCU ESP8266 TDS Sensor for Water Quality Monitoring. EC Meter & Temperature Sensor calibration Arduino TDS Code

  • Suitable forB.Tech/Diploma ESP8266/IoT students
  • Build time1-2 weeks
  • LevelBeginner
  • Available atAjvika Labs, Kakinada

About this project

Overview: IoT Based TDS Meter using ESP8266
In this project, we will learn how to make our own
IoT Based TDS Meter
using NodeMCU
ESP8266
&
TDS Sensor
for
Water Quality Monitoring
. The TDS value (Total Dissolved Solids) gives the sum of dissolved solids in water. These solids include for instance
salts, minerals, and conductive metals ions
. The value is additionally called the
conductivity
of the water. Because the more such solids or ions are within the water, the higher it conducts electricity. TDS meters typically quantify this conductivity in
micro siemens
or
ppm
. The latter stands for parts per million, i.e. the number of solid particles per a million water mixture particles. The value of 40 ppm means from a million particles there are 40 dissolved ions and therefore the rest (= 999 960) are water molecules.
The TDS Sensor can not only measure the Liquid TDS but also the
EC (Electrical Conductivity)
. An electrical conductivity meter (EC meter) measures the electrical conductivity in a solution. It has multiple applications in research and engineering, with common usage in hydroponics, aquaculture, aquaponics,
pisciculture
, and freshwater systems to monitor the number of nutrients, salts, or impurities in the water.
To make our own IoT based TDS Meter, we will need a
TDS Sensor
as well as
Temperature Sensor
which should be Waterproof. For sending the measured TDS, EC & Temperature data, we need an IoT platform. The best free IoT platform is
Blynk
. The ESP8266 based TDS Meter connects to wifi and continuously sends the data to the Blynk application. Thus you can get a 24×7 report related to your water quality. Thus TDS sensor is the best sensor for Water Quality Monitoring. Apart from all this, you can also add a
Ph Sensor
and a
Turbidity Sensor
to learn more about the Water Quality.
Bill of Materials
We need the following components to make an IoT Based TDS Meter. The ESP8266 & TDS Sensor is required along with the Temperature Sensor. All the componets can be purchased online from Amazon. The components purchase link is given below.
S.N.
Components
Quantity
Purchase Links

Nodemcu ESP8266 Board

Amazon
AliExpress

TDS Sensor

Amazon
AliExpress

DS18B20 Sensor

Amazon
AliExpress

Resistor 4.7K

Amazon
AliExpress

Connecting Jumper Wires

Amazon
AliExpress

Breadboard

Amazon
AliExpress
TDS Meter Circuit Diagram & Connections
The connection diagram between NodeMCU ESP8266 & TDS Sensor is given below. The anlog pin of TDS Sensor is connected to A0 of NodeMCU. The VCC pin is connected to 3.3V & GND to GND.
We already discussed the basics of TDS Sensor and Arduino Interfacing in our previous tutorials. You can follow the basic guide here:
Arduino TDS Meter
The use of the DS18B0 Temperature Sensor is for calibration purposes. This is because the TDS value varies as per change in Temperature, so there is a need for temperature compensation as per the change in liquid temperature. This is done by DS18B20, Waterproof Temperature Sensor.
Blynk Application Setup
The IoT Water Quality Monitoring Project is incomplete without the Blynk Application. Blynk is designed for the Internet of Things. It can control hardware remotely, it can display sensor data, it can store data, visualize it, and do many other cool things.
Download and install the
Blynk Application
from
Google Play Store
. IOS users can download from the
App Store
. Once the installation is completed, open the app & sign-up using your Email id and Password.
Create your UI by dragging dropping and filling up details along with the virtual pin assignment. Once the UI is created, you can ask for the authentication Token by sending the mail. You will need the Authentication Token for the code.
Source Code/Program
The source code or program for IoT Based TDS Meter using TDS Sensor & ESP8266 is given below. You can upload this code to the NodeMCU Board. Before compiling the sketch, you need to add following library to the Arduino IDE.
Download:
Blynk Library
From the code part, change the wifi SSID, Password & Blynk Authentication Code.

char
auth
[
]
=
"******************************"
;
char
ssid
[
]
=
"******************************"
;
char
pass
[
]
=
"******************************"
;
The complete code is given below.

#include <Blynk.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char
auth
[
]
=
"fqMvEno5LtFrd_UcIpyyc6U03ehbgeQU"
;
// You should get Auth Token in the Blynk App.
char
ssid
[
]
=
"Alexahome"
;
// Your WiFi credentials.
char
pass
[
]
=
"loranthus"
;
int
DSPIN
=
D5
;
// Dallas Temperature Sensor
namespace
pin
{
const
byte
tds_sensor
=
A0
;
// TDS Sensor
}
namespace
device
{
float
aref
=
3.3
;
}
namespace
sensor
{
float
ec
=

;
unsigned
int
tds
=

;
float
ecCalibration
=

;
}
void
setup
(
)
{
Serial
begin
(
115200
)
;
// Dubugging on hardware Serial 0
Blynk
begin
(
auth
ssid
pass
)
;
}
void
loop
(
)
{
Blynk
run
(
)
;
double
waterTemp
=
TempRead
(
)
;
waterTemp
=
waterTemp*
0.0625
;
// conversion accuracy is 0.0625 / LSB
float
rawEc
=
analogRead
(
pin
::
tds_sensor
)
*
device
::
aref
/
1024.0
;
// read the analog value more stable by the median filtering algorithm, and convert to voltage value
float
temperatureCoefficient
=
1.0
+
0.02
*
(
waterTemp
25.0
)
;
// temperature compensation formula: fFinalResult(25^C) = fFinalResult(current)/(1.0+0.02*(fTP-25.0));
sensor
::
ec
=
(
rawEc
/
temperatureCoefficient
)
*
sensor
::
ecCalibration
;
// temperature and calibration compensation
sensor
::
tds
=
(
133.42
*
pow
(
sensor
::
ec

)
255.86
*
sensor
::
ec *
sensor
::
ec
+
857.39
*
sensor
::
ec
)
*
0.5
;
//convert voltage value to tds value
Serial
(
F
(
"TDS:"
)
)
;
Serial
println
(
sensor
::
tds
)
;
Serial
(
F
(
"EC:"
)
)
;
Serial
println
(
sensor
::
ec

)
;
Serial
(
F
(
"Temperature:"
)
)
;
Serial
println
(
waterTemp

)
;
Serial
(
F
(
""
)
)
;
Blynk
virtualWrite
(
V1
sensor
::
tds
)
;
Blynk
virtualWrite
(
V2
sensor
::
ec
)
;
Blynk
virtualWrite
(
V3
waterTemp
)
;
delay
(
1000
)
;
}
boolean
DS18B20_Init
(
)
{
pinMode
(
DSPIN
OUTPUT
)
;
digitalWrite
(
DSPIN
HIGH
)
;
delayMicroseconds
(

)
;
digitalWrite
(
DSPIN
LOW
)
;
delayMicroseconds
(

)
;
//480-960
digitalWrite
(
DSPIN
HIGH
)
;
pinMode
(
DSPIN
INPUT
)
;
int
t
=

;
while
(
digitalRead
(
DSPIN
)
)
{
t
++
;
if
(
t
>

)
return
false
;
delayMicroseconds
(

)
;
}
t
=

t
;
pinMode
(
DSPIN
OUTPUT
)
;
delayMicroseconds
(
t
)
;
digitalWrite
(
DSPIN
HIGH
)
;
return
true
;
}
void
DS18B20_Write
(
byte
data
)
{
pinMode
(
DSPIN
OUTPUT
)
;
for
(
int
i
=

;
i
<

;
i
++
)
{
digitalWrite
(
DSPIN
LOW
)
;
delayMicroseconds
(

)
;
if
(
data
&

)
digitalWrite
(
DSPIN
HIGH
)
;
else
digitalWrite
(
DSPIN
LOW
)
;
data
>>
=

;
delayMicroseconds
(

)
;
digitalWrite
(
DSPIN
HIGH
)
;
}
}
byte
DS18B20_Read
(
)
{
pinMode
(
DSPIN
OUTPUT
)
;
digitalWrite
(
DSPIN
HIGH
)
;
delayMicroseconds
(

)
;
byte
data
=

;
for
(
int
i
=

;
i
<

;
i
++
)
{
digitalWrite
(
DSPIN
LOW
)
;
delayMicroseconds
(

)
;
digitalWrite
(
DSPIN
HIGH
)
;
pinMode
(
DSPIN
INPUT
)
;
delayMicroseconds
(

)
;
data
>>
=

;
if
(
digitalRead
(
DSPIN
)
)
data
|=
0x80
;
delayMicroseconds
(

)
;
pinMode
(
DSPIN
OUTPUT
)
;
digitalWrite
(
DSPIN
HIGH
)
;
}
return
data
;
}
int
TempRead
(
)
{
if
(
!
DS18B20_Init
(
)
)
return

;
DS18B20_Write
(
0xCC
)
;
// Send skip ROM command
DS18B20_Write
(
0x44
)
;
// Send reading start conversion command
if
(
!
DS1

Technologies used

ESP8266ArduinoLoRaBlynkWiFiBLEDS18B20SPIArduino IDE

Hardware components

  • ESP8266
  • Arduino
  • DS18B20

Software & tools

  • Arduino IDE
  • Blynk

What you get

  • Working project / hardware kit, tested before delivery
  • Complete source code with explanation
  • Project demo and guidance for your viva
  • Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed. Payment is in two parts: • 50% advance to start the project • Remaining 50% before delivery Note: • Documentation and PPT are not included by default • If you need documentation/PPT, it can be arranged for extra time and cost We'll confirm the exact timeline and cost with you after reviewing your requirements.