Design of Li River Water Quality Dynamic Monitoring System Based on Raspberry Pi and TinyML

Abstract

In order to solve the problem of scientific monitoring of water quality, a trophic monitoring system for Li River water quality is developed to improve the decision-making of related environmental management departments. The system is based on embedded computing, deep learning and Internet of Things technology, combined with software and hardware design, to automatically obtain real-time water quality parameters with Raspberry Pi equipped with sensors and positioning modules. A camera is employed to capture the screen, and yolo-tiny image recognition is implemented in the Raspberry Pi. Lastly, the cloud storage is used for interaction to realize real-time monitoring of water quality, real-time positioning of the boat, real-time return of image recognition and visualization. The system is proven efficient and intelligent in facilitating water quality protection.

Share and Cite:

Tang, X.Y. (2023) Design of Li River Water Quality Dynamic Monitoring System Based on Raspberry Pi and TinyML. Journal of Computer and Communications, 11, 121-133. doi: 10.4236/jcc.2023.118009.

1. Introduction

1.1. Research Background, Objective and Significance of the Design

As a well-known tourist attraction, the Li River’s water quality affects the reputation and well-being of the neighboring cities. The water environment of the Li River is generally in good condition, with more than 99 percent of the total length of the river meets the I to III water quality throughout the year, but the water quality of the tributaries still needs to be improved. According to the Ministry of Ecology and Environment of the People’s Republic of China, due to the prominence of indiscriminate digging and excessive aquatic net-box farming, some sections of the Li River are facing deterioration of water quality, and the realization of sewage discharge treatment and the increase of ecological remediation in the vicinity of the river are imminent. Currently, domestic river flow monitoring systems are relatively well developed, with the only shortcoming being the inability to reflect real-time conditions. For uncontaminated or potentially contaminated sections of the river, real-time monitoring of water quality is needed to prevent problems before they occur.

Since the arrival of 5G technology wave, IoT is widely used in high dimensions. High-speed, low-loss networks enable efficient data computing in edge devices, information interaction between devices and remote control. Meanwhile, artificial intelligence technology can help data to be processed and analyzed intelligently. Deep learning technology is deployed on IoT devices to realize TinyML low-power machine learning for scientific and effective monitoring of the environment.

This system is developed for the realization of real-time watershed detection. Using the combination of Raspberry Pi and sampler, it provides convenient, timely and efficient detection of Li River’s water conditions. The project conducts long-term, macro and dynamic studies of the watershed, helping to support the development of ecology and protection of water resources.

1.2. Innovational Analysis from the Current Status Quo

Regarding the general way of water quality testing, methods such as acid-base titration and inductively coupled plasma mass spectrometry are used to test water quality, but they can only be based on a single variable and lack high efficiency. The traditional sampling methods range from manual sampling to mechanized sampling such as using airplanes, but it is easy to have secondary pollution and the labor and financial costs required are highly expensive. Although remote sensing monitoring does not require sampling, there are special perspectives, class imbalance and other technical defects. For the development of the dynamic status quo, Many scholars utilize one-chip computers and other microcontrollers equipped with sensors to monitor, such as Ren Fenglan, Cao Zheng, Yao Xing with STC89C52RC-40I-PDIP40 microcontroller + LCD1602 + AD0832 and other hardware to do the processor [1] , Cao Yang with a DSP as the core to control the sensor [2] . The biggest advantage of this system is the use of Raspberry Pi’s powerful processing capabilities, the detection of multiple variables, direct return to the dynamic data of the water body, time-saving and not a waste of resources to realize water quality testing, at the same time, the camera can be in the Raspberry Pi using visual algorithms to assist in its image capture and identification, more real and effective to implement the pollutant removal of the bit of the river section from the source.

2. System General Framework Design

In this study, in order to realize real-time monitoring of Li River, the research is divided into two parts: software and hardware. The hardware part consists of a Raspberry Pi equipped with several sensors, a camera module for image acquisition, a BDS/GPS module for localization. The software part implements image recognition with the yolo-tiny model, and utilizes cloud database and cloud object storage return to visualize the data, pictures, and identification tags collected on the Raspberry Pi side. The system framework is shown in Figure 1.

3. System Hardware Design

The framework diagram of the hardware part of the system is shown in Figure 2. The system takes Raspberry Pi 4B as the core controller. Raspberry Pi is a more functional micro-computer, above the deployment of microprocessors, and with a number of scalable interfaces makes it possible to connect to a variety of sensors, motors, LEDs and other devices. Raspberry Pi in the GPIO interface through the ADS1115 chip, connected to the sensor (parameters as in Table 1); in the camera and USB interfaces are connected to the camera and BDS/GPS module, respectively.

Figure 1. System framework.

Figure 2. Hardware framework diagram.

Table 1. Sensor parameters.

3.1. Controller Module

This project uses Raspberry Pi to control the system and realize the hardware piggybacking and deep learning models. Raspberry Pi uses ARM architecture processor and is portable and lightweight with the size of a credit card. It can run a variety of programming languages, such as Python, C, Java, etc. It supports a variety of development, from simple LED control to complex IoT systems.

