Establishing a Smart Farm-Scale Piggery Wastewater Treatment System with the Internet of Things (IoT) Applications

: The conventional piggery wastewater treatment system is mainly a manual operation system which may be well managed by experienced technicians. However, the pig farmers must simultaneously manage their pig production as well as their on-farm wastewater treatment facility. For this study, Internet of Things (IoT) applications were introduced on a 1000-pig farm to establish a smart piggery wastewater treatment system, which was upgraded from a self-developed fully automatic wastewater treatment system. Results showed that the removal e ﬃ ciency of biochemical oxygen demand (BOD), chemical oxygen demand (COD), and suspended solids (SS) of the piggery wastewater based on the sensor data before and after water quality sensor calibration were 89%, 94%, and 93%, and 94%, 86%, and 96%, respectively. Moreover, the removal e ﬃ ciency of BOD, COD, and SS of the piggery wastewater based on the analytical chemical data before and after water quality sensor calibration were 93%, 89%, and 97%, and 94%, 86%, and 96%, respectively. Experimental results showed that overall removal e ﬃ ciency of BOD, COD, and SS of the piggery wastewater after water quality sensor calibration were 94%, 86–87%, and 96%, respectively. Results revealed that the farm-scale smart piggery wastewater treatment system was feasible to be applied and extended to more commercial pig farms for establishing sustainable pig farming.


Introduction
To ensure world food security by 2050, livestock food, e.g., meat, egg, and milk, production must be increased by 70% in 10 years. The approach of decreasing the number of livestock farms, increasing farm-scale, and mitigating environmental impact is necessary [1]. Thus, a concept of precision livestock farming (PLF) is introduced and carried out gradually. The primary concept of PLF is providing an on-line monitoring and management system according to animal welfare guidelines and promoting livestock production efficiency [1]. Besides the online monitoring and management system of PLF, the livestock wastewater treatment system with automation has been developed since 1995 in Taiwan [2]. Piggery wastewater, i.e., a mixture of manure, urine, and clean water, must be well treated to meet the effluent limit of environmental protection agency (EPA) in Taiwan. The key facility of the piggery wastewater treatment system is a farm-scale sequencing batch reactor (SBR) controlled by a traditional timer or programmable logic controller (PLC) [2][3][4]. The full-scale demonstration sites include 500-2000 heads pig farms, a 200-head dairy farm, and the experimental livestock farm of National Taiwan University (NTU).

