Water Treatment Plant Prototype with pH Control Modeled on Fuzzy Logic for Removing Arsenic Using Fe(VI) and Fe(III)

: This study proposes a fuzzy control strategy embedded in a Siemens IoT2040 gateway developed for removing inorganic arsenic from synthetic underground water in a treatment plant prototype. The prototype is used to dose a constant ﬂow of Fe(VI) to maintain an oxide-reduction potential to guarantee the oxidation of arsenite into arsenate, while the fuzzy logic embedded in the IoT control manages the addition of Fe(III) to achieve a proper pH adjustment and e ﬃ cient arsenate removal. The tests used synthetic Bangladesh groundwater enriched with 200 µ g / L of arsenite and 200 µ g / L of arsenate. The results revealed that the plant prototype yielded an e ﬀ ective treatment of the water. Arsenate was decreased to an average value of 6.66 µ g / L and, the arsenite concentration decreased to 1.01 µ g / L or less. These values were lower than the limit of 10 µ g / L deemed by the World Health Organization as safe for human consumption.


Introduction
Water shortage on the Peruvian coast is a major problem for the 20 million people who live there; they only receive fresh rainwater during the three summer months each year, which is not enough to fill the large reservoirs in the most important cities. For this reason, it is essential to obtain water from groundwater sources for the rest of the year. Unfortunately, in many cases, this groundwater is polluted with arsenic as has been reported in several cities and towns along the coast [1]. In most cases the arsenic water contamination is of natural origin [2], and in a few cases from anthropogenic activities such as mining and smelting.
In water, arsenic is present as the oxyanions of As(III) and As(IV) that are the predominant arsenic dissolved species, As(III) being the most toxic and mobile form that predominates in anoxic conditions as the ones found in groundwater. Arsenic (III) removal requires a pre-oxidation step to be converted to As(V) followed by adsorption or coprecipitation of the As(V) formed with the use of coagulants like iron or oxyhydroxides [3]. As(III) conventional oxidation has been tested with potassium permanganate, sodium hypochlorite, and monochloramine in demineralized water as well in real water [4], less conventional approaches used ferrate(VI) to remove arsenite and arsenate even though it can be done in one step without producing toxic byproducts [5]. chemicals, the fuzzy logic-based control algorithm (embedded in an IoT2040 gateway system) exerts an accurate control of the pH maintaining the set point. The treatment effectively removes both species of arsenic until reaching values lower than the 10 µg/L, threshold recommended by WHO for drinking water. The tests were conducted using Synthetic Bangladesh Groundwater (SBGW) because it is the choice medium for testing arsenic removal on underground-drinking water. The SBGW chemical composition makes the arsenic removal difficult because of the presence of oxoacids such as bicarbonate, phosphate, and silicate that compete with arsenic for the sites of the iron oxyhydroxide adsorption sites [16].