3.2. Temperature Sensors

Temperature is closely related to chemical reactions in water, microbial activities and dissolved oxygen. This system uses an NTC temperature sensor for temperature detection [3] , which can make the Raspberry Pi acquire data at different temperatures. When the temperature increases, the resistance of the sensor becomes lower in a linear relationship. Its peripheral circuit is shown in Figure 3.

3.3. Turbidity, PH & ORP Sensors

When the river has gravel and other materials, the sunlight scattering rate through the water and absorption rate will change, the greater the value of the turbidity sensor indicates that the turbidity of the water is large, and PH can change the dissolved oxygen in the water as well as a series of chemical reactions in the water, while too low PH is not conducive to the photosynthesis of plants in the water, the ORP (Oxidation-Reduction Potential) is the reaction to the amount of redox in the water, A lower ORP indicates a weaker oxidizing nature of the water, vice versa. The principle of these three sensors is similar, when the sensor senses a weak voltage change, it is amplified by a gain-amplification circuit. When the corresponding indicator increases, the potential increases proportionally, and the indicators of ORP and turbidity sensors are judged by directly referring to the level of the potential. Especially, for PH sensor, standard liquid is taken to calibrate it, and the calibration formula is shown in (1).

PH = V/(−60) + 28.5 (1)

In addition, since they output analog quantities, in order to derive discrete values that are relatively easy to analyze, they need to be converted by the ADS1115 chip, which gets the corresponding digital quantities through I2C bus transmission and outputs them in the background. The schematic diagram is shown in Figure 4, and the peripheral circuit diagram is shown in Figure 5.

Figure 3. Schematic diagram of the peripheral circuit.

Figure 4. Schematic of Raspberry Pi, ADS1115, sensors.

Figure 5. Peripheral circuit diagram.

3.4. BDS/GPS Module

BDS/GPS module is the same kind of satellite propagation and reception, the signal to determine the location of the module, the module to obtain fast and accurate positioning, conducive to real-time position return. The principle of use is that after receiving the signal, the module calculates and processes the signal to return the real-time location. To enable the monitoring of water quality at different locations of the river, this device is added to Raspberry Pi. The schematic is shown in Figure 6.

Figure 6. Schematic diagram of BDS/GDS.

3.5. Camera Module

By connecting the CSI camera to the camera connection of the Raspberry Pi, the module can be controlled by a program to take pictures and save them locally at certain time intervals. Using the camera module, it is possible to view the surrounding garbage while the boat is running on the water and recognize it through deep learning algorithms.

4. Software Design

The software part of the system includes a deep learning algorithm, storage end and visualization end. Using Tiny-Yolo model to run deep learning on Raspberry Pi to achieve the recognition of garbage, water plants, etc.; while the storage end includes cloud database and object storage; displaying the content obtained from the database to the platform, and doing visualization of all the data obtained from the sensors and the content derived from the image recognition.

4.1. TinyML Image Recognition

TinyML refers to the adoption of microcontrollers for low-power machine learning. Instead of running complex machine learning models on large, power-hungry cloud computers, this new approach runs optimized recognition models on end devices with microcontrollers that consume no more than a few milliwatts of power. To sort out the types of trash on the water, TinyML technology was used to identify the types of trash on the water.

4.1.1. The Yolo-Tiny Model

Commonly used image recognition models are CNN convolutional models. CNN model is divided into convolutional layer, a pooling layer and a fully connected layer. The image can be represented as a matrix consisting of 0 and 1. The convolution kernel and the corresponding matrix are multiplied and summed to obtain a new matrix; the pooling layer compresses the neural network, and the fully connected layer classifies the features after they are extracted, and finally recognizes the image. However, after the proposal of CNN, YOLO model was introduced to make image recognition faster.

Yolov5 is an improved version of the Yolo model. Mosaic mix-up of the input image, image processing adding Focus, CSP, FPN + PAN structure, in the output layer with coupled Head multi-scale predictive recognition. The loss function of the model has cross-entropy loss function BEC loss. the model network architecture is huge, divided into convolutional layer and pooling layer, and has good performance, the algorithm flow is shown in Figure 7. The Yolo-Tinyv5 is roughly similar in principle relative to the Yolov5, but it is more lightweight, which is in line with the characteristics of the Raspberry Pi microprocessor such as low power as well as insufficient processing power.

4.1.2. Data Collection and Training Process

The training environment is based on the darknet framework (Figure 8) and is trained with the help of Python version 2.7 under the model of Tiny-Yolov5 using Raspberry Pi 4B. The dataset is 1327 garbage pictures of Li River water body searched online. After labeling the images well, the training set and test set are divided in the ratio of 6:4. The training results are saved in the form of images under the specified path, and the image recognition results are shown in Figure 9.

Figure 7. Yolov5 algorithm flow.

Figure 8. Darknet framework.

Figure 9. Example of image recognition results.

4.1.3. Model Evaluation

