Ph Measure Thru Labview via Matlab

25
UNIVERSITI PUTRA MALAYSIA CONTROL OF pH LEVEL USING FUZZY CONTROLLER ILANUR MUHAINI BT MOHD NOOR FK 2009 8

Transcript of Ph Measure Thru Labview via Matlab

Page 1: Ph Measure Thru Labview via Matlab

UNIVERSITI PUTRA MALAYSIA

CONTROL OF pH LEVEL USING FUZZY CONTROLLER

ILANUR MUHAINI BT MOHD NOOR

FK 2009 8

Page 2: Ph Measure Thru Labview via Matlab

CONTROL OF pH LEVEL USING FUZZY

CONTROLLER

ILANUR MUHAINI BT MOHD NOOR

MASTER OF SCIENCE

UNIVERSITI PUTRA MALAYSIA

MARCH 2009

Page 3: Ph Measure Thru Labview via Matlab

Abstract of thesis presented to the Senate of Universiti Putra Malaysia in fulfillment

of the requirements for the degree of Master of Science

CONTROL OF pH LEVEL USING FUZZY CONTROLLER

By

ILANUR MUHAINI BT MOHD NOOR

March 2009 Chairman: Samsul Bahari b. Mohd Noor, PhD Faculty: Engineering The idea of constructing this project is to simulate the control system of pH level by

adding acid or base (alkali) into a process tank in a wastewater system to maintain the pH

level to neutral value, which is pH 7. Environment has been ruined by lots of

development especially at the industrial area. For that reason, it is important that the

wastage is been taking care of as a preventative measure before things get worse. The

control system of pH level in this project is done by using LabVIEW which is graphical

programming environment software with the addition of fuzzy logic controller of

MATLAB. Block diagram of the whole system is constructed in LabVIEW and the

calculation of the amount of acid and alkali to be added to the process tank to maintain its

pH level at neutral (pH = 7) is done by fuzzy logic controller. Control of pH in mix tank

depends on the flow rate which could be manually control by several valves which enable

either acid or base to be pumped in. The control development has been designed in

LabVIEW block diagram and the Graphical User Interface (GUI) has been created in the

LabVIEW front panel. The result of experiment could be easily controlled and several

results could be compared to obtain the best neutralization system. Further use of this

project could also help the process of drinking water system. Since human has been

contaminated by a lot of sickness and it is founded that alkaline water is good for human,

therefore this project also could be use to control the alkalinity of water instead of

neutralization.

I

Page 4: Ph Measure Thru Labview via Matlab

Abstrak tesis ini dibentangkan kepada Senat Universiti Putra Malaysia untuk memenuhi keperluan bagi pengajian Sarjana Sains

KAWALAN TAHAP pH MENGGUNAKAN PENGAWAL LOGIK FUZZI

Oleh

ILANUR MUHAINI BT MOHD NOOR

Mac 2009

Pengerusi : Samsul Bahari b. Mohd Noor, PhD Fakulti : Kejuruteraan

Tujuan thesis ini adalah untuk merekabentuk satu sistem kawalan tahap pH dengan

menambah asid atau alkali untuk mengekalkan tahap keneutralan dalam tangki sistem

sisa cecair dari kilang. Alam sekitar telah dimusnahkan oleh pelbagai pembangunan

terutama di kawasan perindustrian. Oleh itu, adalah langkah berjaga-jaga perlu diambil

untuk memelihara alam sekitar. Program menggunakan LabVIEW digandingkan dengan

kawalan logik fuzzy MATLAB telah digunakan untuk sistem kawalan tahap pH dalam

tesis ini. Gambarajah blok keseluruhan sistem ini telah direka dengan menggunakan

LabVIEW dan pengiraan isipadu asid dan alkali yang diperlukan untuk mengekalkan

tahap keneutralan (pH=7) pula direka menggunakan sistem kawalan logik fuzzy.

Kawalan pH dalam tangki campuran perlu mengambil kira faktor nisbah aliran cecair di

mana ia boleh dikawal secara manual oleh beberapa injap. Rekabentuk sistem kawalan

ini dibuat dengan menggunakan gambarajah blok dan sistem antaramuka pengguna grafik

