Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » IoT Based Drinking Water Quality Monitoring with ESP32
ESP32 Projects IoT Projects

IoT Based Drinking Water Quality Monitoring with ESP32

Mamtaz AlamBy Mamtaz AlamUpdated:May 28, 20238 Comments7 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
Water Quality Monitoring ESP32
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

Overview

In this project, we will make IoT Based Drinking Water Quality Monitoring System with ESP32 WiFi Module, TDS/EC Sensor & Temperature Sensor. This complete system can be used to monitor the drinking water quality, i.e Water Electrical Conductivity or EC & Water Temperature. The EC & temperature value can be monitored online from any part of the world on an IoT Server called Thingspeak.

According to WHO standards, EC value should not exceed 400 μS/cm or 0.4mS/cm. The best temperature for drinking water is room temperature (20°C / 68°F) for maximum flavor or chilled cold (6°C / 43°F) for maximum refreshment.

This project uses a TDS Sensor and DS18B20 waterproof temperature sensor along with ESP32 WiFi Module to measure water quality monitoring parameters like Electrical Conductivity & temperature. The EC & Temperature value will be displayed on a 0.96″ I2C OLED Display. The same data can also be monitored graphically on Thingspeak Server online.

Check the previous projects related to TDS Sensor:
1. Arduino Based TDS Meter
2. IoT ESP8266 TDS Meter
3. Aquarium Water Quality Monitoring System


Bill of Materials

To make IoT based Water Quality Monitoring System, we need the following components. You can purchase all these components online from the given link.

S.N.Components NameQuantityPurchase Links
1ESP32 Board1Amazon | AliExpress
2Analog TDS Sensor1Amazon | AliExpress
4DS81B20 Temperature Sensor1Amazon | AliExpress
5Resistor 4.7K1Amazon | AliExpress
6Connecting Wires10Amazon | AliExpress
7Breadboard1Amazon | AliExpress




What is Water Electrical Conductivity (EC)?

EC or Electrical Conductivity of water is its ability to conduct an electric current. Salts or other chemicals that dissolve in water can break down into positively and negatively charged ions. These free ions in the water conduct electricity, so the water’s electrical conductivity depends on the concentration of ions.

Salinity and total dissolved solids (TDS) are used to calculate the EC of water, which helps to indicate the water’s purity. The pure the water, the lower the conductivity. To give a real-life example, distilled water is almost an insulator, but salt water is a very efficient electrical conductor.


Analog TDS Sensor

The 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.

Analog TDS 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.

TDS Sensor Board

The sensor has a TDS Measurement Range between 0 ~ 1000ppm with an accuracy of 10% FS (25 ℃). The probe can not to be used in water above 55 degrees centigrade.


Specifications

  • Input Voltage: 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 ℃)
  • Waterproof Probe




DS18B20 Waterproof Temperature Sensor

This is a pre-wired and waterproofed version of the DS18B20 Sensor used to measure something far away, or in wet conditions. The Sensor can measure the temperature between -55 to 125°C (-67°F to +257°F). The cable is jacketed in PVC. These 1-wire digital temperature sensors are fairly precise, i.e ±0.5°C over much of the range. They work great with any microcontroller using a single digital pin.

DS18B20 Temperature Sensor

The sensor requires two libraries like Dallas Temperature Sensor Library & One-Wire Library. It also requires a 4.7k resistor, which is required as a pullup from the DATA to the VCC line when using the sensor. To learn more about this sensor you can go through the previous post: DS18B20 Sensor Tutorial.


Circuit: IoT Based Water Quality Monitoring System

Now, let us interface the Analog TDS Sensor & DS18B20 Temperature Sensor with ESP32 Board. The reason why we are using a temperature sensor is that the temperature parameter is required during Electrical Conductivity EC Value compensation. The EC values change a lot with rising and fall in temperature.

Here is the simple connection diagram for the project.

IoT Based Drinking Water Quality Monitoring with ESP32

Connect the TDS & Temperature Sensor VCC & GND Pin to ESP32 3.3V & GND Pin respectively. Connect the output analog pin of the TDS Sensor to ESP32 A0 Pin, which is the GPIO36 Pin. Similarly, connect the output of DS18B20 to ESP32 IO14 Pin. A 4.7K pull of resistor is necessary and requires a connection between the DS18B20 output pin & 3.3V VCC as a parasitic power.

IoT Water Quality Monitoring ESP32

You may assemble the components on a breadboard for testing purposes.


Project PCB Gerber File & PCB Ordering Online