The model was evaluated using Map@.5 (%) and Map@.5:.95 (%) [4] , where MAP is the mean area of the P-R curves plotted with the percent of detection and recall. The larger the area, the better the model fit; the smaller the area indicates that the model is under-fitted. The Map value is 90.0 for a LOU threshold of 0.5, and the average MAP is 61.4 when the threshold is within the range of 0.5 to 0.95. The training dataset has a reasonable amount of data, does not have low generalization, and with a high Map value, the model is well-fitted and the prediction results are accurate.

4.2. Cloud Database and Object Storage

The cloud database performs operations such as building and deploying through the cloud platform and the project interacts with a relational database MYSQL. A cloud storage object is an unstructured storage built in the issa layer of AliCloud that can store a variety of objects such as audio files and images. For this project, when the user gets the image, only the link of the image is saved. In the image recognition session, the recognition results are saved in the cloud storage together and uploaded to the cloud database. The object storage structure of this project is shown in Figure 10.

Figure 10. Object storage structure.

4.3. Design of Water Quality Testing Platform

Water quality monitoring platform with Vue framework (Java) + Gin framework (go) development. Visualization charts using Echarts to show the overall framework based on B/S, to create a platform with low coupling, usability and close to the user.

Introduction to the Web Page

1) Log-in page

Users can use the registered information to log in after registration, if you do not enter the username and password during the login process, the system will prompt “user name and password can not be empty, please re-enter”. If the password entered is wrong, the system will prompt “Password is wrong, please re-enter”. If the user name is wrong, the system will prompt “User name does not exist”. User name and password are correct to enter the system, the page in Figure 11 [5] .

2) Water quality testing page

The water quality testing page consists of four dynamic line graphs showing the changes in PH, ORP, temperature and turbidity from top to bottom. The program outputs data every three seconds and returns to the front end via WebSocket to the database, as shown in Figure 12.

3) Positioning page

This page gets the data returned by the positioning displayed on the Baidu map. When the location of the Raspberry Pi changes, the specific river can be determined by the location on the map. As shown in Figure 13.

4) Image Recognition Page

The user can see the image captured by the Raspberry Pi and the result of the image recognition to come up with the major pollutants in the place to carry out river protection. As shown in Figure 14, the captured image recognized the result as BOTTLE.

Figure 11. Login page.

Figure 12. Water quality testing page.

Figure 13. Positioning page.

Figure 14. Recognition page.

Figure 15. Test schematic.

Table 2. Test results.

5. System Test

To facilitate testing and recovery, the device was placed in a stationary lake (Figure 15) and the test data and results are shown in Table 2.

Table 3. Some of the data read.

Figure 16. Data presentation.

The data was recorded as shown in Table 3, and the graph is shown in Figure 16.

All values can be seen to fluctuate steadily within reasonable limits, and the results are true and valid, from the hardware to the software of the system are functioning properly and as expected. It further shows that the system is powerful and highly usable.

6. Summary

This study is aimed at solving the real needs of water quality monitoring of water bodies in the Li River Scenic Area, developing a water quality detection system, which is based on the Raspberry Pi microcontroller, giving full play to its powerful processing capabilities and diverse interfaces, accessing a variety of sensors such as PH, turbidity, temperature and other sensors to monitor the quality of the water, accessing the camera to monitor the water body, and accessing the GPS localization. The system uses TinyML for visual processing to identify the water body garbage, monitoring data real-time back to the cloud background MySQL database, and build a platform in the cloud to carry out analysis and judgment, demonstrate the spatial and temporal dimensions of the water quality parameters visualization. The system has been tested to be stable and practical, and can be put into practical application, which can enable the environmental protection department to grasp the situation in a comprehensive and real-time manner, carry out long-term monitoring, improve the decision-making ability, help prevent the eutrophication of the water body of the Li River, and promote the ecological and environmental management of the Li River. At the same time, it can provide a convenient and fast intelligent integrated monitoring means for similar water quality monitoring needs of rivers and lakes and water resources protection. As a project optimization, machine learning algorithms can be added to the acquired sensor data for further prediction of water quality trends, which can provide more information to Li River protection staff.

Conflicts of Interest

The author declares no conflicts of interest regarding the publication of this paper.

References

[1] Ren, F.L., Zhao, Z. and Yao, X. (2023) Design of Water Quality Inspection System Based on Microcontroller. Electromechanical Engineering Technology, 52, 166-169+248.
[2] Zhou, C.H., Yang, Y., Ma, P. and Cao, Y. (2022) Design of Unmanned Ship Water Quality Detection System Based on DSP. Technology and Innovation, 17, 24-26.
[3] Fei, X.X., Wu, S.Y., Zhu, H.S., Ma, Z.J. and Tang, M. (2022) Design and Implementation of Unmanned Shipboard Computer Software for Surface Water Quality Testing. Computer Age, 9, 49-52.
[4] Di, J. and Qu, J.H. (2020) Detection of Apple Leaf Diseases Based on Tiny-YOLO. Journal of Shandong Normal University (Natural Science Edition), 35, 78-83.
[5] Qiu, Q. (2020) Development of Evaluation System for Technical College Students Based on Java Technology. China New Technology and New Products, 17, 20-21.

Copyright © 2024 by authors and Scientific Research Publishing Inc.

Creative Commons License

This work and the related PDF file are licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.