telah direka pada panel hadapan LabVIEW. Hasil eksperimen dapat dikawal dan

dibandingkan untuk mencapai sistem peneutralan yang terbaik dan berkesan. Projek ini

juga boleh membantu pemprosesan air minuman dengan mengawal kealkalian.

II

Page 5: Ph Measure Thru Labview via Matlab

ACKNOWLEDGEMENT

A very great gratitude to my supervisor, Dr. Samsul Bahari Mohd Noor and Dr.

Hamiruce Marhaban for all the effort and guidance in helping me to complete my

Masters of Science project. Other than that, I would like to express my thanks to my

parents, boyfriend and friends who always support me mentally and physically. There are

a lot of commitments that I am responsible of especially in my current work as a lecturer

in Tar College. Doing masters as part time studies is not easy if we cannot manage the

time between studies and work. I truly thank UPM for providing all the necessary

facilities when ever I need it. May all this hard work be as a stepping stone for a brighter

future.

III

Page 6: Ph Measure Thru Labview via Matlab

This thesis submitted to the Senate of University Putra Malaysia and has been accepted as fulfillment of the requirement for the degree of Masters. The members of the Supervisory Committee are as follows: Samsul Bahari B. Mohd Noor, PhD Lecturer Faculty of Engineering Universiti Putra Malaysia (Chairman) Hamiruce Marhaban, PhD Lecturer Faculty of Engineering Universiti Putra Malaysia (Member)

HASANAH MOHD. HAZALI, PhD Professor and Dean School of Graduate Studies

Universiti Putra Malaysia

Date: 14th May 2009

IV

Page 7: Ph Measure Thru Labview via Matlab

V

Page 8: Ph Measure Thru Labview via Matlab

DECLARATION I declare that the thesis is my original work except for quotations and citations which have been duly acknowledged. I also declare that it has not been previously, and is not concurrently, submitted for any other degree at Universiti Putra Malaysia or at any other institution.

-------------------------------------------------- ILANUR MUHAINI BT MOHD NOOR

Date : 3rd July 2009

VI

Page 9: Ph Measure Thru Labview via Matlab

TABLE OF CONTENTS ABSTRACT I ABSTRAK II ACKOWLEDGEMENT III APPROVAL IV DECLARATION V LIST OF TABLES VIII LIST OF FIGURES IX Chapter 1 Introduction

1.1 Introduction to existing plant 1 1.2 Comparison with other projects 1 1.3 Problem Statement 3 1.4 Objectives and Project Interests 4 1.5 Outline of the Thesis 5 1.6 The scope of work 7

Chapter 2 Literature review 2.1 Related research works review 8 2.2 History of pH values 10 2.3 Related theories and measurement 19 2.4 pH calculations 22 2.5 LabVIEW Software 22 2.6 Fuzzy Logic Controller 25 2.7 Advantages of Fuzzy Controller 29 2.8 Fuzzy Controller Design Procedures 32 Chapter 3 MATLAB Fuzzy Logic Controller 3.1 Fuzzy Logic Controller 35 3.2 Building System Using Fuzzy Logic Toolbox 35 3.3 Fuzzy rules 44 3.4 Introduction of LabVIEW software 46 3.5 Description of the software 48 3.6 Procedure in designing the front panel 50

Chapter 4 Results 4.1 Fuzzy Rule viewer in MATLAB 67 4.2 Results of the output level of the mix tank 74

VII

Page 10: Ph Measure Thru Labview via Matlab

Chapter 5 Conclusion 5.1 Conclusion 79 5.2 Recommendation 81 REFERENCES 83 APPENDICES 92 BIODATA OF STUDENT 122

VIII

Page 11: Ph Measure Thru Labview via Matlab

LIST OF TABLE

Table Page

2.0 A list of some common substances and their pH’s

15

2.0 The concentration of both the hydrogen ion and the hydroxyl ion at different pH values.

18

2.2. Relationship among several levels of acidity and basicity

20

2.3 Salt pH produced after the mixing of acid and base

21

3.2 Input and output of the Fuzzy system

36

3.3 Rules Table for fuzzy ph control system

