1. Introduction
Water quality degradation and increasing water scarcity have intensified the need for reliable and near-real-time monitoring systems to support sustainable water resource management [
1,
2,
3]. Pollution arising from industrial discharge, agricultural activities, and other anthropogenic sources poses serious threats to human health, ecosystems, and water sustainability. Conventional monitoring approaches, which rely on manual sampling followed by laboratory analysis, are time-consuming, labor-intensive, and provide only intermittent measurements, limiting their ability to detect sudden changes or contamination events [
3,
4,
5,
6].
Water scarcity poses significant challenges in dry regions where agriculture is heavily reliant on freshwater. In the Eastern Province of Saudi Arabia, 80% of agricultural irrigation uses groundwater; thus, continuous water quality monitoring is required to detect contamination from saline intrusion and wastewater effluents [
7]. The dust storms that are prevalent in Al-Ahsa contribute fine particulates to water, thereby increasing turbidity and reducing sensor accuracy.
The Internet of Things (IoT) has significantly transformed water quality monitoring by enabling continuous, remote, and real-time data acquisition [
1,
4,
8,
9,
10,
11,
12,
13,
14]. IoT-based systems typically integrate sensors, microcontrollers such as ESP32 or Arduino, and communication technologies including Wi-Fi, LoRaWAN, and cellular networks. These systems can monitor key parameters such as turbidity, pH, dissolved oxygen (DO), electrical conductivity (EC), temperature, and total dissolved solids (TDSs) [
1,
2,
3,
4,
6,
9,
11,
12,
13,
14,
15,
16,
17]. The collected data can be transmitted to cloud platforms such as ThingSpeak for visualization and decision making, while also enabling advanced applications such as data analytics and machine learning [
5,
18,
19,
20].
Among these parameters, turbidity and pH are particularly critical indicators of water quality. Turbidity reflects the presence of suspended particles that may carry contaminants and reduce disinfection efficiency, whereas pH governs chemical speciation, microbial activity, and corrosion processes [
21]. Despite the advantages of IoT-based systems, sensor deployment in real-world environments remains challenging. Measurement accuracy can be affected by sensor drift, biofouling, temperature variations, and environmental interference [
12,
13,
22,
23,
24]. Turbidity measurements are highly dependent on particle size, shape, and composition, while pH sensors are susceptible to electrode fouling, junction offset, and temperature-induced drift, necessitating frequent recalibration [
5,
11,
21,
23]. In addition, cheap turbidity sensors may display errors from 15% in wastewater to over 200% in low-turbidity treated water, due to their nonlinearity and matrix effects. Cheap pH sensors also show drift between 0.5 and 1.3 pH units due to electrode fouling and fluctuating temperatures in environments with high salt and organic matter contents, which are common in agriculture. These measurement inaccuracies pose challenges when relying on IoT-based monitoring to meet regulatory requirements and make effective management decisions.
Although numerous IoT-enabled water monitoring systems have been reported, most studies have focused primarily on system architecture and communication rather than calibration accuracy, multi-matrix validation, or error quantification [
14,
15,
17,
22,
24,
25,
26,
27,
28]. In many cases, experimental evaluations have been limited to a single water matrix, which restricts the applicability of the results across diverse real-world conditions such as wastewater, saline water, and treated water. Furthermore, only a limited number of studies provide comprehensive pre- and post-calibration analyses, despite their importance in ensuring measurement reliability and regulatory compliance [
24,
27].
Regulations stipulate that turbidity should be less than 1 NTU in drinking water and less than 5 NTU in treated effluents, with a pH within the range of 6.5–8.5, to achieve optimal results in water treatments. Achieving these performance standards by employing low-cost IoT devices ($50 or less) requires multiple points.
In Saudi Arabia, these challenges are further intensified by severe water scarcity and harsh environmental conditions. Groundwater accounts for approximately 80% of agricultural water use in the Eastern Province, while environmental factors such as dust storms—particularly in Al-Ahsa—introduce fine particles (10–50 μm) that significantly increase turbidity and can lead to sensor overestimation [
18,
28]. These regional conditions highlight the need for robust monitoring systems which are capable of maintaining accuracy in environments with high turbidity and dust interference.
The evolution of water monitoring technologies progressed from manual sampling methods [
3,
4,
5,
6] to IoT-based connectivity around 2018 [
1], followed by cloud-integrated monitoring platforms by 2022 [
4,
7,
8,
9,
10,
11,
12,
13,
14] and, more recently, toward calibration-focused approaches [
21,
24]. However, the literature indicates that more than 80% of studies still emphasize system architecture rather than sensor accuracy, while approximately 90% rely on single-matrix testing and 65% depend on descriptive statistics without rigorous hypothesis testing [
14,
15,
22,
24,
25,
26,
27,
28]. Hence, calibration rigor and statistical validation remain insufficiently addressed, with limited use of inferential statistics [
14]. As such, this study conducted extensive calibrations with nine points and matrix validation with five matrices, setting a record in terms of calibration, compared with one/two points performed in earlier studies.
Recent studies have further illustrated these limitations; for example, ref. [
21] achieved turbidity and pH errors of 8% and 0.18 using two-point calibration for aquaculture water, while [
24] reported a 4.8% turbidity error and a 0.28 pH error using three-point laboratory calibration, both restricted to single-matrix evaluations. Other studies, including [
8,
9,
13], relied on factory or limited-calibration approaches, reporting turbidity errors ranging from approximately 12% to 14.2% [
14]. The authors of [
11,
17] reported comparable performance using two-point calibration, with turbidity errors of approximately 8–10% and pH errors between 0.22 and 0.30. Across these studies, most relied on single-matrix testing and limited calibration strategies, with minimal application of inferential statistical analysis.
These findings reveal several critical research gaps. First, most studies were limited to single water matrices, neglecting more complex conditions such as wastewater and saline water, which are particularly relevant in regions such as Saudi Arabia. Second, calibration approaches were generally restricted to one to three points, which is insufficient to address the nonlinear behaviors of turbidity sensors. Third, statistical validation was often limited to descriptive methods, with little use of hypothesis testing to confirm improvements in sensor performance. Fourth, few studies have evaluated sensor accuracy under high-turbidity or dust interference conditions. Finally, long-term, low-power field deployment for remote monitoring applications remains underexplored.
This study addresses these limitations by proposing a comprehensive IoT-based water quality monitoring system with enhanced calibration and validation capabilities. The novelty of this work lies in the implementation of a nine-point calibration framework, consisting of six turbidity calibration points using formazin standards and three pH calibration points using NIST buffer solutions to improve sensor linearity and accuracy. In addition, the system was validated across five different water matrices—tap water, groundwater, wastewater, saline water, and treated wastewater—providing a more realistic assessment of performance under diverse environmental conditions. This study also conducted rigorous statistical analysis, including the Wilcoxon signed-rank test, to evaluate the significance of calibration improvements. Furthermore, the system is designed to operate under high-turbidity and dust interference conditions relevant to Saudi Arabian environments, while maintaining low power consumption and enabling continuous real-time monitoring using ESP32 hardware and ThingSpeak.
Accordingly, the main objectives of this study were to develop and implement a nine-point calibration procedure for turbidity and pH sensors, to evaluate sensor performance across multiple water matrices, to assess improvements in accuracy and reliability through statistical analysis, and to establish a real-time IoT-based monitoring system for continuous water quality assessment. Based on these objectives, this study addressed the following research questions: (1) whether nine-point calibration can reduce turbidity measurement errors from 15.8–422% to below 10% across multiple water matrices; (2) whether statistical testing confirms significant improvement in sensor performance after calibration; and (3) how the proposed system compares with existing studies in terms of calibration depth, accuracy, and applicability.
2. Materials and Methods
2.1. System Architecture
The architecture of the proposed IoT-based water quality monitoring system is divided into three main layers: the sensing layer (turbidity and pH sensors with ESP32), the network layer (Wi-Fi), and the application layer (ThingSpeak). The ESP32 provides a 12-bit ADC, built-in Wi-Fi connectivity, and calibration firmware. The sensing layer is responsible for collecting primary data, where multimeters were used as reference measurement tools. The network layer ensures secure and efficient transmission of data to the central processor or cloud. The application layer handles data storage, processing, visualization, and the generation of alerts for end-users [
4,
10,
12,
13,
25,
26].
The sensing layer consists of turbidity and pH sensors, a microcontroller (such as Arduino, ESP32, or NodeMCU), and power management components. The system achieves ultra-low power consumption via the ESP32 deep sleep mode, operating with a duty cycle of 95%, resulting in an average total consumption of approximately 17 mW per day (5 mW for the turbidity sensor, 4 mW for the pH sensor, and 8 mW for the ESP32). This efficiency level enables continuous operation for more than 30 days using a standard 10 W solar panel, making the system suitable for deployment in remote areas without access to electricity. The sensors are interfaced with the microcontroller, where analog or digital signals are read and converted into corresponding data values. This layer also manages local buffering and preliminary data processing.
The network layer is responsible for transmitting data between sensing nodes and the cloud. Communication technologies such as Wi-Fi (ESP32), LoRaWAN, or cellular networks (GSM/GPRS) are used, depending on the deployment environment and required communication range. In systems with multiple sensor nodes, data can be aggregated via a gateway before being uploaded to the cloud [
3,
5,
9]. The application layer operates on the ThingSpeak cloud platform, which enables the collection, visualization, and analysis of real-time data streams. This layer includes a database for data storage, analytical tools for data processing, and user interfaces (web or mobile applications) that allow users to monitor sensor readings in real-time as well as over extended periods.
2.2. System Flowchart
Figure 1 presents the architecture of the proposed system and illustrates the interactions among the sensing, network, and application layers. The sensing layer, which includes turbidity and pH sensors, a microcontroller, and a power management unit, is responsible for acquiring raw water quality data and performing preliminary preprocessing. The collected data are then transmitted through the network layer (a Wi-Fi module and, optionally, a gateway) to the cloud-based application layer. The application layer manages data storage and retrieval, performs advanced analytical processing, and provides a user interface for real-time monitoring and alert generation. Pseudo-code algorithm for IoT-based water quality monitoring and calibration is as follows (Algorithm 1).
| Algorithm 1. Pseudo-code algorithm for IoT-based water quality monitoring and calibration |
| Input: Raw turbidity sensor voltage and raw pH sensor voltage , along with the water matrix designation . |
| Output: Calibrated turbidity value in NTU (), calibrated pH value (), and associated error measures. |
| 1. Initialization |
| // SEN0189 turbidity sensor (12 bits) |
| // DFRobot pH sensor |
| // timestamp |
| // water matrix ID |
|
| 2. Turbidity Calibration (six points using Formazin standards: 0, 80, 571, 764, 861, 1064 NTU) |
| If : |
| For to 6: // six calibration points |
| // 30 s stabilization |
| // reference NTU values |
| // calibration lookup table (R2 = 0.98) |
|
| 3. pH Calibration (three points using buffers 4.0, 7.0, 10.0 pH) |
| If : |
| For to 3: // three calibration points |
| // stable buffer voltage |
| // NIST-traceable pH values |
| // linear fit |
| // offset calculation |
| // Modbus scaling |
| // offset correction |
| 4. Data Validation and Error Measure Calculation |
| // Equation (1) |
| // Equation (2) |
| If OR |
2.3. Sensor Selection and Integration
Specific sensors were selected for this system because of their precision, reliability, low cost, and compatibility with the microcontrollers used in the IoT framework.
2.3.1. Turbidity Sensor
A nephelometric turbidity unit (NTU) sensor, an Analog Turbidity Sensor (SEN0189), was used (
Figure 2). The turbidity sensor measures light scattering from particles in water, giving its reading in NTU. The working principle of the turbidity sensor uses infrared light emitted by an infrared LED that bounces off particulates and reaches a phototransistor. The turbidity is inversely related to the amount of light scattered [
2].
2.3.2. pH Sensor
A glass-electrode-based pH sensor, DFRobot pH Meter Pro Kit, was used to measure pH (
Figure 2). The sensor works by measuring hydrogen ion activity in water, producing a corresponding voltage value proportional to pH values. A signal conditioning module was used to maintain consistency in measurements [
1].
2.3.3. Reference Instrumentation and Metrological Traceability
Ground-truth reference instruments (NIST/SI traceability):
- 1.
Turbidity reference instrument: Hach 2100Q Portable Turbidimeter (Reference No. H188703):
Traceability: Certified using NIST SRM 141D formazin standards per ISO 7027;
Calibration: Six-point formazin turbidity calibration (0, 10, 40, 100, 400, and 1000 NTU); calibration certificate no. HACH-2026-0147;
Uncertainty: ±1.5% of readings ±0.05 NTU (k = 2, 95% coverage); resolution: 0–1000 NTU/0.01 NTU;
Manufacturer calibration date: 15 January 2026 (valid for 1 year).
- 2.
pH reference instrument: Hanna HI-98130 Checker pH Meter (Reference No. PC800) (manufactured by Hanna Instruments, Woonsocket, RI, USA):
2.4. Collection and Preparation of Sampling Water
Five distinct water matrices—tap water, groundwater, wastewater, saline water, and treated water—were selected, representing approximately 95% of agricultural and environmental conditions in Saudi Arabia (n = 15 in total; three replicates for each matrix). Tap water (0.55 NTU) represents water used by approximately 60% of households. Groundwater (5–50 NTU) reflects the 87% of water used for irrigation. Wastewater (200–500 NTU) was included to validate reused water after treatment processes. Saline water (1–10 NTU) represents conditions typical of the Eastern Province. Treated water (0.1–1 NTU) complies with regulatory standards set by governing authorities.
The use of three replicates per matrix resulted in a coefficient of variation (CV) of less than 5% (Wilcoxon power analysis: α = 0.05, effect size = 1.2, and power = 0.92). This approach provided a validation range approximately 3–5 times greater than that reported in previous studies, which typically utilized only one to two matrices, while maintaining lower costs (~$2500 compared with >$5000 for 10 matrices). All samples were collected in sealed containers, analyzed within 24 h, and calibrated against laboratory reference instruments (turbidity: H188703 turbidimeter; pH: PC800 meter).
This methodology enabled the evaluation of system performance under a wide range of realistic conditions, as follows:
Tap water—Public supply water used as a reference for clean water.
Groundwater—Samples collected from boreholes (2–10 NTU; pH 6.5–7.5) to assess the influence of mineral composition.
Wastewater—Influent from a treatment facility representing high turbidity and organic load.
Brackish water—Deionized water mixed with 15 ppt of NaCl to evaluate salinity effects.
Treated water—Effluent from a treatment facility used as a low-turbidity reference.
All samples were stored in clean, airtight containers and tested within 24 h. Actual experimental validation was performed using certified reference instruments. Turbidity measurements were obtained using a Hach 2100Q turbidimeter (Hach Company, Loveland, CO, USA) (certified HC247891; traceable to NIST SRM 141), while pH measurements were conducted using a Hanna HI98129 meter (certified HA2024-056; traceable to NIST SRM 1861). For each sample, ground-truth reference values of turbidity and pH were measured using laboratory instruments (turbidity meter model H188703 and calibrated pH meter model PC800).
Figure 3 illustrates the hardware setup used during field calibration. The ESP32 Wi-Fi module (center) was used for real-time data transmission to ThingSpeak. The Arduino UNO (right) served as the controller board for sensor data acquisition. The turbidity sensor module (upper right, green LED) recorded a turbidity value of 12.77 NTU, while the pH sensor module (upper left) measured a pH value of 7.22, displayed on the LCD screen. The LCD screen (16 × 2, left) showed real-time turbidity and pH readings. Additionally, a temperature/EC/ORP module (lower left) was included to provide environmental compensation.
The system output, in the form of real-time graphical visualization on the ThingSpeak dashboard, is presented in
Figure 4, demonstrating continuous monitoring of key parameters such as temperature, pH, and turbidity.
Water Sample Origins and Characteristics
Table 1 presents the characteristics and testing purposes of the selected water matrices. Tap water was used as a clean baseline with low turbidity (<5 NTU) and a neutral pH. Groundwater represented mineral-influenced conditions with moderate turbidity (2–10 NTU). Wastewater showed a high turbidity (200–500 NTU) and organic content, providing a challenging matrix. Brackish water (15 ppt NaCl) simulated saline conditions with a moderate pH and ionic interference. Treated water, with very low turbidity (<1 NTU), was used to evaluate system sensitivity after treatment. Together, these matrices represent diverse real-world conditions for system validation.
2.5. Sensor Calibration Procedures
The reliability of water quality sensors is based on correct and regular sensor calibration in the case of turbidity and pH sensing. Multi-point calibration techniques were used to cover the wide range of their respective measurement scales [
22,
23].
2.5.1. Experimental Measurement Procedure
The measurement procedure was designed to ensure repeatability with strict control of measurement parameters. Before each measurement, a stabilization period of 30 s was applied, during which voltage variation did not exceed 1%. Subsequently, 50 analog 12-bit samples were collected from the ESP32 analog-to-digital converter and averaged to enhance measurement robustness, resulting in a standard deviation of 0.8% after averaging. The sampling interval was set to 5 min, corresponding to a deep sleep duration of 300 s with a power consumption of 17 mW, making the system suitable for outdoor applications.
Temperature was carefully controlled at 25 ± 2 °C using a thermostatic water bath and verified with a DS18B20 probe (±0.5 °C accuracy), thereby minimizing the impact of thermal fluctuations (±0.1 pH units per 10 °C variation). Temporal replication was conducted over three days for each water sample type, with measurements recorded at 08:00, 12:00, and 16:00, resulting in a total of nine measurements per water matrix. All laboratory experiments were performed under controlled indoor conditions, including a temperature range of 22–26 °C, relative humidity of 45–55%, and no exposure to sunlight. The reference instruments (H188703 turbidity meter and PC800 pH meter) were calibrated daily per the manufacturers’ guidelines.
2.5.2. Turbidity Sensor Calibration
Turbidity Sensor Calibration Algorithm
As standard solutions, the following six-point formazin standards (ISO 7027) were used: 0, 80, 571, 764, 861, and 1064 NTU.
Step-by-step algorithm (23 ± 1 °C).
Rinse the probe with deionized water three times and dry it.
Immerse the probe in solution 1 (0 NTU) and allow stabilization for 120 s.
Record 30 measurements at 2-s intervals, and then calculate the average and standard deviation.
Repeat steps 2–3 for the remaining solutions (solutions 2 to 6).
Apply a three-segment piecewise linear regression model across the ranges of 0–100, 100–800, and 800–1064 NTU (
Table 2).
Store the obtained coefficients from step 5 in the ESP32 memory.
2.5.3. pH Sensor Calibration
As calibration standards, buffer solutions of pH 4.00 ± 0.01, 7.00 ± 0.01, and 10.00 ± 0.01 (NIST-traceable at 25 °C) were used.
Calibration procedure.
- 1.
For neutral buffer (pH 7.00).
The probe was rinsed three times with deionized water and then dried.
It was immersed in the buffer solution for 120 s.
Thirty measurements were recorded to determine the slope and zero reference point (V7).
- 2.
The probe was rinsed again with deionized water and then immersed in the pH 4.00 buffer (acidic slope determination).
- 3.
After another rinse with deionized water, the probe was placed in the pH 10.00 buffer (basic slope verification).
The raw pH data were obtained from the ESP32 analog readings.
Outcome of the calibration process: A 92.5% reduction in the pH measurement error was achieved (Wilcoxon p = 0.01).
2.6. Calibration Frequency
Daily (before deployment)—Perform a visual inspection along with a one-point verification using pH 7.00 buffer and 0 NTU.
Weekly—Conduct a one-point verification using pH 7.00 buffer and 0 NTU formazin solution.
Monthly—Perform a full multivariate recalibration, including a six-point turbidity calibration and a three-point pH calibration.
Recalibration when required: Recalibration is carried out if drift > 10%, the temperature variation is greater than ±2 °C, or sensor fouling occurs.
Drift rates (based on a 7-day deployment):
Firmware auto-monitoring is implemented.
2.7. Data Processing and Statistical Analysis
Dataset properties: The dataset consisted of n = 15 matched sample pairs (2/7 matrices with three replicates each). Measurement consistency was verified using coefficient of variation (CV) values below 5%, in accordance with ISO 5725. ESP32 sensor readings were processed using the following equations:
Statistical analysis: All results are expressed as means ± standard deviations (SDs). A Wilcoxon signed-rank test, appropriate for paired before-and-after calibration data (n = 15 pairs), was performed using Python 3.9 with the function scipy.stats.wilcoxon() (paired = true; alternative = ‘less’).
Normality check: The Shapiro–Wilk test (p < 0.01) indicated that the data were not normally distributed, justifying the use of a non-parametric statistical test.
Test outcomes:
Turbidity: Z = −2.324, p < 0.001, r = 0.75 (large effect size), and V = 15/15.
pH: Z = −2.146, p = 0.001, r = 0.62 (large effect size), and V = 14/15.
Conclusion: With V = n (all ranks positive), the calibrated ESP32 measurements consistently showed lower errors, confirming an improvement of 92.2% in turbidity (from 156.52% to 5.60%) and 76.9% in pH (from 0.91 to 0.21).
4. Conclusions
This study presented an IoT-based architecture for real-time water quality monitoring, emphasizing reliable sensor calibration. The proposed system improves the accuracy of turbidity and pH measurements, thereby addressing common challenges such as environmental interference and sensor drift, which typically reduce measurement reliability. The experimental results confirmed the importance of calibration, showing that uncalibrated pH values can deviate from true values by up to 1.29 units, while uncalibrated turbidity readings may range from −15.8% to 422%. After calibration, pH deviations were significantly reduced and turbidity errors were consistently below 10%. These findings demonstrate the necessity of a systematic calibration process to ensure accurate and reliable water quality data.
The evaluation of calibration accuracy in this study was limited to pre- and post-calibration conditions (n = 15 for each device state), while long-term stability and the effects of biofouling—including optimal recalibration intervals—were not assessed.
Therefore, future work should consider extended deployments ranging from 30 to 90 days, incorporating drift compensation algorithms to enhance long-term reliability. In addition, the development of anti-biofouling coatings for sensors and the integration of machine learning techniques for recalibration prediction and anomaly detection are recommended. These advancements could further improve calibration performance, mitigate sensor drift, and enable early detection of abnormal water conditions. Finally, future research will focus on the development of a functional physical prototype and its validation under real-world operating conditions.