Research on Intelligent Chemical Dosing System for Phosphorus Removal in Wastewater Treatment Plants

: Whether the phosphorus removal chemical in wastewater treatment plants (WWTPs) can be accurately dosed not only affects the compliance of the effluent total phosphorus but also has a huge impact on sludge production and energy consumption during the wastewater treatment process. For the effluent from the secondary sedimentation tank of a wastewater treatment plant in southern China, based on experimental screening of the optimal pH value, chemical types and concentrations of chemicals, coagulation time, etc., a dynamic dosage prediction feedforward model for chemical phosphorus removal agents in the effluent from the secondary sedimentation tank of the WWTPs was developed to predict the most economical dosage of the chemicals. Meanwhile, combined with the adaptive fuzzy neural network P feedback control algorithm, dynamic real-time control of chemical dosing was achieved. Through micro-control design, a software model for signal collection and feedback in a specific phosphorus removal scenario was formed, and an automatic control system for chemical dosing was ultimately developed for a WWTP in a city in southern China. After stable operation for two months, the system achieved a 100% compliance rate for effluent total phosphorus (TP) concentration and a 67% improvement in effluent stability, helping the wastewater treatment plant achieve stable and precise control of the phosphorus removal process in the secondary sedimentation tank effluent, which is conducive to further promoting its implementation of low-carbon pathways.


Introduction
For a long time, phosphorus has been one of the focal points in wastewater treatment plants (WWTPs).However, phosphorus removal in wastewater is a complex process, involving multiple operational units such as biological tanks and secondary sedimentation tanks [1].This complexity arises from a multitude of influencing variables, making it difficult to achieve desired phosphorus removal outcomes [2].Due to often insufficient biological phosphorus removal efficiency, recent years have seen widespread scholarly attention towards chemically-based methods for controlling effluent total phosphorus [3][4][5][6].These methods primarily involve the addition of metal salts to the aerobic zone to induce particle precipitation, achieving phosphorus removal by discharging excess sludge containing particulate phosphorus [7][8][9].However, the effectiveness of this method is influenced by factors such as pH, temperature, and redox conditions [10,11], as the metal salts added to the wastewater participate in both precipitation and chemical coagulation reactions [12].Consequently, current chemical phosphorus removal in WWTPs often relies heavily on the empirical experience of operators, resulting in excessive dosing of metal coagulants [13].Nevertheless, studies indicate that with increasing doses of metal salts for chemical phosphorus removal, the residual phosphorus concentration in the wastewater gradually decreases, but this relationship is not linear [14,15].Excessive dosage of agents increases sludge production, leading to increased carbon emissions during sludge treatment and disposal processes [14,16].The control of phosphorus removal chemical dosage directly affects whether effluent water quality meets discharge standards and corresponding energy saving and carbon emission reduction, making it one of the urgent research directions in wastewater treatment plants.
With the rapid development of data acquisition techniques and intelligent control technologies in wastewater treatment processes [13], research on intelligent methods for controlling effluent total phosphorus (TP) has been widely conducted [17][18][19].However, many current intelligent control strategies for effluent TP still face issues such as considering limited variables that affect phosphorus removal efficiency and poor phosphorus removal performance [20,21].Therefore, how to design an effective controller, in consideration of both the mechanism of the chemical phosphorus removal process and the comprehensive influencing factors during the process, remains a challenging issue [22].Adaptive control and predictive control are based on the construction of accurate mathematical models for controlled systems, thus the methodology depends heavily on the quality of the simulated system and can only achieve good performance when the model variation is small or the model operates under stable conditions [23,24].Fuzzy control, independent of precise mathematical models, exhibits higher robustness [25].Proportional integral derivative (PID) controllers are the most commonly used controllers in the industry [26], being simple, widely applicable, and providing performance close to optimal [27].However, choosing suitable PID gains for nonlinear systems is still challenging, and traditional PID controllers act poorly with significant time delays [28][29][30].Therefore, an adaptive fuzzy neural network PID controller is proposed in this study.
This paper focuses on the mathematical model of chemical dosing and designs a feedforward and feedback regulation system based on the adaptive PID control theory.An automatic control system for phosphorus removal chemical dosing was developed for a WWTP in a southern city in China.The goal of the system was to predict effluent quality based on real-time online monitoring data, adjust operational parameters promptly, and ultimately achieve fully automatic control of stable effluent TP, promoting the development of urban wastewater treatment plants towards energy-saving and carbon emission reduction.The novelty of the chemical phosphorus removal model combining feedforward and feedback control strategies lies in its integrated use of both control strategies to enhance the system's control accuracy and adaptability.Firstly, the model used in this paper can improve simulation accuracy, the feedforward control can predict and compensate for upcoming changes, while the feedback control can correct errors that have already occurred.When used in combination, they can more precisely control the dosage of chemical reagents.Secondly, the model has strong adaptability.By monitoring data in real-time, the system can promptly respond to changes in water quality, automatically adjust operational parameters, and enhance the system's adaptability and robustness.Moreover, this controller combines the learning capability of neural networks with the reasoning capability of fuzzy logic to handle uncertainty and nonlinearity in the wastewater treatment process.