41

IX

Page 12: Ph Measure Thru Labview via Matlab

LIST OF FIGURES

Figure Page

1.2 The ph neutralization plant showing mainly the mix tank with acid and caustic (base) tank supplied to it

2

1.3 Block diagram of fuzzy controller 4

1.4 Flow chart of designing the whole project

6

2.0 pH scale and pH of some common items

16

3.2 Fuzzy Inference System Editor

36

3.3 Membership Function editor of pH 37

3.4 Membership Function plots for acid flow 39

3.5 Membership Function plots for base flow 40

3.6 Rule editor showing seven rules which are being used in the system

42

3.7 Rule viewer showing at sensed pH level of 2.63

43

3.8 The fuzzy rules are written in the fuzzy rule editor

45

3.9 Front Panel of LabVIEW 46

3.10 Block Diagram of LabVIEW 47

3.11 Front Panel of LabVIEW software for pH neutralization system

49

3.12 Front panel 51

3.13 Block Diagram showing simple input and output linked in a formula block diagram of acid

52

3.14 Front panel for user to key in their desired input 54

X

Page 13: Ph Measure Thru Labview via Matlab

XI

3.15 Block diagram showing simple input and output linked in a formula of base

55

3.16 Front panel for simple formula input 57

3.17 Block diagram for formula module 58

3.18 Block diagram showing the adjustable of pH level depends on incoming sensed value of the pH sensor

60

3.19 Block diagram showing the adjustable of pH level depends on incoming sensed value of the pH sensor (continuity of Figure 3.18)

61

3.20 Front panel view before fuzzy controller being added to the LabVIEW environment

61

3.21 Block diagram of the completed project

63

3.22 Larger view of the block diagram of the completed project

64

3.23 Front panel of the completed project 65

4.1 Rule viewer of pH 7 67

4.2 Rule viewer of pH 1.862 68

4.3 Rule viewer of pH 11.5 69

4.4 Rule viewer of pH 6.358 70

4.5 Rule viewer of pH 12.78 71

4.6 Surface viewer of pH versus acid flow 72

4.7 Surface viewer of pH versus base flow 73

4.8 – 4.12

Mix tank pH versus time

74-78

Page 14: Ph Measure Thru Labview via Matlab

CHAPTER 1

1.1 Introduction

Nearly all process plants generate a wastewater effluent that must be neutralized prior to

discharge or reuse. Therefore, pH control is needed in just about every process plant, and

yet a large percentage of pH loops perform poorly. Results are lesser product quality,

environmental pollution, and material waste. Examples of areas where pH control

processes are in extensive use are water treatment plants, many chemical processes,

metal-finishing operations, production of pharmaceuticals and biological processes. With

ever increasing demands to improve plant efficiency and tighter regulations in

environmental protection, effective and continuous pH control is extremely

advantageous. A control of pH process is highly nonlinear. The pH value versus the

reagent flow has a logarithmic relationship. Away from neutrality, the process gain is

relatively small. Near neutrality where pH=7, the process gain can be a few thousand

times higher.

1.2 The Neutralization System Neutralization is a chemical reaction, also called a water forming reaction, in which an

acid and a base or alkali (soluble base) react and produce a salt and water (H2O). In other

words, it can be said that neutralization is the combination of hydrogen ions H+ and

hydroxide ions OH− (or oxide ions O2−) to form water molecule H2O. In the process, a

salt is formed[9].

1

Page 15: Ph Measure Thru Labview via Matlab

The neutralization systems to be controlled are illustrated in Figure 1.2. Figure 1.2

is a closed loop system, which contains a mix tank, an acid tank and a base tank. The mix

tank contains the wastewater to be processed. As we know, most of the wastewater is

acidic or basic which are not beneficial to the environment. Therefore, the aim of this

system is to neutralize it by adding acid or base from another tank depends on its pH

value sensed by the pH meter (sensor) in the mix tank. If the reading of the pH meter

shows pH value which is less than 7, then it is acidic and certain amount of base will be

pumped into the mix tank from the base tank. On the other hand, if the reading of the pH

meter shows pH value which is more than 7, then it is basic and certain amount of acid

