**1. Introduction**

Wastewater neutralization plays an important part in a wastewater treatment process. It provides the optimum environment for microorganism activity between pH 6.5 and 7.5{1}, and the right water discharge to the public sewage as mandated by the Department of Environment of between pH 5 and 9 (Environmental Quality Act, 1974) {2}. Wastewater of pH below 4.5 and above 9 may greatly reduce the activity of the microorganisms which treat the water and may not support their life at all {3}.

For a number of years, Hydrogen chloride (HCL) acid was used in wastewater treatment facilities to control alkalinity. It's a product that works, but it also has many potential problems. HCL acid can be difficult to apply and control. Correcting the pH of alkaline wastewater is usually required either for discharge to sewer, in preparation to further biological, physical/chemical treatment or direct discharge to the environment. Strong acids such as hydrochloric acid have traditionally been used to neutralize alkaline waste streams prior to discharge {4}.

On the control side, It is well known that controlling pH is very difficult, and specially neutralization in industry, due to the high non linearity of the system. In fact the pH dynamics are not only time variant, but change with each pH value and becomes oscillatory around the 7 mark as well. Even by placing the pH probe in the proximity of a mixer or in a turbulent flow could result in a big change in the pH. It has been reported in literature that researchers have been trying for ages to control the pH with a tuned classical PID controller with many additional restrictions; but experience has shown that this is not satisfactory because of the changing of dynamics hence the transfer function where when the PID is tuned for a certain characteristics, it becomes completely un-tuned for the next. To overcome this problem, we (here at the chemical engineering department University of Bahrain) have engaged in finding a solution to the problem. One of the option possible is the use of fuzzy logic. For the last fifty years, since Zadeh {5} introduces his famous paper on fuzzy logic and