Materials and Methods
Fe(VI) was previously produced using a split-cell electrochemical reactor with an anodic chamber and an iron electrode and a cathode chamber with a graphite electrode [17]. Both chambers are separated by a CTIEM-1 Zibo Cantian China 2.3 cm 2 cation exchange membrane with a pore diameter < 100 nm. The reactor functions at a current density of 80 A/m 2 using NaOH 20 mol/L as anolyte and catholyte. The anolyte was collected after 5 h of electrolysis, assayed for ferrate(VI), and stored for testing in the prototype water treatment plant.
Ferrate(VI) concentration measurement was performed using visible spectrophotometry in a Shimadzu UV-2600 spectrophotometer (Shimadzu Scientific Instruments, Kyoto, Japan). The anolyte obtained in the electrochemical reactor was diluted with NaOH 10 mol/L and read at 505 nm using a molar extinction coefficient of 1070 L mol −1 cm −1 [18] according to the following relationship: where ∆ Abs is the difference in absorbance with respect to the blank, measured at 505 nm, V final is the sum of the volumes of the sample, V sample , and the volume of the 10 mol/L NaOH solution added for the dilution, while ε is the molar extinction coefficient reported for ferrate(VI) at 505 nm (1070 L mol −1 cm −1 ), and the width of the cell (1 cm). The concentration of the ferrate(VI) solution was determined as 0.26 mol/L. It was directly used to treat the raw water without any dilution. Arsenic removal tests were conducted using Synthetic Bangladesh Ground Water (SBGW) [19]. SBGW was prepared using ultrapure water (18 MΩ.cm) and stock solutions of Na 2 HPO 4 7 H 2 O (for Emsure ® ACS, Merck, Darmstadt, Germany), NaHCO 3 (for Emsure ® ACS, Merck, Darmstadt, Germany), CaSO 4 2 H 2 O (Emsure ® precipitate, Merck, Darmstadt, Germany), MgCl 2 6 H 2 O (Emsure ® ACS, Merck, Darmstadt, Germany), CaCl 2 (for Emsure ® ACS, Merck, Darmstadt, Germany) and Na 2 SiO 3 · 5H 2 O (>95%, Sigma-Aldrich, St. Louis, MO, USA) and adjusting the pH to 7.0 ± 0.2 with carbon dioxide as described in another study [20,21]. Arsenite was prepared from arsenic trioxide (Sigma, Milwaukee, WI, USA) and arsenate from sodium arsenate dibasic heptahydrate (>98% Aldrich, Milwaukee, WI, USA). The water composition used is shown in Table 1. In addition, initial ORP was measured in 100 mV and initial pH was adjusted to two values: first to 6.58 and then to 9.38. An HPLC coupled to a hydride generation system and, as a detector, an atomic fluorescence spectrometer (HPLC-HG-AFS) PSA Millennium Excalibur (PSA Analytical Ltd., Kent, UK) were used to analyze the arsenic species content in the water samples taken during the tests. The water samples from before and after the treatment were analyzed immediately, and another set was preserved with acetic acid and EDTA as backup [22,23]. The water treatment plant prototype ( Figure 1) uses a Cole-Palmer 75211-15 centrifugal pump, with a GJ series stainless steel micropump head and a magnetic connection to steer the SBGW water during treatment. The workflow was configured at 120 L/h and was measured using a rotameter purchased from Blue-White Industries, Ltd. (Huntington Beach, CA, USA). Water is propelled through a 2.3-m long, 1" diameter PVC pipe containing a 316-L stainless steel static mixer. Using a Lead Fluid BQ50S metering pump, the Fe(VI) solution was added to the inlet, and the oxide-reduction potential (ORP) was recorded using an Endress + Hauser CPS12D digital electrode. The mixture residence is approximately 40 s. Since Fe(VI) increases the pH levels of the treated water, the pH was corrected using FeCl 3 at 40%, dosed by another Lead Fluid BQ50S pump and measured using an Endress + Hauser Orbisint CPS11D pH sensor.
Water 2018, 10, x FOR PEER REVIEW 4 of 12 BQ50S metering pump, the Fe(VI) solution was added to the inlet, and the oxide-reduction potential (ORP) was recorded using an Endress + Hauser CPS12D digital electrode. The mixture residence is approximately 40 s. Since Fe(VI) increases the pH levels of the treated water, the pH was corrected using FeCl3 at 40%, dosed by another Lead Fluid BQ50S pump and measured using an Endress + Hauser Orbisint CPS11D pH sensor. The pH control system was built and programmed as follows: the Orbisint CPS11D pH probe was connected to a Liquiline CM44 transmitter that sends a digital signal through a RJ-45 cable to a Siemens S7-1500C PLC, which executes an analog-scaled conversion of the pH signal and relays it to the IoT2040. The IoT2040 runs the fuzzy logic program developed with the MATLAB development tool and generates a PWM (pulse-width modulation) control signal for the dosing pump.
Fe(VI) dosage was then adjusted for the ORP value in the input mix to reach at least 750 mV, to ensure As(III) would be oxidized into As(V). It was decided to control the pH at a value of 6.45. Under these conditions, the arsenite oxidized into arsenate reacts with the iron, and the formed flocs are ultimately removed in a 5-µm filter.