Design of a Piggery Wastewater Treatment System on a Selected Pig Farm
The selected commercial pig farm, about 1000 pigs on the farm, was located in I-Lan County, Taiwan (available online: https://www.facebook.com/iyangranch/; accessed on 29 May 2020). The estimated daily wastewater was 30 m 3 /day (30 L/pig/day × 1000 pigs ×10 −3 m 3 /L), but the actual daily wastewater was about 48 m 3 /day (i.e., most rainwater was mixed with raw wastewater on the farm). A newly designed and constructed wastewater treatment system was constituted of raw wastewater pig, primary clarifier, anaerobic digesters, adjustment basin, sequencing batch reactor (SBR), effluent basin, and sludge storage basin. Some basins were constructed underground (length × width × water depth) such as raw wastewater pit (1.8 m × 1.8 m × 4 m), adjustment basin (6.1 m × 2.7 m × 4.5 m), effluent basin (5.7 m × 2 m × 4.5 m), and sludge storage basin (5.7 m × 6.1 m × 4.5 m). The others were constructed above ground (length × width × water depth), about 5 m in height, such as primary clarifier (5.7 m × 2 m × 4.5 m), anaerobic digesters (4 m × 2.7 m × 4.5 m for each digester), and SBR (6.1 m × 2.7 m × 4.5 m). A flowchart of the newly constructed wastewater treatment system is shown in Figure 1. The appearance of the wastewater treatment system and PLC panel box with a human-machine interface (HMI) are shown in Figures 2 and 3, respectively. The hydraulic retention time (HRT) of the raw wastewater pit, primary clarifier, digesters, adjustment basin, SBR, and sludge storage basin was 0.3, 1.1, 8.1, 1.5, 1.5, and 3.3 days, respectively. The SBR was operated by a 5-HP root blower under an alternative aeration process to ensure energy saving of aeration as well as ammonium removal enhancement of the treatment process [2][3][4]9].
Water 2020, 12, x FOR PEER REVIEW 3 of 14

Design of a Piggery Wastewater Treatment System on a Selected Pig Farm
The selected commercial pig farm, about 1000 pigs on the farm, was located in I-Lan County, Taiwan (available online: https://www.facebook.com/iyangranch/; accessed on 29 May 2020). The estimated daily wastewater was 30 m 3 /day (30 L/pig/day × 1000 pigs ×10 −3 m 3 /L), but the actual daily wastewater was about 48 m 3 /day (i.e., most rainwater was mixed with raw wastewater on the farm). A newly designed and constructed wastewater treatment system was constituted of raw wastewater pig, primary clarifier, anaerobic digesters, adjustment basin, sequencing batch reactor (SBR), effluent basin, and sludge storage basin. Some basins were constructed underground (length × width × water depth) such as raw wastewater pit (1.8 m × 1.8 m × 4 m), adjustment basin (6.1 m × 2.7 m × 4.5 m), effluent basin (5.7 m × 2 m × 4.5 m), and sludge storage basin (5.7 m × 6.1 m × 4.5 m). The others were constructed above ground (length × width × water depth), about 5 m in height, such as primary clarifier (5.7 m × 2 m × 4.5 m), anaerobic digesters (4 m × 2.7 m × 4.5 m for each digester), and SBR (6.1 m × 2.7 m × 4.5 m). A flowchart of the newly constructed wastewater treatment system is shown in Figure 1. The appearance of the wastewater treatment system and PLC panel box with a humanmachine interface (HMI) are shown in Figures 2 and 3, respectively. The hydraulic retention time (HRT) of the raw wastewater pit, primary clarifier, digesters, adjustment basin, SBR, and sludge storage basin was 0.3, 1.1, 8.1, 1.5, 1.5, and 3.3 days, respectively. The SBR was operated by a 5-HP root blower under an alternative aeration process to ensure energy saving of aeration as well as ammonium removal enhancement of the treatment process [2][3][4]9].

Automatic Control Mode of Piggery Wastewater Treatment System
The daily cleaning periods of pig pens were at 09:00-11:00 and 14:00-16:30. Daily piggery wastewater volume was 48 m 3 /day, and the available volume of the SBR was 74 m 3 (i.e., 6.1 m × 2.7 m × 4.5 m; L × W × water depth). The daily discharging volume of effluent was 48 m 3 in 15 min by a 4" poly vinyl chloride (PVC) motor-operated valve. Thus, the same volume of influent, 48 m 3 , was pumped into the SBR daily from the adjustment basin. The process of the whole piggery wastewater system was controlled by a programmable logic controller (PLC) with an HMI as follows: Pig houses → Raw wastewater pit (water level controlled with a water pump) → Solid/liquid separator → Primary clarifier (overflow) → Anaerobic digester #1 (overflow) → Anaerobic digester #2 (overflow) → Anaerobic digester #3 (overflow) → Anaerobic digester #4 (overflow) → Anaerobic digester #5 (overflow) → Anaerobic digester #6 (overflow) → Anaerobic digester #7 (overflow) → Anaerobic digester #8 (overflow) → Adjustment basin (PLC controlled with a water pump) → SBR → Effluent basin → Effluent discharge. The effluent was discharged twice a day from the effluent basin. Thus, the influent was introduced constantly into the system. Moreover, the SBR operation mode is shown in Table 1.

Automatic Control Mode of Piggery Wastewater Treatment System
The daily cleaning periods of pig pens were at 09:00-11:00 and 14:00-16:30. Daily piggery wastewater volume was 48 m 3 /day, and the available volume of the SBR was 74 m 3 (i.e., 6.1 m × 2.7 m × 4.5 m; L × W × water depth). The daily discharging volume of effluent was 48 m 3 in 15 min by a 4" poly vinyl chloride (PVC) motor-operated valve. Thus, the same volume of influent, 48 m 3 , was pumped into the SBR daily from the adjustment basin. The process of the whole piggery wastewater system was controlled by a programmable logic controller (PLC) with an HMI as follows: Pig houses → Raw wastewater pit (water level controlled with a water pump) → Solid/liquid separator → Primary clarifier (overflow) → Anaerobic digester #1 (overflow) → Anaerobic digester #2 (overflow) → Anaerobic digester #3 (overflow) → Anaerobic digester #4 (overflow) → Anaerobic digester #5 (overflow) → Anaerobic digester #6 (overflow) → Anaerobic digester #7 (overflow) → Anaerobic digester #8 (overflow) → Adjustment basin (PLC controlled with a water pump) → SBR → Effluent basin → Effluent discharge. The effluent was discharged twice a day from the effluent basin. Thus, the influent was introduced constantly into the system. Moreover, the SBR operation mode is shown in Table 1.
The effluent was discharged twice a day from the effluent basin. Thus, the influent was introduced constantly into the system. Moreover, the SBR operation mode is shown in Table 1.
The multi-parameter recorder and the BOD/COD sensors were then connected to a wireless controller and data logger (PRO Controller, AQUAS Inc., Taipei, Taiwan) through an RS485 Modbus remote terminal unit (RTU), and all data of the sensors were transmitted by the wireless controller and data logger to a remote server placed in the research office of Dept. of Animal Science and Technology, National University (AST/NTU) through either cable or wireless internet. The wireless controller and data logger were solar-powered for data collection, communication, logging, alarming, control, and analysis applications ( Figures 5 and 6).  The multi-parameter recorder and the BOD/COD sensors were then connected to a wireless controller and data logger (PRO Controller, AQUAS Inc., Taipei, Taiwan) through an RS485 Modbus remote terminal unit (RTU), and all data of the sensors were transmitted by the wireless controller and data logger to a remote server placed in the research office of Dept. of Animal Science and Technology, Water 2020, 12, 1654 6 of 13 National University (AST/NTU) through either cable or wireless internet. The wireless controller and data logger were solar-powered for data collection, communication, logging, alarming, control, and analysis applications (Figures 5 and 6).     All data can be analyzed and piloted through the webserver software of AQWEB (AQUAS Inc., Taipei, Taiwan) (available online: http://140.112.84.78; accessed on 27 May 2020). All related researchers can monitor and remote-control the data and operation through browsers of office computers or mobile phones such as internet explorer (IE), Safari, and apps of android or iOS (Figures 7 and 8). The flowchart of the whole wastewater treatment system can be seen in the AQWEB software, and the manager can intervene in the routine operation of wastewater treatment from a remote office. For remote control of in situ machines, digital signals were transmitted to the PLC through a digital input/digital output (DI/DO) module. The operation conditions were feedbacked to the PLC and then transmitted to the remote server also through DI/DO module. All machines were operated under the PLC control with the relay and actuator. All sensor data were collected from 21 March 2019 to 20 April 2020. All data can be analyzed and piloted through the webserver software of AQWEB (AQUAS Inc., Taipei, Taiwan) (available online: http://140.112.84.78; accessed on 27 May 2020). All related researchers can monitor and remote-control the data and operation through browsers of office computers or mobile phones such as internet explorer (IE), Safari, and apps of android or iOS ( Figures  7 and 8). The flowchart of the whole wastewater treatment system can be seen in the AQWEB software, and the manager can intervene in the routine operation of wastewater treatment from a remote office. For remote control of in situ machines, digital signals were transmitted to the PLC through a digital input/digital output (DI/DO) module. The operation conditions were feedbacked to the PLC and then transmitted to the remote server also through DI/DO module. All machines were operated under the PLC control with the relay and actuator. All sensor data were collected from 21 March 2019 to 20 April 2020.

Calibration of Water Quality Sensors
The DO, pH, temperature, and EC sensors were calibrated by a senior technician of the AQUAS Inc. followed by their instrumental computer program and compared with the data of the portable DO, pH, temperature, and EC meters on site. However, the sensibility of the BOD, COD, and SS sensors were calibrated based on the chemical analyzed data of the same wastewater samples. For the SS sensor, the analytical chemical data of the same wastewater samples were very close to the sensor data. Thus, only the sensibility of the BOD and COD sensors was calibrated by the chemical analyzed data of the same wastewater samples. Calibration curves of BOD and COD were prepared by plotting the analytical chemical data against the sensor data of the same wastewater samples. The calibration curves of the COD (y = 1.57x − 149.31, R 2 = 0.9401) and BOD (y = 0.24x + 29.10, R 2 = 0.9797) were established based on four sets of the effluent data before sensor calibration in Table 2. The yaxis was analytic chemical data, and the x-axis was the sensor data. The BOD and COD sensors were All data can be analyzed and piloted through the webserver software of AQWEB (AQUAS Inc., Taipei, Taiwan) (available online: http://140.112.84.78; accessed on 27 May 2020). All related researchers can monitor and remote-control the data and operation through browsers of office computers or mobile phones such as internet explorer (IE), Safari, and apps of android or iOS ( Figures  7 and 8). The flowchart of the whole wastewater treatment system can be seen in the AQWEB software, and the manager can intervene in the routine operation of wastewater treatment from a remote office. For remote control of in situ machines, digital signals were transmitted to the PLC through a digital input/digital output (DI/DO) module. The operation conditions were feedbacked to the PLC and then transmitted to the remote server also through DI/DO module. All machines were operated under the PLC control with the relay and actuator. All sensor data were collected from 21 March 2019 to 20 April 2020.

Calibration of Water Quality Sensors
The DO, pH, temperature, and EC sensors were calibrated by a senior technician of the AQUAS Inc. followed by their instrumental computer program and compared with the data of the portable DO, pH, temperature, and EC meters on site. However, the sensibility of the BOD, COD, and SS sensors were calibrated based on the chemical analyzed data of the same wastewater samples. For the SS sensor, the analytical chemical data of the same wastewater samples were very close to the sensor data. Thus, only the sensibility of the BOD and COD sensors was calibrated by the chemical analyzed data of the same wastewater samples. Calibration curves of BOD and COD were prepared by plotting the analytical chemical data against the sensor data of the same wastewater samples. The calibration curves of the COD (y = 1.57x − 149.31, R 2 = 0.9401) and BOD (y = 0.24x + 29.10, R 2 = 0.9797) were established based on four sets of the effluent data before sensor calibration in Table 2. The y-

Calibration of Water Quality Sensors
The DO, pH, temperature, and EC sensors were calibrated by a senior technician of the AQUAS Inc. followed by their instrumental computer program and compared with the data of the portable DO, pH, temperature, and EC meters on site. However, the sensibility of the BOD, COD, and SS sensors were calibrated based on the chemical analyzed data of the same wastewater samples. For the SS sensor, the analytical chemical data of the same wastewater samples were very close to the sensor data. Thus, only the sensibility of the BOD and COD sensors was calibrated by the chemical analyzed data of the same wastewater samples. Calibration curves of BOD and COD were prepared by plotting the analytical chemical data against the sensor data of the same wastewater samples. The calibration curves of the COD (y = 1.57x − 149.31, R 2 = 0.9401) and BOD (y = 0.24x + 29.10, R 2 = 0.9797) were established based on four sets of the effluent data before sensor calibration in Table 2. The y-axis was analytic chemical data, and the x-axis was the sensor data. The BOD and COD sensors were calibrated based on the calibration curves and the related wastewater samples with special devices in the laboratory of AQUAS Inc.

Analysis of Water Quality
Wastewater samples were analyzed for COD, BOD, and SS using standard methods [18]. Wastewater samples were filtered and the filtrates were analyzed for anions and cations by ion chromatography (or ion-exchange chromatography) (Metrohn ion analysis; Metrohn AG, Herisau, Switzerland) [9]. Electrical conductivity and the pH of water samples were determined by a pH/conductivity meter (ExStik EC500, EXTECH Instrument, FLIR Commercial Systems, Goleta, CA, USA). Dissolved oxygen of water samples was determined by a DO meter (WalkLAB, Trans Instruments PTE, Ltd., Singapore).

Statistical Analysis
One-way ANOVA analysis was performed using Origin 9.1 software (OriginLab, Northampton, MA, USA) to compare the results using Tukey's test with a significance level of 0.05.

The Efficiency of Piggery Wastewater Treatment Based on the Analytical Chemical Data
The BOD, COD, SS, pH, and EC of the raw piggery wastewater were 1127 ± 178 mg/L, 4077 ± 21 mg/L, 3676 ± 166 mg/L, 7.3 ± 0.3, and 2597 ± 614 µS/cm, respectively (Table 3). After solid/liquid separation, the BOD, COD, SS, pH, and EC of the piggery wastewater were 492 ± 112 mg/L, 858 ± 242 mg/L, 978 ± 18 mg/L, 7.0 ± 0.6, and 2498 ± 540 µS/cm, respectively. Moreover, the BOD, COD, SS, pH, and EC of the effluent were 70 ± 17 mg/L, 523 ± 121 mg/L, 140 ± 34 mg/L, 8.0 ± 0.4, and 2411 ± 579 µS/cm, respectively, when the average MLSS of the SBR system was 2013 ± 1040 mg/L. Thus, the overall removal efficiencies of the BOD, COD, and SS of the piggery wastewater based on only the analytical chemical data were 94%, 87%, and 96%, respectively (Table 3). For characterizations of EC in the effluent, the analytical data of the cations and anions in the effluent are shown in Table 4. Results showed that there was no significant difference among the concentrations of the same cations or anions (p > 0.05). Table 3. Overall analytical chemical data of the wastewater quality indexes in water samples (n = 201). Data presented as mean ± SD. n = sample size. NA: not available. Data presented as mean ± SD. n = sample size.

The Efficiency of Piggery Wastewater Treatment Based on the Water Quality Sensors
For the SBR system, the DO, MLSS, and pH of sensor data before and after sensor calibration were 2.50 ± 0.01 mg/L, 1089 ± 530 mg/L, 8.03 ± 0.73 and 2.00 ± 0.68 mg/L, 2760 ± 653 mg/L, 7.73 ± 0.73, respectively (Table 5). However, the MLSS and pH of analytical data before and after sensor calibration were 885 ± 56 mg/L, and 7.76 ± 0.28, and 2891 ± 211 mg/L and 7.84 ± 0.19, respectively (Table 5). Statistical analysis results of MLSS showed that there was a significant difference between the sensor data and analytical chemical data before sensor calibration (p < 0.05). However, the statistical analysis results of MLSS showed that there was no significant difference between the sensor data and analytical chemical data after sensor calibration (p > 0.05).
For the data of effluent, the BOD, COD, and SS of sensor data and analytical data before sensor calibration were 128 ± 73 mg/L, 245 ± 183 mg/L, and 228 ± 206 mg/L, and 79 ± 24 mg/L, 448 ± 187 mg/L, and 121 ± 52 mg/L, respectively (Table 2). However, the BOD, COD, and SS of sensor data and analytical data after sensor calibration were 69 ± 9 mg/L, 575 ± 46 mg/L, and 146 ± 16 mg/L, and 66 ± 16 mg/L, 563 ± 25 mg/L, and 149 ± 15 mg/L, respectively ( Table 2). Statistical analysis results of BOD, COD, SS, and EC showed that there was a significant difference between the sensor data and analytical chemical data before sensor calibration (p < 0.05). However, the statistical analysis results of BOD, COD, SS, and EC showed that there was no significant difference between the sensor data and analytical chemical data after sensor calibration (p > 0.05). The removal efficiencies of BOD, COD, and SS of the piggery wastewater based on the sensor data before and after water quality sensor calibration were 89%, 94%, and 93%, and 94%, 86%, and 96%, respectively (Table 6). Moreover, the removal efficiencies of BOD, COD, and SS of the piggery wastewater based on the analytical chemical data before and after water quality sensor calibration were 93%, 89%, and 97%, and 94%, 86%, and 96%, respectively ( Table 7). The reduced COD removal efficiency in Table 7 was due to the differences in the uncorrected sensor data and chemically analyzed data before sensor calibration. Experimental results showed that overall removal efficiency of BOD, COD, and SS of the piggery wastewater after water quality sensor calibration were 94%, 86-87%, and 96%, respectively (Table 3, Table 6, and Table 7). Therefore, results revealed that the feasibility of applying smart piggery wastewater treatment systems for in situ wastewater treatment on commercial pig farms. Table 6. Removal efficiency of BOD, COD, and SS of the piggery wastewater based on the sensor data.

Set-Up Remote Monitoring Alarm and Feedback Control
The AQWEB system was developed by applying supervisory control and data acquisition (SCADA) in coordination with a PLC of an automatic sewage treatment system. The alarm limit values of all water quality indexes were set up before regular operation; that is, the SS alarm will be turned on and transmitted to the manager by email or short message of the mobile phone when the effluent SS sensor data were higher than the SS limit values simultaneously. And the sludge pump inside the effluent basin will be turned on to clean up the sediment of the effluent basin in the meantime.
The MLSS limit values of the SBR could be used to control daily discharge volumes of anaerobic sludge from anaerobic digesters to maintain the optimal concentration of activated sludge in the SBR system. Remote control commands interrupting the on-site manual operation process also were designed in the AQWEB system for the whole wastewater treatment process.

Reducing Daily Wastewater Volume, Increasing Hydraulic Retention Time (HRT), and Maintaining Mesophilic Conditions of Wastewater Treatment Basins
The average rainwater volume of I-Lan County was about 67-515 mm/month in 2019 (https: //www.cwb.gov.tw/V8/C/D/DailyPrecipitation.html; accessed on 29 May 2020). Thus, the pig farmer stops pumping raw wastewater into the wastewater treatment system when it is in typhoon invasion day. The system cannot calculate the water balance and mass balance; however, it will be connected with the data of the extra water flowmeters installed before the raw wastewater pit for measuring the volumes of wastewater and rainwater. So far, the system only controls the constant influent volume and measures the volume of effluent.
Besides, for the promotion of the SBR operation, separation of rainwater and wastewater on-farm was a key issue to increase the HRT of anaerobic digesters and SBR. Thus, the construction of separate and individual drainage pipelines for rainwater and piggery wastewater can promote the efficiency of the smart piggery wastewater treatment system. Some wastewater heating systems were introduced and installed inside the anaerobic digesters through hot water recirculation tubing for heating the wastewater inside the digesters in winter to keep stable biogas production under mesophilic conditions.

The Advantages and Disadvantages of the Smart Piggery Wastewater Treatment System
The traditional piggery wastewater treatment system applied the plug flow model for the digesters and activated sludge basins after solid/liquid separation of raw wastewater. The return sludge process has to be manually operated to keep the optimal operation of an activated sludge system. However, most pig farmers lack professional knowledge to manage their wastewater treatment system properly. In contrast, the smart piggery wastewater treatment system has advantages such as labor-saving, accurate operation, being capable of remote monitoring/control, high efficiency, and controlling pollution problems by the administration or government. However, it has some disadvantages such as higher maintenance cost of electrical parts including water quality sensors, corrosion problems of electrical parts on-farm, the difficulty of self-maintaining the whole smart system by the farm owners, being highly dependent on the system dealers, highly electricity-dependent operation, highly computer-dependent operation (need to prevent an invasion of computer virus infection), and so on. To achieve the balance between economic feasibility and technical feasibility of the new system, small-and medium-scale pig farms need to establish a fully automatic piggery wastewater system, i.e., no water quality sensors installed as well as the AQWEB. However, large-scale pig farms need to establish a smart wastewater treatment system.

Conclusions
The on-farm results of this study showed high removal efficiency of BOD, COD, and SS of the piggery wastewater by the smart piggery wastewater treatment system on a 1000-head pig farm. Experimental results showed that overall removal efficiency of BOD, COD, and SS of the piggery wastewater after water quality sensor calibration were 94%, 86-87%, and 96%, respectively. The data of calibrated water quality sensors were close to the data of chemical analysis; thus, the smart system seemed to be able to extend to more large-scale commercial pig farms. However, more behavior data of the system will be collected and analyzed continuously for advanced improvement. Moreover, to promise global food security and mitigate environmental impact, promotion of the smart or automatic piggery wastewater treatment system may help pig farming to promote their environment-friendly image and the substantial value of sustainable pig farming.