Water Quality Monitoring Via Internet of Things (IoT)
Nurafiqah Farhani Ramzyzan, Zulkifli Mohamed, Ramzyzan Ramly
Faculty of Mechanical Engineering, University Technology MARA, Malaysia
DOI: https://doi.org/10.51244/IJRSI.2025.120700045
Received: 04 July 2025; Accepted: 08 July 2025; Published: 31 July 2025
In Malaysia, the pressing need for effective water management encompasses various applications, including monitoring rainwater harvesting quality, drinking water quality, and managing aquarium water quality. This research addresses this broad need by developing a versatile microcontroller-based water quality monitoring system. Centred around the usage of the ESP32 TTGO by LilyGo microcontroller, this system enables precise measurement and real-time monitoring of water parameters, providing critical insights into water quality and indicating whether treatment is necessary. The system is designed to cater to these essential uses, ensuring robust monitoring capabilities for rainwater harvesting, drinking water, and aquarium water. The methodology employed in this research involves the utilization of Arduino IDE, Visual Studio Code, and Flutter software to develop the microcontroller-based system, followed by rigorous testing, calibration, and validation procedures to ensure its accuracy and reliability. The calibration process includes a meticulous comparison of sensor data with readings from a trustworthy testing device that has undergone prior calibration. The successful development of the water quality monitoring device, coupled with its dedicated app, allows users to seamlessly monitor water quality from any location and access data remotely. This innovation enhances various water monitoring practices and promotes sustainable water management across different applications, contributing to the broader goal of water resource conservation.
Keywords: water quality monitoring; Internet of Things (IoT); ESP32; Arduino; microcontroller-based system
Recognising the fact that water mismanagement can no longer afford to be taken lightly in the face of fast urbanisation, Malaysia has begun to ride the wave towards Telstra-style irrigation efficiencies. Quality monitoring of different water resources from rainwater to potable water and aquarium water is of great importance for safety and utility. Current methods for water quality testing are generally not rapid and not all of them instantaneous, prolonging the time of occurrence of contamination problems [1]. Hence, a reliable, real-time monitoring system is required to determine the accurate measurement of water parameters [2].
The aim of this study is to contribute to the development of a versatile microcontroller-based water quality monitoring system that can be used for many applications such as rainwater harvesting, drinking water quality monitoring and aquarium water management. The system is crafted to offer real-time monitoring and accurate measurement of different water parameters, harnessing technologies such as the ESP32 TTGO by LilyGo microcontroller, Arduino IDE, Visual Studio Code, and Flutter software.
The objectives of this study are to develop a versatile water quality monitoring system, to calibrate the monitoring system to ensure its accuracy, and to test the performance of the calibrated system in various applications. Rapid urbanisation in Malaysia leads to worsening air pollution, thus, affecting the quality of different water sources. Industrial emissions and exhaust from vehicles have contaminants that can travel through water, so it is imperative to check the quality of water before it is put to use. Listening to the increasing concern of water quality, the available methods are inadequate to provide real-time and accurate data.
This study focuses on creating an advanced monitoring system capable of delivering accurate, real-time data on water quality. The goal is to enhance how water resources can be managed by developing a versatile system that can be used across different types of water. The research aims to ensure the safety and sustainability of water sources, specifically rainwater, drinking water, and aquarium water. It seeks to provide a reliable tool for continuous monitoring and assessment, benefiting both human and environmental health.
Project Methodology
The methodology section outlines the steps taken to develop, calibrate, and test the microcontroller-based water quality monitoring system. This system is designed to provide real-time and accurate measurements of various water parameters, for rainwater harvesting, drinking water and aquarium water quality monitoring.
Figure 1. Project Flowchart
Figure 2. Device IoT Block Diagram
Hardware Development
Referring to the lefthand side of Figure 1, the hardware development for the water quality monitoring system involved several essential phases. Initially, the procurement progress was done by acquiring all the required components for the project. The components were carefully selected with reference to Essamlali et al. [1], and Meghana et al. [2]. The components are the TTGO-T-Display by Lilygo for microprocessor and display purposes, the Gravity: Analog pH sensor, the DF Analog Water TDS Sensor Module, and the DS18B20 Temperature sensor. The next step is to program the TTGO board with the coding for each sensor, which was adapted from methodologies outlined by Essamlali et al. [1], Meghana et al. [2], and Hidayatullah et al. [3]. In this phase, the Arduino code was both written and modified to effectively read data from the sensors.
After completing the programming, thorough testing and calibration of each sensor were performed to ensure accurate functionality, following methodologies from Banna et al. [4] and Junaidi et al. [5]. The next step is the hardware assembly process, this process focuses on connecting all the sensors to the TTGO board according to their designated configurations as described by Alimorong et al. [6] and Hong et al. [7]. Specifically, the pH and TDS sensors are both connected to separate analog input pins, while the temperature sensor is connected to the system via digital pin.
The final step in hardware development is enclosure development and hardware assembly, influenced by methodologies detailed by Rahmat [8] and Alimorong et al. [6]. This step involved integrating all 3 sensors into a cohesive unit and developing an enclosure to protect the hardware from environmental factors. This enclosure both ensures the durability of the device and enhances the practicality of the device for deployment in various environments. Upon completion, the system’s hardware was prepared for system integration and further development processes in the water quality monitoring system.
Final Assembly
The figures below illustrate the final assembly of the device and its schematic diagram. The components include the TTGO-T-Display by LilyGO, Gravity Analog pH Sensor, DF Analog Water TDS Sensor Module, and DS18B20 Temperature Sensor. A power bank has been chosen as the device’s power source.
Figure 3. Final Device Hardware Set-up
Figure 4. Final Device Schematic Diagram
Software Development
Referring to the righthand side of Figure 1, the software development for the water quality monitoring system involved several important processes. Initially, the focus was on the front end, where the app’s user interface (UI) was designed using Flutter widgets. This step involved planning and creating a well-structured and intuitive UI to ensure an optimal user experience.
Following the UI design, attention shifted to the back end, where the functionality of the app was developed and implemented using Dart code. This phase ensured that the app could perform the desired operations, including data collection, processing, and display.
Once the core functionality was in place, the next step was to set up MQTT communication. This involved establishing a reliable communication link between the Flutter app and the Arduino hardware, enabling real-time data transmission and reception.
After setting up MQTT, the app underwent thorough testing, validation, and improvement. This step ensured that all features operated correctly and efficiently, with the user interface responding as expected, data being accurately transmitted and received via MQTT, and sensor readings being correctly displayed. Any discrepancies identified during testing were addressed to improve the app’s reliability.
Debugging followed the testing phase. Utilizing debugging tools, the development team identified and resolved any issues, which enhanced the app’s stability. Finally, the performance of the app was optimized to ensure it operated smoothly, providing a seamless user experience.
Through these comprehensive steps, the software development process ensured that the water quality monitoring system’s app was reliable and user-friendly, ready for deployment alongside the hardware components.
System Integration
The system integration for the water quality monitoring system involved several important steps to ensure seamless operation of both hardware and software components. Initially, the focus was on continuous improvement, refining, and optimising the system to ensure that both the hardware and software worked together seamlessly. Enhancements were made to improve overall system efficiency and performance.
Following optimisation, comprehensive testing was performed to ensure all components functioned correctly together. The sensors, microcontroller, and the mobile application were tested to verify their interactions and data flow, confirming the system’s reliability and accuracy. After testing, the system was deployed in its intended environment. This process involved setting up the operational system and monitoring its performance to ensure accurate and reliable water quality data, while addressing any issues that arose in real-time usage.
Through these steps, the water quality monitoring system was refined, tested, and deployed, creating a functional system capable of collecting sensor data, processing it through the microcontroller, and transmitting the information to a mobile application for real-time monitoring through Wifi connection. Continuous improvement, integration testing, and deployment ensured the system was well-prepared for practical use and ongoing monitoring.
The integration of the water quality monitoring system is shown in the IoT diagram in Figure 2. This diagram illustrates the multi-layer architecture enabling seamless communication between hardware components and the application interface for real-time monitoring. The system is structured into three primary layers:
Figure 2 demonstrates how each layer interacts, from data collection to transmission and real-time monitoring. This comprehensive system integration ensures accurate and reliable water quality monitoring, enhancing the management and utilization of water resources.
System Calibration
Proper calibration of sensors is vital to obtain accurate and reliable data. The table below details the calibration methods and procedures used for each type of sensor in the system:
Table 1: List of System Calibration Method
Calibration Method | Procedure |
pH Sensor
Three-point calibration |
1. The sensor was first submerged in a pH 4.01 buffer solution, then the pH offset in the code is modified.
2. Then, the sensor was submerged in a pH 6.86 buffer solution, then the pH offset in the code is modified again. 3. Lastly, the sensor was submerged in a pH 9.18 buffer solution. The pH offset in the code is then modified and a new algorithm is created to include all modifications. |
TDS Sensor
Calibration using a reference TDS sensor |
1. Both the reference TDS sensor and the device’s TDS sensor were submerged in the same solution.
2. The device’s TDS sensor reading in the code was adjusted to match the reference sensor’s reading. |
Temperature Sensor (DS18B20)
Factory calibrated |
No calibration is required as DS18B20 sensors are factory calibrated. Verification can be done using a known temperature reference. |
This chapter presents the findings from the water quality monitoring system and discusses the implications of these results. The development phase of the water quality monitoring device involved meticulous design and construction, integrating sensors for pH, Total Dissolved Solids (TDS), and temperature measurements. Careful selection and assembly of hardware components were undertaken to ensure optimal performance and reliability. Subsequently, a rigorous calibration process was implemented to align the sensor data with readings from a trusted testing device. This calibration procedure was crucial in ensuring the accuracy and consistency of the water quality measurements obtained by the monitoring system.
Upon completion, the hardware system demonstrated robust performance, effectively monitoring water quality across various types of water sources. The sensors provided accurate and reliable measurements, enabling users to assess the quality of water in real-time. The analysis in this chapter encompasses the performance of both hardware and software components, examining the accuracy and reliability of the sensors, the effectiveness of the data processing algorithms, and the usability of the user interface. Additionally, the integration and functionality of the complete system are evaluated, with particular attention to real-time monitoring capabilities and data transmission efficiency. The discussion interprets these findings in the context of existing literature, highlighting the contributions and limitations of the developed system. This comprehensive analysis provides insights into the system’s potential applications and future improvements for enhanced water quality monitoring.
Calibration Result
The calibration of sensors is crucial for ensuring accurate and reliable measurements. Tables 2 to 4 highlight the data obtained during the calibration process for the pH sensor, TDS sensor, and temperature sensor. Figure 4 depicts the experimental setup during testing.
Figure 5. Experimental Set-up
pH Sensor Calibration
Table 2: pH Sensor Calibration Data
Buffer Solution (pH) | Measured pH | Error (pH) | Adjusted Offset | Acceptable Error (pH) | Notes | |
Before Calibration | After Calibration | |||||
4.01 | 3.77 | 4.03 | 0.02 | +21.25 | ± 0.2 | Initial calibration at pH 4.01 |
6.86 | 7.55 | 6.85 | 0.01 | +21.25 | ± 0.2 | Mid-point calibration at pH 6.86 |
9.18 | 9.85 | 9.17 | 0.01 | +21.25 | ± 0.2 | Final calibration at pH 9.18 |
Figure 6. Calibration Curve for pH Sensor
The pH sensor underwent calibration using buffer solutions of known pH values (4.01, 6.86, and 9.18). Initially, measured pH values differed significantly from these standards, highlighting the sensor’s need for calibration. The “Before Calibration” data showed a weak correlation with the buffer solutions, indicated by a low R² value, as seen in Figure 6, signifying inaccurate measurements.
Following calibration, where an offset adjustment of +21.25 was applied, the sensor’s accuracy improved notably. Post-calibration measurements closely aligned with the buffer solutions, as reflected in a high R² value for the “After Calibration” data. This strong correlation confirms the calibration’s effectiveness in enhancing the sensor’s performance and accuracy.
In summary, calibration substantially enhanced the pH sensor’s accuracy. Before calibration, the sensor showed considerable deviations from actual pH values, whereas after calibration, measurements closely matched the buffer solutions, demonstrating reliable and accurate performance as indicated by the high R² value.
Total Dissolved Solids (TDS) Sensor Calibration
Table 3: TDS Sensor Calibration Data
Reference TDS (ppm) | Measured TDS (ppm) | Error (ppm) | Percentage Error (%) | Acceptable Error (%) | Adjusted Calibration Constant | Notes | |
Before Calibration | After Calibration | ||||||
173 | 180 | 170 | 3 | 1.73% | ± 5 % | +3 ppm | Calibrated using a reference TDS sensor in the same solution |
338 | 328 | 330 | 8 | 2.37% | ± 5 % | +3 ppm | |
1025 | 1000 | 1005 | 20 | 1.95% | ± 5 % | +3 ppm |
Figure 7. Calibration Curve for TDS Sensor
The TDS sensor was calibrated using reference solutions with known TDS values of 173 ppm, 338 ppm, and 1025 ppm. To further validate the calibration, comparisons were made with results from several other studies, confirming the accuracy and reliability of the calibration process [3], [6], [9]. Initially, measured TDS values deviated significantly from these standards, indicating the sensor’s inaccuracy before calibration, despite a perfect R² value, as seen in Figure 7, suggesting a linear relationship.
After calibration, which applied an adjusted calibration constant of +3 ppm, the sensor’s accuracy notably improved. Post-calibration measurements closely matched the reference solutions, demonstrating enhanced accuracy despite the R² value remaining 1. This calibration process effectively aligned sensor readings with actual TDS values, showcasing improved performance.
In summary, calibration significantly improved the TDS sensor’s accuracy in measuring water quality parameters. Before calibration, despite perfect linearity, the sensor showed substantial deviations from actual TDS values. Calibration addressed these inaccuracies, highlighting its crucial role in ensuring precise data for effective water management and environmental sustainability.
Temperature Sensor (DS18B20) Verification
The temperature sensor (DS18B20) was verified against a known temperature reference. The sensor showed no deviation from the reference temperature, indicating that it is correctly calibrated.
Table 4: Temperature Sensor Calibration Data
Reference Temperature (°C)
(Current room temperature at the time) |
Measured Temperature (°C) | Deviation (°C) | Notes |
27.2 | 27.2 | 0.0 | Verified against a known temperature reference |
Experimental Result
Due to the device’s versatile use, the experimental phase involved testing three categories of water: rainwater, aquarium water, and drinking water. Each category included multiple samples collected from different locations. The results were analysed to determine the suitability of each water type for its intended use and whether the water is safe to drink. The device was calibrated before each testing to ensure accurate measurements. It should be noted that the analysis presented here is based solely on the water parameters tested and conforms to the safe standards provided by the Department of Environment (DOE) [10], [11], [12], [13]. Other parameters outside the scope of this research might influence the overall assessment and should be considered for a comprehensive evaluation of water quality.
Rainwater Harvesting Sample Analysis
Rainwater samples were collected from four locations: Shah Alam (Selangor), Melaka, Kelantan, and Terengganu. The data of the samples are recorded in Table 5. The pH and TDS values were measured to assess the water quality. The minimum TDS value detectable by the sensor is 30 ppm. Values below this threshold could not be detected by the sensor, so a calibrated TDS meter was used to measure these samples.
Table 5. Rainwater Harvesting Samples Data
Location | pH Value | TDS Value (ppm) | |
Calibrated Meter | Calibrated Sensor Reading | ||
Shah Alam, Selangor | 6.2 | 9 | 0 |
Melaka | 6.8 | 4 | 0 |
Kelantan | 6.5 | 24 | 0 |
Terengganu | 6.1 | 14 | 0 |
Figure 8. Rainwater Harvesting Graph Analysis
According to Figure 8, the pH values for rainwater ranged from 6.1 to 6.8, which is slightly acidic to near-neutral, typical for rainwater. The TDS values are all below 30 ppm, indicating low levels of dissolved solids. Since these values are below the sensor’s detection limit, they were measured using a calibrated TDS meter.
The variation in TDS levels among the locations can be attributed to different environmental factors. In Shah Alam, Selangor, the TDS value of 9 ppm suggests minimal contamination, possibly due to urban runoff or local industrial activities contributing trace amounts of dissolved solids. Melaka exhibited the lowest TDS value of 4 ppm, indicating very pure rainwater, likely due to lower industrial activity and cleaner atmospheric conditions. In Kelantan, the TDS value of 24 ppm is higher, possibly due to agricultural activities in the region, which can introduce more dissolved solids into the rainwater through atmospheric deposition. Terengganu showed a TDS value of 14 ppm, suggesting moderate levels of dissolved solids, possibly influenced by coastal factors or local environmental conditions.
While rainwater with these pH and TDS levels can be suitable for drinking, it is essential to ensure it is free from microbial contamination. The low TDS values indicate good water quality in terms of dissolved solids.
Aquarium Water Analysis
Samples from a swimming pool from a condominium in Seksyen 7 Shah Alam, Tasik Seksyen 7 (lake water), and sea water from Port Dickson were tested to evaluate their suitability for aquarium use. The data of the samples are recorded in Table 6.
Table 6. Aquarium Water Sample Data
Water Source | pH | TDS (ppm) |
Swimming Pool | 7.8 | 353 |
Tasik Seksyen 7 (Lake) | 6.5 | 104 |
Sea Water | 8.2 | 2000+ |
Figure 9. Aquarium Water Graph Analysis
According to Figure 9, the suitability of each water source for aquarium use varies based on its pH and TDS values. The swimming pool water, with a pH of 7.8, is slightly alkaline, which is typical for swimming pools to ensure disinfection. However, the TDS value of 353 ppm, while acceptable for pools, is not ideal for aquarium use due to the presence of chlorine and other chemicals. Lake water, with a pH of 6.5, is slightly acidic, making it suitable for certain freshwater fish species. The TDS value of 104 ppm indicates low to moderate levels of dissolved solids, making it generally suitable for aquarium use, although treatment to remove potential contaminants is recommended. Sea water has a pH of 8.2, which is slightly alkaline and typical for seawater. However, its TDS value exceeds the sensor’s maximum reading capability, being over 2000 ppm. This high salinity makes it suitable for marine aquariums that require such conditions but unsuitable for freshwater aquariums.
In terms of safety for drinking, swimming pool and sea water are not suitable due to chemical additives and high salinity, respectively. Lake water, despite its low TDS level, should be treated before drinking to remove potential pathogens and contaminants.
Drinking Water Analysis
Tap water and filtered water were tested to assess their quality for drinking purposes. The data of the samples are recorded in Table 7.
Table 7. Drinking Water Samples Data
Water Source | pH | TDS (ppm) |
Tap Water | 7.2 | 120 |
Filtered Water | 7.0 | 55 |
Bottled Mineral Water | 7.5 | 150 |
Figure 10. Drinking Water Graph Analysis
According to Figure 10, the suitability of each water source for drinking purposes varies based on its pH and TDS values. Tap water, with a pH of 7.2, is neutral and ideal for drinking. Its TDS value of 133 ppm is within the acceptable range for drinking water, indicating moderate levels of dissolved minerals. Filtered water also has a neutral pH of 7.0, and its TDS value of 55 ppm is low, indicating the removal of most dissolved solids, which is typical for filtered water. Bottled mineral water, with a pH of 7.5, is slightly alkaline, which is considered healthy for drinking. The TDS value of 157 ppm indicates a higher concentration of dissolved minerals, which can be beneficial for health.
In terms of safety for drinking, tap water, filtered water, and bottled mineral water are all suitable. The filtered water, with its low TDS, is particularly ideal for those seeking minimal dissolved solids in their drinking water, while bottled mineral water provides beneficial minerals.
The findings from the study highlight important limitations and usage guidelines for the TDS and pH sensors used in water quality monitoring. The TDS sensor is effective within a specific range, accurately measuring values between 30 ppm and 900 ppm. Samples with TDS values outside this range cannot be reliably measured by the sensor. To verify this, a calibrated TDS meter was used, confirming that the sensor cannot detect values below 30 ppm.
For pH measurements, the pH meter requires about a minute to stabilize after initial fluctuations. Accurate pH readings are obtained once the meter settles and show a constant value.
In conclusion, the experimental results demonstrate the system’s capability to monitor water quality effectively across various types, including rainwater, aquarium water, and drinking water. The study indicates that most samples are suitable for their intended purposes. However, water sources like swimming pools and seawater are identified as unsuitable for drinking due to their respective pH and TDS levels. It is crucial to conduct regular sensor calibration and monitoring to ensure precise and dependable assessments of water quality over time.
The developed water quality monitoring system has successfully achieved the objectives set forth at the project’s outset. Firstly, a comprehensive framework for future water testing characteristics was established through meticulous design and calibration processes. This ensured that the system could accurately monitor pH, TDS, and temperature parameters in real-time, providing users with critical insights into water quality. The calibration procedures implemented were effective in adjusting offsets for pH and TDS sensors, thereby enhancing measurement precision across their respective ranges and meeting stringent accuracy requirements.
Furthermore, the performance testing of the calibrated monitoring system confirmed its reliability in various applications, including rainwater harvesting and urban water management. The system’s ability to remotely monitor and manage water quality parameters demonstrates its contribution to sustainable water management practices and environmental health. The successful calibration and testing phases underscored the system’s capability to deliver accurate results essential for ensuring water safety and quality.
Looking ahead, several recommendations can enhance the system’s functionality and versatility. Improving sensor accuracy through advanced calibration techniques or higher precision components would bolster measurement reliability. Additionally, expanding the system’s monitoring capabilities to include parameters like ammonium levels, nitrogen content, and total suspended solids (TSS) would provide a more comprehensive water quality assessment. Lastly, optimizing the device design for compactness, aesthetics, and user ergonomics would enhance its practicality across diverse environments, furthering its adoption and effectiveness in water quality monitoring.
In conclusion, the successful development and implementation of this water quality monitoring system represent a significant advancement in addressing critical water management challenges. By incorporating these recommendations, future iterations of the system can continue to evolve, meeting the growing demands for effective and sustainable water quality monitoring solutions.
Availability of data and material
Some of the data are not available anymore becaususe most of the data are taken in real time of the experiment. Some of the mateial are still available,,
Funding
Since this is a senior final year project FYP, so all funding comes from pocket monhly allowance..
The authors would like to acknowledge University Teknolohgi MARA for giving us the opportunity to conduct this FYP.