pH Control
Electrochemical production of ferrate(VI) is conducted in a concentrated 20 mol/L NaOH producing a ferrate(VI) 0.26 mol/L solution. Then, after adding Fe(VI) into the water, a rapid increase in pH is expected. However, the control system takes a certain time before it reaches a stable pH level at the pre-established setpoint value. The task of the pH control system is to deliver the right amount of ferric chloride to lower the pH and achieve the set point.
The titration curve of ferric chloride with NaOH is a typical curve of the neutralization of a strong acid by a strong base [24], very high volumes of reagent are required to achieve very small changes at very high or very low pH values; conversely, very small volumes of neutralizing solution at pH near 7 will produce great changes in pH. This behavior with the fact that each unit of the pH scale represents a 10-fold variation in the concentration of protons emphasizes the non-linearity of the process, and suggests that pH control would be best served using a fuzzy control system whose ability to handle non-linearities has been recognized [14,25].
For example, at an initial pH value of 9.38, it takes the system approximately 9 min to stabilize its value and reach the pre-established setpoint of 6.45 ( Figure 2). An average pH = 6.455 ± 0.015 is attained in continuous mode, which is of equal magnitude to the final error-value of 0.035 pH units The pH control system was built and programmed as follows: the Orbisint CPS11D pH probe was connected to a Liquiline CM44 transmitter that sends a digital signal through a RJ-45 cable to a Siemens S7-1500C PLC, which executes an analog-scaled conversion of the pH signal and relays it to the IoT2040. The IoT2040 runs the fuzzy logic program developed with the MATLAB development tool and generates a PWM (pulse-width modulation) control signal for the dosing pump.
Fe(VI) dosage was then adjusted for the ORP value in the input mix to reach at least 750 mV, to ensure As(III) would be oxidized into As(V). It was decided to control the pH at a value of 6.45. Under these conditions, the arsenite oxidized into arsenate reacts with the iron, and the formed flocs are ultimately removed in a 5-µm filter.

pH Control
Electrochemical production of ferrate(VI) is conducted in a concentrated 20 mol/L NaOH producing a ferrate(VI) 0.26 mol/L solution. Then, after adding Fe(VI) into the water, a rapid increase in pH is expected. However, the control system takes a certain time before it reaches a stable pH level at the pre-established setpoint value. The task of the pH control system is to deliver the right amount of ferric chloride to lower the pH and achieve the set point.
The titration curve of ferric chloride with NaOH is a typical curve of the neutralization of a strong acid by a strong base [24], very high volumes of reagent are required to achieve very small changes at very high or very low pH values; conversely, very small volumes of neutralizing solution at pH near 7 will produce great changes in pH. This behavior with the fact that each unit of the pH scale represents a 10-fold variation in the concentration of protons emphasizes the non-linearity of the process, and suggests that pH control would be best served using a fuzzy control system whose ability to handle non-linearities has been recognized [14,25].
For example, at an initial pH value of 9.38, it takes the system approximately 9 min to stabilize its value and reach the pre-established setpoint of 6.45 ( Figure 2). An average pH = 6.455 ± 0.015 is attained in continuous mode, which is of equal magnitude to the final error-value of 0.035 pH units reported in a batch system [26], which is an excellent result for a continuous system where the control is more challenging.
Water 2018, 10, x FOR PEER REVIEW 5 of 12 reported in a batch system [26], which is an excellent result for a continuous system where the control is more challenging.

Arsenic Removal
The SBGW was spiked with arsenite and arsenate at a final concentration of 200 µg/L of each species. Although this synthetic water contains ions that interfere with arsenic removal processes, which are based on using iron, and that its pH was initially at 9.38, we can observe arsenite oxidation as of the 3rd minute of treatment. From the 3rd minute to the 18th minute, arsenite concentration is below equipment detection limits and, as of the 21st minute, the removal destabilizes and increases from 6.43 µg/L to 14.328 µg/L at the 24th minute. Throughout this period, the average arsenic concentration was 6.66 ± 5.647 µg/L ( Figure 3). Hence, at the 9th, 12th, 21st, and 24th minute, the total arsenic concentration exceeded the 10 µg/L threshold set by the World Health Organization (WHO) for drinking water.
Additionally, at an initial pH level of 6.58, the readings, at 33 and 36 min were below the equipment detection limit and, at the 39th minute, arsenite concentration was 1.0120 µg/L, and the arsenate concentration was below the detection limits ( Figure 3).