will be pumped into the mix tank from the acid tank.

Figure 1.2: The PH neutralization plant showing mainly the mix tank with acid and caustic (base) tank supplied to it

2

Page 16: Ph Measure Thru Labview via Matlab

1.3 Problem Statement

As the process to be controlled is highly nonlinear, the usual PI-type fuzzy controller is

not able to control these systems adequately. To solve this problem, based on prior

knowledge of the process, the pH neutralization process is divided into several fuzzy

regions such as high-flow rate, medium-flow rate and low-flow rate. Then, a fuzzy logic

controller is designed using random variable of pH value as input, giving adequate

performance in all regions.

One of the most critical problems in practical engineering design and implementation

applications is the total cost and time constraint. Industrial control projects also are

restricted by financial limitations especially in hardware. However economizing the

project usually causes the quality is being degraded. Software control methods like fuzzy

controllers are more efficient because it could be controlled without effecting hardware in

the plant. Not only that, the whole system could be altered without difficulty in case of

any addition or deduction of inputs and outputs in the process plant. Unlike

mathematical models simulation, fuzzy controllers only need few rules and suitable

membership function which saves hassle time if one is not dedicated in developing the

mathematical model. This projects also being designed using LabVIEW programming

which is a graphical programming. Only a small number of calculations on flow rate of

the acid and base need to be added with C programming in the block diagram module of

LabVIEW.

In compare with the conventional controllers, fuzzy controllers have a high ability to

control nonlinear, time–invariant, time-delayed and complex processes. But unlike the

3

Page 17: Ph Measure Thru Labview via Matlab

conventional controllers, the procedures of fuzzy control algorithm involve the powerful

software and big volume of memory to implement.

Fuzzification, fuzzy inference and defuzzification call for strong software programming

as shown in Figure 1.3. The heart of fuzzy controller is rule base that expresses the

control laws in a human expert natural language basis. The number of rules is determined

based on the number of fuzzy subsets (membership functions) for each fuzzy input/output

variable. When the number of fuzzy subsets and consequently the number of fuzzy rules

is bigger the approximation of control surface is more accurate, smooth and robust. On

the other hand fuzzy rules should be stored in a memory space and big number of rules

needs large memory space and long program cycle time. The design, tuning and

implementation of fuzzy controllers are complex and time consuming, too. Therefore

new simple algorithms are necessary to simplify the design procedure of fuzzy logic

controller.

Figure 1.3: Block Diagram of a Fuzzy Controller

1.4 Objectives and Project Interests

To design and implement fuzzy controller to obtain a neutral pH for the

wastewater treatment plant using LabVIEW software.

4

Page 18: Ph Measure Thru Labview via Matlab

To simulate the pH level of mix tank with randomly sensed pH values and

analyzes non-linear system.

1.5 Outline of the Thesis and Contributions

The thesis consists of five chapters. The first chapter is Introduction and includes

overview background, problem statement, and outline of the project. The main idea of the

project is to control the flow rate of acid liquid and alkali liquid into the mix tank to

maintain the mix tank at neutral pH which is 7. The manner in which the flow rate is

quantified depends on whether the quantity flowing is a solid, liquid or gas. For solid, it

is appropriate to measure the rate of mass flow, whereas in the case of liquid and gases,

flow is usually measured in terms of the volume flow rate. Chapter two explains about

the Fuzzy Logic Controllers in MATLAB software. Mamdani-type fuzzy controllers is

chosen for this project since it is more suitable with the non-linear system compared to

Sugeno-type. Fuzzy Logic is a model for an alternative design methodology which can be

applied in developing both linear and non-linear systems for embedded control. By using

fuzzy logic, designers can realize lower development costs, superior features, and better

end product performance. Chapter three includes the method of using LabVIEW software

which is virtual programming software that compromise of Front Panel and Block

Diagram of the system. LabVIEW programs are called virtual instruments, or VIs,

because their appearance and operation imitate physical instruments, such as

oscilloscopes and multimeters. LabVIEW contains a comprehensive set of tools for

acquiring, analyzing, and storing data, as well as tools to help troubleshoot the codes.

