# Water Quality Monitoring: A Water Quality Dataset from an On-Site Study in Macao
## 2 System Design  
In this project, a number of pH sensors [6], TDS sensors [7], temperature sensors (DS18B20) [8], and turbidity sensors [9] were connected to the Raspberry Pi via an Arduino for data acquisition and transmission. Each sensor is connected to either an analog or digital input port on the Arduino; for example, the pH and TDS sensors are connected to analog pins A0 and A1, respectively, the turbidity sensor is connected to analog pin A3, and the temperature sensor (DS18B20) is connected via a 1-wire protocol to a digital pin (e.g., D2) on the Arduino. The Arduino converts the analog signals from the pH, TDS, and turbidity sensors into digital signals via its analog-to-digital converter (ADC) [10] and transmits the processed data to the Raspberry Pi in real time via serial communication using the UART protocol [11]. Data transfers from the Arduino to the Raspberry Pi are at fixed intervals, typically every 5 s. The data transfer takes place via UART communication, and each sensor's data are packaged in a structured format (usually JSON) to ensure that the information transmitted is easy for the Raspberry Pi to parse and process [12]. The data sent from the Arduino to the Raspberry Pi are transmitted at regular intervals based on a defined sampling rate. The sampling period is uniform for each sensor to ensure that all sensors collect data synchronously. Once the data are received, the Raspberry Pi reads the transmitted information using a Python (version 3.11; [[https://www.python.org/](https://www.python.org/)]([https://www.python.org/](https://www.python.org/))) script and stores it in a local SQLite (version 3.44; [[https://www.sqlite.org/](https://www.sqlite.org/)]([https://www.sqlite.org/](https://www.sqlite.org/))) database for subsequent processing and analysis. The workflow then proceeds with data preprocessing, which includes cleaning and preparing the collected data for further classification. These processed data are classified into three levels based on predefined thresholds for each sensor parameter: meets physicochemical criteria, boundary conditions, and does not meet physicochemical criteria. These classifications help to assess the water's quality and determine its suitability for consumption. To validate and improve the classification accuracy, machine learning models such as Isolation Forest, Random Forest, Logistic Regression, and Local Outlier Factor are used for anomaly detection and model validation. The results from these models are analyzed and evaluated to ensure the system's reliability in classifying water quality. The validation process involves comparing the predicted classifications with actual water quality data and adjusting the models as needed to improve their performance. The outcome is a robust water quality monitoring system that uses both sensor data and machine learning techniques to provide real-time insights into water safety. The workflow of the system is illustrated in Figure 1. The process starts with data acquisition and transmission, followed by preprocessing, classification, and machine-learning-based validation to assess water quality.  
The system's hardware structure, as shown in Figure 2, consists of multiple sensors connected to an Arduino, which then transmits data to a Raspberry Pi for further processing and storage in an SQLite database. This architecture ensures efficient data acquisition and real-time monitoring.  
To verify the implementation, a simulation setup was developed, as shown in Figure 3.  
Figure 1: Workflow of the water quality monitoring system.  
Figure 2: System hardware structure, showing sensor connections and data transmission.