Arsenic Removal
The SBGW was spiked with arsenite and arsenate at a final concentration of 200 µg/L of each species. Although this synthetic water contains ions that interfere with arsenic removal processes, which are based on using iron, and that its pH was initially at 9.38, we can observe arsenite oxidation as of the 3rd minute of treatment. From the 3rd minute to the 18th minute, arsenite concentration is below equipment detection limits and, as of the 21st minute, the removal destabilizes and increases from 6.43 µg/L to 14.328 µg/L at the 24th minute. Throughout this period, the average arsenic concentration was 6.66 ± 5.647 µg/L ( Figure 3). Hence, at the 9th, 12th, 21st, and 24th minute, the total arsenic concentration exceeded the 10 µg/L threshold set by the World Health Organization (WHO) for drinking water.
Additionally, at an initial pH level of 6.58, the readings, at 33 and 36 min were below the equipment detection limit and, at the 39th minute, arsenite concentration was 1.0120 µg/L, and the arsenate concentration was below the detection limits ( Figure 3).
As(III) removal using metal cations, like Fe(III), is inefficient, unlike As(V) removal, because As(III) is mainly found as a neutral species at pH levels as high as 9, while the dominant species of As(V) are H 2 AsO 4 − and HAsO 4 2− which are charged [27] facilitating reaction with ferric ions.  As(III) removal using metal cations, like Fe(III), is inefficient, unlike As(V) removal, because As(III) is mainly found as a neutral species at pH levels as high as 9, while the dominant species of As(V) are H2AsO4 − and HAsO4 2− which are charged [27] facilitating reaction with ferric ions.
However, As(III) oxidation is one way to improve the removal efficiency and the subsequent adsorption of As(V) on the oxyhydroxides formed by Fe(III) [28]. The Fe(VI) dosage used at the plant oxidizes arsenite and helps to guarantee that the ORP reaches values >750 mV. In these conditions, the predominant species is As(V) (Figure 4), which can be removed using Fe(III) ions.
The 0.26 mol/L ferrate(VI) solution is added to the raw water flow at a rate of 9.90 µL/min ( Figure  5); as the flow of raw water is 2L/min, the amount of iron added per liter of raw water is 72 µg. According to Roberts [28], As(V) removal at an initial concentration of 500 µg/L requires 2.0-2.5 mg (2000-2500 µg) of Fe(III) to lower arsenic concentrations to below 50 µg/L in the absence of Si and P. In the presence of Si and P-as with the SBGW used in our study-the dosage of iron was calculated as 15-18 mg (15,000-18,000 µg/L) to achieve the same efficiencies. Therefore, the concentration of Fe(III) needed to achieve substantial removals of arsenic is several orders of magnitude higher than that supplied by the ferrate(VI) solution alone. The FeCl3 solution provides the additional Fe(III) ions needed while lowering the pH to the setpoint. Another study also described the effective removal of arsenic species by using a minute amount of ferrate(VI) with Fe(III) as a supplementary coagulant [29].
When the treated water reaches the pH setpoint, a more positive result is generated because the arsenate-iron complex is less soluble [30] and the flocs can be easily removed with the 5 µm filter. However, As(III) oxidation is one way to improve the removal efficiency and the subsequent adsorption of As(V) on the oxyhydroxides formed by Fe(III) [28]. The Fe(VI) dosage used at the plant oxidizes arsenite and helps to guarantee that the ORP reaches values >750 mV. In these conditions, the predominant species is As(V) (Figure 5), which can be removed using Fe(III) ions.
The 0.26 mol/L ferrate(VI) solution is added to the raw water flow at a rate of 9.90 µL/min ( Figure 4); as the flow of raw water is 2L/min, the amount of iron added per liter of raw water is 72 µg. According to Roberts [28], As(V) removal at an initial concentration of 500 µg/L requires 2.0-2.5 mg (2000-2500 µg) of Fe(III) to lower arsenic concentrations to below 50 µg/L in the absence of Si and P. In the presence of Si and P-as with the SBGW used in our study-the dosage of iron was calculated as 15-18 mg (15,000-18,000 µg/L) to achieve the same efficiencies. Therefore, the concentration of Fe(III) needed to achieve substantial removals of arsenic is several orders of magnitude higher than that supplied by the ferrate(VI) solution alone. The FeCl 3 solution provides the additional Fe(III) ions needed while lowering the pH to the setpoint. Another study also described the effective removal of arsenic species by using a minute amount of ferrate(VI) with Fe(III) as a supplementary coagulant [29].
When the treated water reaches the pH setpoint, a more positive result is generated because the arsenate-iron complex is less soluble [30] and the flocs can be easily removed with the 5 µm filter.