Chapter four will discuss about the results of simulation, plotted graph and rule views.

5

Page 19: Ph Measure Thru Labview via Matlab

Finally, the thesis is concluded in Chapter five. The capabilities and limitations of the

proposed methods are presented. Furthermore, some perspectives for future work are

suggested.

The whole process in designing the whole project is illustrated in the flow chart of Figure

1.4. After sensed the wastewater pH value in the mix tank, the system will calculate the

concentration (M) based on the pH value. If the pH value is 7, then no acid or base will

be pumped into the mix tank but if it is less or more than 7, then it will calculate again the

concentration value so that a specific amount of acid or base will be added.

Calculate concentration(M) based on pH value

Calculate: Mole = MV/1000

Yes

Stop

pH = 7 V = ?

Mix Tank

No

pH sensed by sensor?

Start

Figure 1.4 : Flow chart of designing the whole project

6

Page 20: Ph Measure Thru Labview via Matlab

1.6 The Scope of Work

The scope of the thesis is to design and simulate a pH controller for a wastewater tank

using MATLAB Fuzzy Toolbox and LabVIEW Control Development. LabVIEW is a

kind of programming language, which allows us to connect to the external world through

a data acquisition (DAQ) card, and make changes to this external environment.

LabVIEW uses function blocks instead of written code to do this. The DAQ card

connects from the computer to the external world we wish to control. LabVIEW provides

the graphical user interface (GUI) in the front panel and graphical programming base in

the block diagram section. These features include a menu which could call the Fuzzy

logic controller (MATLAB) as the controller of the whole system and provide the ease in

integration; LabVIEW has the ability to execute MATLAB m-files.

The proposed methods are applicable to nonlinear processes, time invariant and time-

delayed processes.

7

Page 21: Ph Measure Thru Labview via Matlab

CHAPTER 2 : LITERATURE REVIEW

2.1 Related research works review

A number of approaches have been proposed in the literature in recent years to solve pH

control problems. In both nonlinear and linear control techniques, researches have been

proposed and proved on neutralization processes. Ranganath Muthu and Elamin El

Kanzi, 2003 [86] designed the combination of proportional plus integral controller (PI)

controller and fuzzy logic controller (FLC) for a simulation highly non-linear of pH

neutralization process. The paper compares the performance between PI and FLC. The

author also compares the regulatory response of the influent flow and servo response

during the neutralization process. It is shown in this paper that the FLC shows better

regulatory as well as servo response than the PI controller. The linear techniques paper

are based on using multiple linear models evaluated at several working points, for

example, the multimodel control approach proposed by Nyström et al. (1998) [87]. Using

this technique, the controller is designed based on linear quadratic (LQ) technique and

then the procedure is combined with two gain scheduling methods, which enables work

to be done over a wide range of operating points. A scheduling-gain multimodel LQ

controller can be proposed by designing an optimal linear controller for multimodel plant

representation (in which models have their stationary gains scaled to the same value). A

similar technique has been proposed by Galan et al. (2000) [88] , using robust control

based on a multi-linear model. The proposed methods try to identify the regions and then

to decompose the complex system domain, to calculate an optimal controller. It must be

8

Page 22: Ph Measure Thru Labview via Matlab

pointed out that a multi-model scheme can be classified as robust only in the sense of

accommodating a wider range of plant operation. However, it does not require detuning

in closed loop performance, as required by regular model based schemes.

Another example is in Toivonen et al. (2003) [89], where velocity-based linearized

models are proposed to modify the internal model control applied to designing scheduled

controllers. The authors applied the proposed method to a strongly nonlinear pH

neutralization process, describing the relation between variable changes, without the

necessity of a well-defined stationary gain. By modifying the IMC structure, this method

can eliminate the steady state offsets.

Although linear controllers are simple to implement, nonlinear controllers give better

performance, due to the inherent nonlinear behavior of the pH process. Nonlinear

controllers have been proposed by Narayanan et al. (1998) [90], using three process

variables (difference in hydrogen and hydroxyl ion concentrations, hydrogen ion

concentration, and pH process) and an internal model control strategy with a nonlinear

adaptive model. Nonlinear controllers have also been studied by Yoon et al. (2002) [91],