If you don’t want to assemble the circuit on a breadboard and you want PCB for the project, then here is the PCB for you. I used EasyEDA to design the PCB. The PCB Board for IoT Water Quality Monitoring looks something like below.

The Gerber File for the PCB is given below. You can simply download the Gerber File and order the PCB from ALLPCB at 1$ only.

Download Gerber File: IoT Drinking Water Quality Monitoring

You can use this Gerber file to order high quality PCB for this project. To do that visit the ALLPCB official website by clicking here: https://www.allpcb.com/.

You can now upload the Gerber File by choosing the Quote Now option. From these options, you can choose the Material Type, Dimensions, Quantity, Thickness, Solder Mask Color and other required parameters.

After filling all details, select your country and shipping method. Finally you can place the order.

You can assemble the components on the PCB Board.


Setting up Thingspeak Server

In order to Monitor the Electrical Conductivity (EC) & Temperature data on Thingspeak Server, you first need to Setup the Thingspeak. To set up the Thingspeak Server, visit https://thingspeak.com/. Create an account or simply sign in if you created the account earlier. Then create a new channel with the following details.

Then go to the API section of the dashboard and copy the API Key. This API key is needed in the code part.



Source Code/Program

The source code/program for IoT Based Drinking Water Quality Monitoring with ESP32 is written in C/C++ on Arduino IDE. The code uses a lot of libraries in this project.

Some of the libraries for this project along with the download link are given below. First, download all these libraries and add them to the Arduino library folder.

1. OneWire Library: https://github.com/PaulStoffregen/OneWire
2. Dallas Temperature Library: https://github.com/milesburton/Arduino-Temperature-Control-Library
3. ADS1015 Library: https://github.com/adafruit/Adafruit_ADS1X15 (Install version 1.4)
4. DFRobot ESP EC Library: https://github.com/GreenPonik/DFRobot_ESP_EC_BY_GREENPONIK
5. Adafruit GFX Library: https://github.com/adafruit/Adafruit-GFX-Library
6. Adafruit SSD1306 Library: https://github.com/adafruit/Adafruit_SSD1306

The complete code for the project is given below. Before uploading the code to the ESP32 Board, you need to make some changes to the following lines.

1
2
3
4
String apiKey = "****************";     //  Enter your Write API key from ThingSpeak
 
const char *ssid =  "****************";     // replace with your wifi ssid and wpa2 key
const char *pass =  "****************";

Replace the Thingspeak API Key with the key that you copied earlier from the Thingspeak setup API tab. Then change the WiFi SSID & Password by replacing them with your local SSID & password.

Now you can upload the code to the ESP32 WiFi Module.

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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <Arduino.h>
#include <Wire.h>
#include <EEPROM.h>
#include <WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Adafruit_ADS1015.h>
#include <DFRobot_ESP_EC.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
 
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
 
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
 
#define ONE_WIRE_BUS 14                // this is the gpio pin 13 on esp32.
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
 
DFRobot_ESP_EC ec;
Adafruit_ADS1115 ads;
 
float voltage, ecValue, temperature = 25;
 
String apiKey = "**************";     //  Enter your Write API key from ThingSpeak
 
const char *ssid =  "**************";     // replace with your wifi ssid and wpa2 key
const char *pass =  "**************";
const char* server = "api.thingspeak.com";
 
WiFiClient client;
 
 
void setup()
{
  Serial.begin(115200);
  EEPROM.begin(32);//needed EEPROM.begin to store calibration k in eeprom
  ec.begin();
  sensors.begin();
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    for (;;);
  }
  delay(2000);
  display.clearDisplay();
 
  Serial.println("Connecting to ");
  Serial.println(ssid);
 
 
  WiFi.begin(ssid, pass);
 
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
}
 
 
void loop()
{
  voltage = analogRead(A0); // A0 is the gpio 36
  sensors.requestTemperatures();
  temperature = sensors.getTempCByIndex(0);  // read your temperature sensor to execute temperature compensation
  ecValue = ec.readEC(voltage, temperature); // convert voltage to EC with temperature compensation
 
  Serial.print("Temperature:");
  Serial.print(temperature, 2);
  Serial.println("ºC");
 
  Serial.print("EC:");
  Serial.println(ecValue, 2);
 
  display.setTextSize(2);
  display.setTextColor(WHITE);
 
  display.setCursor(0, 10);
  display.print("T:");
  display.print(temperature, 2);
  display.drawCircle(85, 10, 2, WHITE); // put degree symbol ( ° )
  display.setCursor(90, 10);
  display.print("C");
 
  display.setCursor(0, 40);
  display.print("EC:");
  display.print(ecValue, 2);
  display.display();
  delay(1500);
  display.clearDisplay();
 
  ec.calibration(voltage, temperature); // calibration process by Serail CMD
 
  if (client.connect(server, 80))  //   "184.106.153.149" or api.thingspeak.com
  {
 
    String postStr = apiKey;
    postStr += "&field1=";
    postStr += String(temperature, 2);
    postStr += "&field2=";
    postStr += String(ecValue, 2);
    postStr += "\r\n\r\n";
    delay(500);
 
    client.print("POST /update HTTP/1.1\n");
    client.print("Host: api.thingspeak.com\n");
    client.print("Connection: close\n");
    client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(postStr.length());
    client.print("\n\n");
    client.print(postStr);
    delay(500);
  }
  client.stop();
}