Fe(VI) and Fe(III) Instantaneous Dosing
The instantaneous dosing of Fe(VI) and Fe(III) was automatically recorded during 40 min of treatment ( Figure 5), and an increase in Fe(VI) dosage was observed from 9.4 to 9.95 µL/min, which translates into a 5.8% increase from the initial dosage. Concurrently, a decrease in Fe(III) dosage from 9.75 to 9.4 µL/min occurs, corresponding to a 3.6% reduction from the initial dosage. Similarly, an oscillation in Fe(III) dosage is noticed, which decreases as the treatment advances, thus demonstrating better dosage control.

Fe(VI) and Fe(III) Instantaneous Dosing
The instantaneous dosing of Fe(VI) and Fe(III) was automatically recorded during 40 min of treatment (Figure 4), and an increase in Fe(VI) dosage was observed from 9.4 to 9.95 µL/min, which translates into a 5.8% increase from the initial dosage. Concurrently, a decrease in Fe(III) dosage from 9.75 to 9.4 µL/min occurs, corresponding to a 3.6% reduction from the initial dosage. Similarly, an oscillation in Fe(III) dosage is noticed, which decreases as the treatment advances, thus demonstrating better dosage control.
The water treatment plant prototype developed controls pH levels based on fuzzy logic, and it was used to treat SBGW whose initial equimolar content of both arsenite and arsenate was at 200 µg/L concentration. At a high initial pH level of 9.38 for the synthetic water, the arsenite concentration was removed until reaching values lower than the equipment detection limits, while the arsenate was removed until reaching an average value of 6.66 µg/L. Nevertheless, when the initial pH was 6.58, the arsenate concentration was lower than the equipment detection limits and the arsenite concentration reached 1.0120 µg/L. For both initial pH conditions, it was possible to remove arsenic until reaching values lower than the 10 µg/L threshold recommended by the WHO for potable water. Hence, the effectiveness of the prototype developed was successfully validated.

Estimated Cost of the Treated Water
The dosing rate of the Fe (VI) and Fe (III) solutions allows calculation of the cost of the chemicals used for the treatment. The dosing rates used for the calculations are the ones for the last minute of the treatment, when the dosage stabilized, and the removal of arsenic was more effective.
The dosing flow of ferrate(VI) in 0.26 mol/L solution was 9.90 µL/minute; according to this flow, the raw water flow, and the calculated cost of the gram of ferrate(VI) produced by the electrochemical reactor at US $ 0.020 [17], the cost is the following: (1) The dosing flow rate of FeCl 3 40% solution and density of 1.40 g/cm 3 were 29 µL/minute; according to this dosing flow, the raw water flow, and the sale price of US$ 38 per 40 kg cylinder, the following cost is obtained: Since, both inputs are required for the complete treatment of the water. The cost of inputs-without considering capital or operating expenses-is US$ 0.022 per cubic meter of treated water.