Overview of the Case WWTP Process
A WWTP in southern China is designed with a capacity of 70,000 m 3 /d and serves an area of 45.36 km 2 and a population of 0.25 million people.The main process adopts a modified Anaerobic-Anoxic-Oxic (AAO) process (as shown in Figure 1).The tertiary treatment includes a high-efficiency sedimentation tank and a cloth-media filter.Polyaluminum chloride (PAC) (Baore Chemical Co., Ltd., Nanjing, China), magnetic powder, and polyacrylamide (PAM) are dosed, with dosing points located at the high-efficiency sedimentation tank.The effluent quality meets the Class A standard of the "Discharge standard of pollutants for municipal wastewater treatment plant" (GB18918-2002) [31].According to the operating data of the WWTPs in the past three years (Table 1), the actual biological phosphorus removal efficiency was 50-55%, and the TP concentration in the effluent of the secondary sedimentation tank fluctuated between 1.2-1.8mg/L.To achieve the final goal of the Class A discharge standard (TP ≤ 0.5 mg/L), the current semi-manual chemical dosing system suffers from unstable pre-biological treatment and requires more advanced control strategies.Currently, only the TP online monitoring equipment (Endress+Hauser China, Shanghai, China) is installed at the influent and effluent points of the plant, lacking process phosphorus monitoring.This inability to grasp the phosphorus fluctuation in the effluent of the secondary sedimentation tank in good time leads to the inability to accurately adjust and control the dosing system.It is preliminarily believed that there is excessive dosing of PAC.

Pilot-Scale Experimental Setup
The pilot-scale high-efficiency sedimentation reactor has four systems, i.e., the coagulation and precipitation system, sludge recirculation system, chemical dosing and control system, and online monitoring and control system (Figure 2).The coagulation and precipitation system is primarily designed based on the existing high-efficiency sedimentation tank (scaled down by 1:1000), with an influent flowrate of 35 m 3 /d.Its internal structure comprises a primary coagulation zone, secondary coagulation zone, flocculation zone, and sedimentation zone.The sludge recirculation system transports a portion of sludge from the bottom of the sludge zone to the coagulation zone using a peristaltic pump (Chongqing Jieheng Peristaltic Pump Co., Ltd., Chongqing, China), while the remaining sludge is discharged externally by another peristaltic pump.The chemical dosing and control system consists of two chemical-dissolving buckets, two gear flow meters (Shanghai Cixi Instrument Co. Ltd., Shanghai, China), two diaphragm metering pumps (NEWDOSE, Beijing, China), and other accessories, e.g., dampers, and back pressure regulators.All the electronic components (devices, instruments, and accessories) are connected to the online monitoring and control system.The online monitoring and control system includes a local power distribution and control cabinet, a remote server and a web/mobile interactive interface.It is able to collect and upload (1) local/remote control status, (2) all the device and instrument working status and alarm signals, (3) influent flowrate and valve opening, (4) influent and effluent phosphate (PO 4 3− ), pH and temperature, (5) chemical dosing flowrate, (6) returned and wasted chemical sludge flowrates, ( 7) stirring speeds of five mixers.Furthermore, it could also remotely set the stirring speeds, flowrates and valve opening, as well as switch on/off the devices and clean faults.Two phosphate analyzers (Shandong Greencare Precision Instrument Co., Ltd., Shandong, China) employ the spectrophotometric determination of phosphate by the molybdenum blue method specified in GB11893-89 [32] and HJ670-2013 [33].The phosphate is automatically sampled and detected every 40 min.