Water Quality Monitoring with ESP32 on Thingspeak Server

After uploading the code to the ESP32 Board, the ESP32 will try connecting to the WiFi Network. Once it connects to the WiFi Network, it will start reading the EC & Temperature values from the Sensor. You can open the Serial Monitor to read those values.

The temperature sensor will show the room temperature. When the TDS Sensor is dry and not exposed to air, it will show an EC value as zero. You can view these data on OLED Screen.

When the temperature Sensor & TDS Sensor is dipped in water, the OLED will display the EC & Temperature value of the water.

Adding more salts to water increases the electrical conductivity of water & will show a massive rise in water EC value.

IoT Water Quality Monitoring

You can also monitor the same data on the Thingspeak dashboard. To view the data, go to the Thingspeak private view & you will see the EC & Temperature data getting uploaded after the interval of every 15 seconds.

IoT Based Drinking Water Quality Monitoring with ESP32

This is how you can make your own IoT-Based Drinking Water Quality Monitoring with ESP32 WiFi Module, Analog TDS Sensor & DS18B20 Temperature Sensor.


Video Tutorial & Guide

IoT Based Drinking Water Quality Monitoring System with ESP32
Watch this video on YouTube.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleControl Relay/LED/Lamp with AWS IoT Core using ESP32
Next Article Arducam | Interfacing 5MP SPI Camera with Arduino UNO

Related Posts

IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

Updated:May 10, 20261K
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

Updated:May 2, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

Updated:April 27, 20261K
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

Updated:April 27, 20262K
DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

Updated:February 1, 20261K
View 8 Comments

8 Comments

  1. Sidhant on March 28, 2023 3:10 PM

    Sir, for below program the mentioned version (1.4) is not available ; so can you tell which version should i download?
    3. ADS1015 Library: https://github.com/adafruit/Adafruit_ADS1X15 (Install version 1.4)

    Reply
  2. khelendra bisen on April 6, 2023 8:14 AM

    Port not selected in ssp 32 what can i do

    Reply
  3. Gagan kushwah on April 13, 2023 1:04 PM

    Hello Hello sir, I have tried to make a project from your youtube channel. But there is a little problem with it. I do not have the LCD display that you have installed. I have 16×2 I2c module display

    Reply
  4. Zeiry Yozeph on October 19, 2023 6:08 PM

    Try using the Older version…its work for me

    Reply
  5. cilicio on December 19, 2023 8:45 AM

    hi, the temperature sensor is only showing -127 constantly, what is the issue?

    Reply
    • Admin on December 19, 2023 8:57 AM

      Connect 4.7k resistor between the ouput and vcc pin of DS18B20.

      Reply
  6. Kv on May 2, 2024 2:00 AM

    We cant see the graph in thingspeak

    Reply
  7. Krishna on May 2, 2024 2:02 AM

    Everything worked. But the values are not showing on thingspeak . What should i do

    Reply

CommentsCancel reply

Latest Posts
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

May 31, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

February 1, 2026
Top Posts & Pages
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • IoT Based Drinking Water Quality Monitoring with ESP32
    IoT Based Drinking Water Quality Monitoring with ESP32
  • LD2410 Sensor with ESP32 - Human Presence Detection
    LD2410 Sensor with ESP32 - Human Presence Detection
  • ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
    ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
  • DIY IoT Water pH Meter using pH Sensor & ESP32
    DIY IoT Water pH Meter using pH Sensor & ESP32
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
  • How to use Modbus RTU with ESP32 to read Sensor Data
    How to use Modbus RTU with ESP32 to read Sensor Data
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (204)
    • ESP32 MicroPython (7)
    • ESP32 Projects (81)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.