Conclusions
A prototype of a water treatment plant using Fe(VI) as an oxidizing agent with a pH control system based on fuzzy logic was successfully implemented. This plant treated SBGW water prepared with an initial arsenite and arsenate content of 200 µg/L for both. The non-linear behavior of the pH by adding Fe(VI) in continuous flow was adequately controlled. This allowed the removal of arsenic below the limit of 10 µg/L recommended by the WHO for drinking water with a cost of US$ 0.022 per cubic meter (without considering capital or operating expenses).
The treatment was carried out by choosing a setpoint of 6.45, under two initial pH conditions: 9.38 and 6.58. In both cases, it was verified that the average pH value obtained was 6.455 ± 0.015. Regarding arsenic removal, for a pH = 9.38, the concentration of arsenite was removed to values below the detection limit of the equipment, and arsenate to an average value of 6.66 µg/L; for a pH = 6.58, the concentration of arsenate was below the detection limit of the equipment, and that of arsenite was 1.0120 µg/L.  Acknowledgments: Support from Facultad de Ingeniería y Arquitectura Universidad de Lima, Instituto de Investigación Científica de la Universidad of Lima -IDIC, Siemens distributor in Perú DIN automation and Endress + Hauser distributor in Perú Corsusa are greatly acknowledged.

Conflicts of Interest:
The authors declare no conflict of interest.

Appendix A. Design and Implementation of pH Control with Fuzzy Logic
The Mamdani fuzzy logic model was used, which is composed of (i) a Fuzzifier, whose pH value is transformed into a language that the IoT microprocessor can process; (ii) a Fuzzy Inference System, containing the different membership levels originated in the Fuzzifier; (iii) the Fuzzy Rule System, a set of rules serving as the system engine obtained from learning procedure information generated at the laboratory and interpreted with IF-THEN type rules, which determine an antecedent and a consequence; and (iv) the Defuzzifier, whose goal is to convert the output to analog values as received from the Center of Gravity for all possible responses, according to the degree of membership. Figure A1 depicts the general application structure for the fuzzy control system of a water treatment plant prototype. In the fuzzification, the value from the pH analog sensor is converted into relative values. The inference stage then provides fuzzy system rules. In the defuzzification, relative values are converted into analog values to control the rotational speed of the peristaltic pump (actuator) [14].
Water 2018, 10, x FOR PEER REVIEW 9 of 12

Conflicts of Interest:
The authors declare no conflict of interest.

Appendix A. Design and Implementation of pH Control with Fuzzy Logic
The Mamdani fuzzy logic model was used, which is composed of (i) a Fuzzifier, whose pH value is transformed into a language that the IoT microprocessor can process; (ii) a Fuzzy Inference System, containing the different membership levels originated in the Fuzzifier; (iii) the Fuzzy Rule System, a set of rules serving as the system engine obtained from learning procedure information generated at the laboratory and interpreted with IF-THEN type rules, which determine an antecedent and a consequence; and (iv) the Defuzzifier, whose goal is to convert the output to analog values as received from the Center of Gravity for all possible responses, according to the degree of membership. Figure A1 depicts the general application structure for the fuzzy control system of a water treatment plant prototype. In the fuzzification, the value from the pH analog sensor is converted into relative values. The inference stage then provides fuzzy system rules. In the defuzzification, relative values are converted into analog values to control the rotational speed of the peristaltic pump (actuator) [14].  Figure A2 depicts the scheme of the control loop with feedback used for the calculation of E(K) = y(K) − r(K) error. Here, E(K) is the fuzzy system input, y(K) variable specifies the pH value of the water after the Fe(VI) dosage, and r(K) is the set point value. The output response value Y(k) of the fuzzy system maintains the voltage between 0 and 5 V to control the rotation speed of the pump dosing ferric chloride.  Table A1 shows the variables used as input functions of the fuzzifier system and output functions of the defuzzifier system. Figure A3. denotes the fuzzy controller rules (trapezoidal functions), which are established according to the experience of the operator. These are the input rules of the fuzzy system. Figure A4. denotes the fuzzy pH controller output that are the output rules of the fuzzy system.  Figure A1. Fuzzy logic system diagram. Figure A2 depicts the scheme of the control loop with feedback used for the calculation of E(K) = y(K) − r(K) error. Here, E(K) is the fuzzy system input, y(K) variable specifies the pH value of the water after the Fe(VI) dosage, and r(K) is the set point value. The output response value Y(k) of the fuzzy system maintains the voltage between 0 and 5 V to control the rotation speed of the pump dosing ferric chloride.
Water 2018, 10, x FOR PEER REVIEW 9 of 12