Pilot-Scale Experimental Plan
A series of accompanying pilot-scale experiments were performed by using the actual effluent from the secondary clarifier of the case WWTP.The pilot influent TP ranged from 0.62 to 1.88 mg/L in 2022 and 2023.The concentrated PAC liquid (2.5%) was made by adding 4.17

Laboratory Test for Chemical Selection
In order to test the phosphorus removal performance for four commonly used agents (PAC, FeCl 3 , polyaluminium ferric chloride (PAFC), and polysilicate aluminum ferric (PSAF)), solutions with different mass concentrations (20 mg/L, 40 mg/L, 60 mg/L, 80 mg/L, 120 mg/L, 160 mg/L, and 200 mg/L) were prepared, respectively.The results indicated that: (1) at low concentrations (≤60 mg/L), the phosphorus removal rate is proportional to the dosage concentration; (2) at the same concentration, the phosphorus removal effectiveness is in the order of FeCl 3 , PSAF, PAC, and PAFC.However, due to increased effluent turbidity caused by FeCl 3 and the high price of PSAF, PAC was finally chosen as the phosphorus removal chemical for this study, which is consistent with the phos-phorus removal chemical used in the case WWTP.More details about these experiments can be found in [34].

Determination of the Optimal Dosage for Pilot-Scale Chemical
During the constant dosing stage (II), the effective PAC dosage was gradually increased (4, 6, 8, 10, 12 mg Al 2 O 3 /L), and the influent PO 4 3− concentration (actual effluent from the secondary sedimentation tank) fluctuated between 0.8-1.2mg/L (Figure 3).As the dosing concentration increased, the effluent PO 4 3− concentration gradually decreased, and the phosphate removal amount increased.However, due to the limited height of the pilot reactor, the absence of magnetite powder and PAM, and the lack of a post-filtration device, the increase in suspended solids caused by sludge flotation would affect the effluent PO 4 3− concentration, resulting in slightly lower dosing efficiency of the pilot reactor compared to the actual tank.To achieve the Class A standard for effluent TP, the dosage concentration of the pilot reactor needs to reach 8-10 mg Al 2 O 3 /L.With the stepwise increase in the dosing concentrations, the effluent PO 4 3− concentrations varied from 0.6 to 0.2 mg P/L.During the whole experimental period, the influent pH was maintained between 6.24~7.24,and the effluent pH was maintained between 6.21~7.27without pH adjustment.Al 2 (OH) The dosage of PAC is mainly influenced by wastewater components, the relative concentration of metal salts and phosphate ions, and the type of phosphate ions, pH, and other ligands such as sulfates, carbonates, fluorides, and organic matter.When the Al/P molar ratio is slightly higher than the stoichiometric coefficient, the dosage is linearly related to the effluent PO 4 3− concentration.However, when the Al/P molar ratio is far higher than the stoichiometric coefficient, excessive aluminum could form aluminum hydroxide precipitate at the same time.If pH is not corrected in advance, increasing the dosage of metal salt coagulants will further lower the pH of the sewage, forming soluble complexes such as AlH 2 PO 4 2+ , and thus leading to a rapid increase in PO 4 3− concentration after an initial decrease.
In the previous studies, the commonly used empirical formulas to describe the relationship between dosage and PO 4 3− concentration are mostly investigated under relatively high effluent PO 4 3− concentrations, rather than under low effluent PO 4 3− concentrations.The empirical formulas that solely consider chemical precipitation will significantly underestimate the total chemical dosage, especially when the effluent PO 4 3− concentration is relatively low.However, although both the adsorption mechanism and chemical precipitation mechanism are considered, the above-mentioned mechanisms could not be differentiated from other processes such as ion exchange, surface complexation of phosphates and metal hydroxide colloids.Furthermore, if PAC is overdosed, the mechanism of the reaction would change and further lead to a decrease in the model accuracy.
During this study, the pH range of the influent and effluent was relatively stable and within the optimal pH range for aluminum coagulant-based phosphorus removal.Therefore, the influence of pH could be ignored and the relationship between phosphate removal and dosage concentration is established as shown in Figure 4.The original dosage model (Equation (2)) adjusts the dosage based on the influent flowrate at a certain dosage concentration.It enables timely adjustments of the dosage amount according to the changes in the influent flowrate, making it a relatively simple and direct feedforward control method.However, if the influent PO 4 3− concentration varies in a wider range, a fixed value for the dosage rate could not react sufficiently and needs to be adjusted based on experience and expertise.Further modifications are needed to decide the dosage concentration C to work under more comprehensive conditions.
where: q c represents the instantaneous flowrate of the coagulant, measured in mL/h; Q represents the influent flowrate, measured in L/h; C represents the dosage concentration of the coagulant in water, measured in g/m 3 ; ρ represents the density of the coagulant, which is 1000 kg/m 3 ; w c represents the effective content of the coagulant, which is 2.5%.
Based on the relationship between the dosage concentration C and the phosphate removal Figure 4, the following equation is established: Finally, the feedforward equation is established as follows: where: P i represents the inflow PO 4 3− concentration, measured in g/m 3 ; P eset represents the setpoint value of the effluent PO 4 3− concentration, measured in g/m 3 .