© 2012 Ghassoul, licensee InTech. This is an open access chapter distributed under the terms of the Creative Commons Attribution License (http://creativecommons.org/licenses/by/3.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited. © 2012 Ghassoul, licensee InTech. This is a paper distributed under the terms of the Creative Commons Attribution License (http://creativecommons.org/licenses/by/3.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited.

control, fuzzy logic control has been widely implemented successfully in many industrial applications ranging from home appliances such as washing machines to heavy industries such as loading and unloading very heavy loads in ports efficiently by minimizing the action time. Certainly its use in controlling pH is feasible.This is due two reasons:

	- 1. The huge number of rule one could implement. In fact, we have currently applied more than 125 rules and still the margin is open.
	- 2. The simplicity of MATLAB fuzzy control, where the SIMULINK blocksets could be used directly. This saves a lot of computing time. On top of that, those blocksets are already optimized.
	- 3. Though MATLAB was originally designed as a simulator platform, for the last few years, several companies have developed several interfacing cards to interface online different processes to the MATLAB platform, such as HUMUSOFT MF 624 multifunction I/O card and National Instrument card NI PCI-6221 data acquisition card. Hardware interface to the process in question, real time, where this has been done with a relative ease thank's to National Instrument NI PCI- 6221 data acquisition card.

But before discussing how SIMULINK is used, we first have to highlight the pH apparatus used. Luckily, we found an obsolete pH control apparatus made by ARMFIELD UK (PC5 PH control RIG) which was made back in the early eightees, with the following components: framework assembly complete with pump set, two storage tanks, two flow meters, with a completely irreparable pH probe, pneumatically operated valve driven with a current to pressure converter, air filter regulator, glass vessel, clamps , stirrer together with obsolete three term PID electronic controller, slide indicator and chart recorder. The control was developed around a dedicated classical PID controller where the user only sets up the PID parameters through a number of knobs. The response is either given through slide indicator or chart recorder. (see figure (1)). This procedure was no use, where advanced control is not possible. So this controller was completely isolated and replaced by a modern SIMULINK based controller built for this purpose. The process is as follows. Two tanks are used ; one filled with an acidic liquid and the other with base liquid. The acidic liquid is controlled manually and the base liquid is controlled through a 3 to 15 PSI proportional control valve. The pressure is generated by controlling a pressure gauge through a current to pressure converter. Unfortunately, the output from MATLAB to the acquisition card is only in volts, whereas the valve driving signal is in milliamperes. This has lead to the design of a 0 - 5V voltage to 4-20mA current converter to drive the valve. The control voltage is generated by SIMULINK as a result of the control strategy developed around the fuzzy control blocksets. The control signal produced by the blockset is outputted through the NI card to the hardware. The beauty of this control is that the process could be monitored through MATLAB virtual instrument online.

#### **1.1. PH control**

244 MATLAB – A Fundamental Tool for Scientific Computing and Engineering Applications – Volume 1

action time. Certainly its use in controlling pH is feasible.This is due two reasons:

the change of the pH characteristic does not influence the control strategy.

considered very carefully for several reasons.

already optimized.

acquisition card.

more than 125 rules and still the margin is open.

control, fuzzy logic control has been widely implemented successfully in many industrial applications ranging from home appliances such as washing machines to heavy industries such as loading and unloading very heavy loads in ports efficiently by minimizing the

1. The fuzzy control does not require any transfer function, nor any tedious mathematical analysis. So there is no need to model the system continuously, with each pH space, so

2. The membership space of the pH is restricted between zero and fourteen where pH between zero and seven is acid and between seven and fourteen is base. This space is divided into a limited number of memberships, and the control for each membership could be easily tuned separately. To apply this strategy we had to look for the best possible solution. And luckily, we find the solution in MATLAB, through SIMULINK fuzzy control blocksets. The choice of SIMULINK fuzzy control blocksets was

1. The huge number of rule one could implement. In fact, we have currently applied

2. The simplicity of MATLAB fuzzy control, where the SIMULINK blocksets could be used directly. This saves a lot of computing time. On top of that, those blocksets are

3. Though MATLAB was originally designed as a simulator platform, for the last few years, several companies have developed several interfacing cards to interface online different processes to the MATLAB platform, such as HUMUSOFT MF 624 multifunction I/O card and National Instrument card NI PCI-6221 data acquisition card. Hardware interface to the process in question, real time, where this has been done with a relative ease thank's to National Instrument NI PCI- 6221 data

But before discussing how SIMULINK is used, we first have to highlight the pH apparatus used. Luckily, we found an obsolete pH control apparatus made by ARMFIELD UK (PC5 PH control RIG) which was made back in the early eightees, with the following components: framework assembly complete with pump set, two storage tanks, two flow meters, with a completely irreparable pH probe, pneumatically operated valve driven with a current to pressure converter, air filter regulator, glass vessel, clamps , stirrer together with obsolete three term PID electronic controller, slide indicator and chart recorder. The control was developed around a dedicated classical PID controller where the user only sets up the PID parameters through a number of knobs. The response is either given through slide indicator or chart recorder. (see figure (1)). This procedure was no use, where advanced control is not possible. So this controller was completely isolated and replaced by a modern SIMULINK based controller built for this purpose. The process is as follows. Two tanks are used ; one filled with an acidic liquid and the other with base liquid. The acidic liquid is controlled manually and the base liquid is controlled through a 3 to 15 PSI proportional control valve. The pressure is generated by controlling a pressure gauge through a current to pressure converter. Unfortunately, the output from MATLAB to the acquisition card is only in volts, PH is an important variable in production fields such as chemical and petrochemical industries where tons of toxic products are pumped into environment due to contaminated chemical waste. Most of those product wastes are mainly alkaline. This will certainly harms the environment in particular sea life as well as agricultural products which in turn reflects on the human life quality. So it is essential to treat those wastes to neutralize their pH to an acceptable level, ideally around 7. So what is pH. The PH of a solution is defined as the negative of the logarithm to the base of 10 of the hydrogen ion concentration.

$$\text{PH} = \begin{array}{c} -\log \text{ 10 } \boxed{\text{H} + \text{ }} \end{array}$$

Most of the factories waste is mainly alkaline; this certainly harms the environment by poisoning life onshore or offshore, including humans either through contaminated food and water or through breathing. This is witnessed by the increased rate of cancer cases in the world. So it is a must to neutralize the industry waste by neutralizing the pH. This is quantitavely done by bringing the pH to around the magic value of seven. In industry, the pH could vary between any value between 2 and 10. Here in our lab, we are using PC5 Armfield obsolete PH control apparatus. Its PI & D diagram is shown in figure(1).

The neutralization process basically follows the following reaction:

$$\text{(NCL+NAOH} \rightarrow \text{NACL+H}\_2\text{O)}$$

This reaction results in salt and water which do not present any harm to nature. (The process system is shown in figure(2)). The system basically consists of two liquid circuits; one feeding the acidic substance and the other feeds the base liquid. The added liquid is controlled by a proportional control valve whereas the base liquid is manually operated.

To make the mixture homogeneous, a variable speed mixer is used. The pH is picked up with the aid of a probe placed into the mixing vessel close to the outlet. Unlike the PID controller where many restrictions are imposed, fuzzy controller only requires the probe to be out off the flow turbulence way next the outlet. The probe reading is conditioned and fed to the controller through the NI PCI-6221 card of the E series, and at the same time, fed to the pH meter for confirmation. The card has 16 analogue input channels which could be connected as differential or single ended, sixteen bit resolution and two output analogue channels. The signal conditioning is no more than an instrumentation amplifier (figure(3)) of type INA114. This type of amplifier is very precise. The output of the amplifier is then fed to NI card, to be read into SIMULINK to be analyzed using the fuzzy controller. Once the signal has been treated, the resulting control variable is outputted through the output port of the NI card to drive the control valve. Unfortunately this output is in volts, whereas the driving signal required by the control valve is in milliamperes(current). This requires the design of a voltage to current converter. It should be mentioned here that the control valve used is of proportional type where it closes linearly from fully closed to fully open by using a current to pressure converter which converters a 4-20mA to 3-15PSI pressure. The Valve controls the acid flow rate of type HCL. So by varying the valve opening, the flow rate changes so does the pH. The base flow is manually controlled. The output of the pH sensor is fed to an instrumentation amplifier as mentioned earlier, to condition it, and at the same time to the NI6221 acquisition card, through which it is read into the SIMULINK fuzzy controller. The output of the controller is applied to the voltage to current converter, which in turn drives the current to pressure converter. This action adjusts the flow rate of the HCL, thus the input to the controller is the pH reading of the waist (NAOH) which is compared against the required set point. At the same time the output obtained from the controller is used to control the valve. (1- convert the output voltage to current. 2- convert the current to pressure which drives the valve) and the valve in turn controls the percentage the valve opening to control the HCL flow rate. This output tends to maintain the pH value of the waist (NAOH) to a target value.

**Figure 1.** PI & D of the PH control system

**Figure 2.** The PH control system

waist (NAOH) to a target value.

**Figure 1.** PI & D of the PH control system

NI card, to be read into SIMULINK to be analyzed using the fuzzy controller. Once the signal has been treated, the resulting control variable is outputted through the output port of the NI card to drive the control valve. Unfortunately this output is in volts, whereas the driving signal required by the control valve is in milliamperes(current). This requires the design of a voltage to current converter. It should be mentioned here that the control valve used is of proportional type where it closes linearly from fully closed to fully open by using a current to pressure converter which converters a 4-20mA to 3-15PSI pressure. The Valve controls the acid flow rate of type HCL. So by varying the valve opening, the flow rate changes so does the pH. The base flow is manually controlled. The output of the pH sensor is fed to an instrumentation amplifier as mentioned earlier, to condition it, and at the same time to the NI6221 acquisition card, through which it is read into the SIMULINK fuzzy controller. The output of the controller is applied to the voltage to current converter, which in turn drives the current to pressure converter. This action adjusts the flow rate of the HCL, thus the input to the controller is the pH reading of the waist (NAOH) which is compared against the required set point. At the same time the output obtained from the controller is used to control the valve. (1- convert the output voltage to current. 2- convert the current to pressure which drives the valve) and the valve in turn controls the percentage the valve opening to control the HCL flow rate. This output tends to maintain the pH value of the

**Figure 3.** Signal amplifier of type INA114