Conflicts of Interest:
The authors declare no conflict of interest.

Appendix A. Design and Implementation of pH Control with Fuzzy Logic
The Mamdani fuzzy logic model was used, which is composed of (i) a Fuzzifier, whose pH value is transformed into a language that the IoT microprocessor can process; (ii) a Fuzzy Inference System, containing the different membership levels originated in the Fuzzifier; (iii) the Fuzzy Rule System, a set of rules serving as the system engine obtained from learning procedure information generated at the laboratory and interpreted with IF-THEN type rules, which determine an antecedent and a consequence; and (iv) the Defuzzifier, whose goal is to convert the output to analog values as received from the Center of Gravity for all possible responses, according to the degree of membership. Figure A1 depicts the general application structure for the fuzzy control system of a water treatment plant prototype. In the fuzzification, the value from the pH analog sensor is converted into relative values. The inference stage then provides fuzzy system rules. In the defuzzification, relative values are converted into analog values to control the rotational speed of the peristaltic pump (actuator) [14].    Table A1 shows the variables used as input functions of the fuzzifier system and output functions of the defuzzifier system. Figure A3. denotes the fuzzy controller rules (trapezoidal functions), which are established according to the experience of the operator. These are the input rules of the fuzzy system. Figure A4. denotes the fuzzy pH controller output that are the output rules of the fuzzy system.  Figure A2. Fuzzy control structure. Table A1 shows the variables used as input functions of the fuzzifier system and output functions of the defuzzifier system. Figure A3. denotes the fuzzy controller rules (trapezoidal functions), which are established according to the experience of the operator. These are the input rules of the fuzzy system. Figure A4. denotes the fuzzy pH controller output that are the output rules of the fuzzy system.         The pH error is N7 If (input N7) then (output P7) Pump is set to P7 The pH error is N8 If (input N2) then (output P7) Pump is set to P8  In order to optimize the fuzzy system, a simulation was run with the Surface Viewer tool in Matlab, where the variable Input1 is the difference between the value obtained in the sensor minus the setpoint (error), in the Ouput1 axis, it is the PWM output value that controls the RPM the actuator (the peristaltic pump). The corresponding curve response is shown in Figure A5. Table A2. Input and output functions with fuzzy system rules.

Functions of the Fuzzifier (Inputs) Fuzzy Rule System Functions of the Defuzzifier (Outputs)
The pH error is N1 If (input N0) then (output P0) Pump is set to P1 The pH error is N2 If (input N1) then (output P1) Pump is set to P1 The pH error is N3 If (input N3) then (output P3) Pump is set to P3 The pH error is N4 If (input N4) then (output P4) Pump is set to P2 The pH error is N0 If (input N5) then (output P5) Pump is set to P0 The pH error is N5 If (input N6) then (output P6) Pump is set to P5 The pH error is N6 If (input N8) then (output P8) Pump is set to P6 The pH error is N7 If (input N7) then (output P7) Pump is set to P7 The pH error is N8 If (input N2) then (output P7) Pump is set to P8 Water 2018, 10, x FOR PEER REVIEW 11 of 12 Figure A5. Fuzzy system response curve.
The fuzzy system rules were implemented into the Iot2040 program that uses scaling functions for calculating sensor values and blocks to normalize input signals [32]. The value ranges from 0 to 27,648, while the pH sensor has values that range from 0 and 14. The PLC analog module becomes the input for calculating the values ranging from 0 to 5 V, which is the input of the IoT2040, and its output signal type is pulse-width modulation, which is calculated based on membership rules and obtained from center of gravity estimates to control the voltage of the peristaltic pump, ranging from 0 to 5 V. The fuzzy system rules were implemented into the Iot2040 program that uses scaling functions for calculating sensor values and blocks to normalize input signals [32]. The value ranges from 0 to 27,648, while the pH sensor has values that range from 0 and 14. The PLC analog module becomes the input for calculating the values ranging from 0 to 5 V, which is the input of the IoT2040, and its output signal type is pulse-width modulation, which is calculated based on membership rules and obtained from center of gravity estimates to control the voltage of the peristaltic pump, ranging from 0 to 5 V.