Adaptive Fuzzy Neural Network P Feedback Controller
In order to achieve precise control of effluent PO 43− under complex environmental conditions and ensure stable and safe compliance with effluent TP standards, a new adaptive fuzzy neural network P feedback control system is developed (Figure 5).The proposed controller comprises a neural network and fuzzy feedback control.The neural network uses an adaptive algorithm to tune the dosing rules in the fuzzy interface.The fuzzy interface utilized a Mamdani-type fuzzy controller as the core controller.In the Mamdani-fuzzy controller, the trigonometric functions are used as membership functions, and error (e) and error rate (ec) are controller inputs.Fuzzy reasoning is employed to infer the correction amount for the P controller parameter ∆K P (proportional gain).
The neural network was employed to tune the dosing rules of the phosphorus removal agent (shape of membership functions), i.e., the center points of the membership functions, width vectors, and connection weights of the output layer.This system combines the learning capability of neural networks with the reasoning capability of fuzzy logic, enabling better handling of uncertainty and nonlinearity.Through this system, controller parameters can be dynamically adjusted based on real-time and historical data to adapt to continuously changing environmental conditions, achieving precise control of effluent TP.

System Design
The system architecture is an advanced wastewater treatment solution that integrates real-time monitoring, data analysis, autonomous learning, and intelligent control, focusing on efficiently removing phosphorus from wastewater (Figure 6).By deploying various monitoring devices, the system collects key parameters in real-time, such as the influent flowrates, influent and effluent PO 4 3− for feedforward and feedback control, and utilizes the cloud server for data processing and model analysis.The intelligent control system adjusts the dosage of chemicals every minute through dosing pumps with frequency converter based on the results of data analysis, optimizing both biological phosphorus removal and chemical phosphorus removal processes.The whole system covers the entire process from AAO biological tanks to disinfection, ensuring the efficiency and stability of wastewater treatment.Additionally, it possesses autonomous learning capabilities to adapt to different operating conditions and changes in water quality, thereby contributing to environmental protection.