proposing back stepping techniques to handle a wide class of uncertain systems and avoid

unwanted cancellations of favourable nonlinearities.

There are also researchers interested in studying pH control using predictive control

techniques. For example, Gomm et al. (1996) [92], proposed the use of a neural

predictive strategy to study the in-line pH process. They used a nonlinear autoregressive

exogenous (NARX) model structure for the proposed approach, which was used on-line

to predict future process responses. Norquay et al. (1998) [93], have also studied the use

9

Page 23: Ph Measure Thru Labview via Matlab

of both static nonlinear elements and linear dynamic elements of the SISO Wiener

Model. The authors studied several methods to calculate the predictions: polynomial

methods, autoregressive models with exogenous inputs (ARX) and step-response models

to represent the linear dynamic element.

Although all these techniques have been proved successfully on real plants, the main

difficulty is still the necessity of developing a model that adequately represents the pH

process in any operating condition. To solve this problem, this paper discusses a

technique based on fuzzy control to design pH controllers without the necessity of any

plant model.

Babuska et al. (2002) [94], have proposed a fuzzy self-tuning PI controller for a pH

control in a fermentation system, where the essential idea is to tune the controller PI gains

on-line by means of a parameter that results from a fuzzy inference mechanism.

Most fuzzy controllers use control error (e) and change in the control error (Δe) as

controller inputs. As it is a fuzzy controller, it does not need a mathematical model of the

system to control the pH levels.

2.2 History of pH values

Acidic and basic are two boundaries that describe chemicals, just like hot and cold are

two extremes that describe temperature. Mixing acids and bases can cancel out their

extreme effects; much like mixing hot and cold water can even out the water temperature.

A substance that is neither acidic nor basic is neutral.

10

Page 24: Ph Measure Thru Labview via Matlab

2.2.1 Definition

The pH of a solution measures the degree of acidity or alkalinity relative to the ionization

of water sample. Pure water dissociates to yield 10-7 M of [H+] and [OH-] at 25 ºC; thus,

the pH of water is neutral i.e. 7.

pHwater = - log [H+] = - log 10-7 = 7

Most pH readings range from 0 to 14. Solutions with a higher [H+] than water (pH less

than 7) are acidic; solutions with a lower [H+] than water (pH greater than 7) are basic or

alkaline.

2.2.2 pH Measurement

Measuring pH involves comparing the potential of solutions with unknown [H+] to a

known reference potential. pH meters convert the voltage ratio between a reference half-

cell and a sensing half-cell to pH values.

In acidic or alkaline solutions, the voltage on the outer membrane surface changes

proportionally to changes in [H+]. The pH meter detects the change in potential and

determines [H+] of the unknown by the Nernst equation:

E = Eo + (2.3RT)/nF log {unknown [H+]/internal [H+]}………(Equation1)

where:

E = total potential difference (measured in mV);

Eo = reference potential;

R = gas constant;

T =temperature in Kelvin;

n = number of electrons;

11

Page 25: Ph Measure Thru Labview via Matlab

F = Faraday's constant;

[H+] = hydrogen ion concentration.

2.2.4 pH Temperature Compensation

The pH of any solution is a function of its temperature. Voltage output from the electrode

changes linearly in relationship to changes in pH, and the temperature of the solution

determines the slope of the graph. One pH unit corresponds to 59.16 mV at 25 °C, the

standard voltage and temperature to which all calibrations are referenced. The electrode

voltage decreases to 54.20 mV/pH unit at 0.0 °C and increases to 74.04 mV/pH unit at

100.0 °C.

Since pH values are temperature dependent, pH applications require some form of

temperature compensation to ensure standardized pH values. Meters and controllers with

automatic temperature compensation (ATC) receive a continuous signal from a

temperature element and automatically correct the pH value based on the temperature of

the solution. Manual temperature compensation requires the user to enter the temperature

of the solution in order to correct pH readings for temperature. ATC is considered to be

more practical for most pH applications.

2.2.5 pH System

A successful pH reading is dependent upon all components of the system being

operational. Problems with any one of the three which are electrode, meter or buffer will

yield poor readings.

12