Implementation of Application Interfaces
The system, developed using C#, encompasses a comprehensive suite of features that cater to the needs of modern WWTPs.It includes both web and mobile interfaces that provide a range of functionalities such as displaying key monitoring indicators, alerting users to equipment malfunctions, enabling remote control, and offering data analysis capabilities.The following is a breakdown of the system's components and their roles: Step 1 Initialization of configuration files Set up the necessary configuration settings that the system requires to operate.This includes parameters for device communication, user access, and system preferences.
Step 2. Initialization of database Prepare the database for storing and retrieving data.This is crucial for maintaining records of operational metrics, system logs, and historical data for analysis.
Step 3. Initialization of WebSocket (WS) and Message Queuing Telemetry Transport (MQTT) task processors These protocols are used for real-time, bi-directional communication between the server and clients.WS is often used for web applications, while MQTT is a lightweight messaging protocol ideal for IoT devices.
Step 4. Starting MQTT server The MQTT server is launched to handle the publish/subscribe messaging pattern, allowing the system to efficiently distribute messages to different parts of the infrastructure.
Step 5. Starting WS server The WS server is initiated to provide a full-duplex communication channel over a single long-lived connection, which is particularly useful for real-time data transmission.
Step 6. Starting HTTP server The HTTP server is started to manage web requests and responses, allowing users to interact with the system via web browsers.
Step 7. Alarm data change notifications The system is designed to alert users when there are significant changes in alarm data, such as critical equipment failures or breaches in operational parameters.
Step 8. Real-time monitoring of key indicators Users can view real-time data for various operational indicators, providing immediate insights into the plant's performance.
Step 9. Real-time value upload for indicators The system supports the continuous upload of real-time values for the monitored indicators, ensuring that the latest data are always available for analysis.
Step 10.Remote control Allows users to remotely control equipment and processes within the plant, enabling adjustments to be made from a distance.
Step 11.Control reply After a remote control command is issued, the system provides feedback to confirm the execution of the command and to report any status changes.

Implementation of an Upper Computer Program
The system, implemented in Python 3.7, includes a variety of intelligent control and data management functions, specifically: Step 1. Local control Allows the system to directly control devices within the local network, reducing latency and improving response speed.
Step 2. Remote data upload The switch and analog data obtained from the device can be uploaded remotely to a central database for centralized management and analysis.
Step 3. Remote control Enables control of the device over the internet or a dedicated network, without geographical limitations.
Step 4. Automatic chemical dosing algorithm The system automatically adjusts the amount of chemicals added based on real-time data, optimizing the treatment process for improved efficiency and accuracy.
Key components and workflow of the system are as follows: Step 1. Modbus RTU connection: Establishes a connection with local devices via the Modbus RTU protocol for real-time monitoring and control.
Step 2. Data acquisition and device control: After obtaining switch and analog data from the device, the system can perform corresponding control operations.
Step 3. Database storage: The acquired device data are stored in a database for historical records, trend analysis, and fault diagnosis.
Step 4. Scheduled data upload: The system automatically uploads data every full hour to ensure continuity and completeness of the data.
Step Step 6. Automatic chemical dosing calculation The system runs the automatic chemical dosing algorithm on a separate thread, calculating and adjusting the amount of chemicals added based on real-time monitoring data, achieving automatic control.

Implementation of Dosing Algorithm Program
In the feedforward control stage, the algorithm utilizes real-time data monitoring to predict and adjust the dosage in advance to anticipate changes in water quality.The feedforward algorithms could be switched based on whether the following data could be acquired and trusted, including the influent flowrate, influent and effluent TP or PO 4 3− concentrations.Additionally, the system can calculate the treatment capacity of the reagents in real time and dynamically adjust the dosage according to actual conditions to achieve optimal phosphorus removal performance.
In the feedback control stage, the algorithm sets multiple control objectives and corresponding proportional gain variations (∆Kp) based on fuzzy logic control, which are used to implement graded feedback control according to different treatment stages.
In this system (Figure 7), besides precise operations in the feedforward and feedback control stages, neural network technology is introduced to optimize fuzzy logic control rules, further enhancing phosphorus removal efficiency.During the training process, the neural network continuously adjusts the weights and biases in the network through forward and backward propagation algorithms to minimize the error between the actual output and the desired output.Through this learning process, the neural network can automatically adjust key parameters such as the proportional gain variation (∆Kp) and membership functions in the fuzzy controller to adapt to changing water quality conditions and treatment requirements.

Results of Intelligent Phosphorus Removal Operation with Automatic Dosing
Comparison before and after the implementation of intelligent control algorithms indicates that despite a gradual increase in influent PO 4 3− concentration from 0.8 mg/L to approximately 1.2 mg/L, the stability of effluent has improved (Figure 8).Previously, the effluent PO 4 3− concentration fluctuated between 0.3-0.6 mg/L, mainly due to semi-manual operations, which lacked sufficient response to real-time changes in influent conditions.After the implementation of intelligent control algorithms, the fluctuation range was narrowed to between 0.4-0.5 mg/L.The dosage can be dynamically adjusted based on real-time data, resulting in more precise and efficient phosphorus removal, with a stability improvement of 67%.

Conclusions
(1) At low concentrations (≤60 mg/L), the phosphorus removal efficiency of the four phosphorus removal chemicals is in the following order: FeCl 3 , PSAF, PAC, and PAFC.(2) The mathematical chemical dosing model for phosphorus removal in the high-efficiency sedimentation tank is as follows: the feedforward dosage is a function of the influent flowrate and the effluent TP from the secondary sedimentation tank.Additionally, the effluent TP is continuously monitored and used as feedback to adjust the dosage of the chemicals in real time to ensure stable compliance.(3) To ensure compliance with effluent standards, traditional dosing methods of phosphorus removal chemicals are relatively fixed and conservative.With the implementation of an automatic control system, dosing can be adjusted more accurately and flexibly in real-time according to changes in influent water quality and quantity.It is estimated that this can improve effluent stability by 67%.(4) Automatic control of phosphorus removal chemicals is easily achievable through modifications in actual production operations.Moreover, due to its favorable economic effects, it is worth promoting.

Figure 1 .
Figure 1.Process flow diagram of the case WWTP.

Figure 2 .
Figure 2. High-efficiency sedimentation tank, (a) cross-sectional view, (b) photo of the pilot set.
kg of PAC solid powder (30%) into the 50 L bucker with a stirring speed of 70 r/min.During the experimental period, only PAC was used as the phosphorus removal agent, without the addition of magnetite powder and PAM.The experiments are divided into four stages: (1) trial operation stage (I), (2) constant dosing stage (II), (3) feedforward dosing stage (III), and (4) adaptive feedforward-feedback dosing stage (IV).

Figure 3 .
Figure 3. Performance of the pilot-scale setup at different dosing concentrations.4.Feedforward-Feedback Compound Control Model for Phosphorus Removal Agent Dosage 4.1.Feedforward Dosage Model When the phosphorus removal agent is PAC (Al n (OH) m Cl 3n−m , with effective substance calculated as Al 2 O 3 ), the reaction between PAC and PO 4 3− is described as follows [35]: Al 2 (OH) 2+ 4 + H n PO

Figure 4 .
Figure 4. Effects of PAC dosage concentration on phosphorus removal performance.

Figure 5 .
Figure 5. Adaptive fuzzy neural network P feedback control system structure for chemical phosphorus removal.

Figure 6 .
Figure 6.Chemical phosphorus removal intelligent control design structure.

5 .
Remote monitoring program -Initializes MQTT client: Sets up the MQTT protocol client for communication with remote devices or servers.-Sets Connection information: Configures connection parameters for the MQTT client, such as server address, port, and client ID. -Subscribes on connection: Automatically subscribes to relevant topics upon successful connection to receive control messages.-Parses information and controls devices: Parses receive information and execute corresponding device control commands based on the parsed results.

Figure 8 .
Figure 8.Comparison between semi-manual and intelligent automatic dosing.