You are on page 1of 15

Water Bath using Fuzzy Logic Controller

Izzul Haziq Yuslee


School of Electrical Engineering
Faculty of Engineering
Universiti Teknologi Malaysia

Abstract-This paper describes the development of a water bath temperature controller using the fuzzy logic controller.
The development of this model is using the MATLAB Fuzzy Logic Toolbox and MATLAB Simulink. The objective of this
water bath is to achieve output temperature close to the set temperature by the user. The system utilised seven linguistic
variables and 49 rules were developed. The popular Max-Min method was used for the inference process, while Mean of
Maximum (MoM) for the aggregation. The result of the developed model demonstrated a good performance by achieving
near to the desired set point. Some modification or tuning needs to be done to get accurate results yet produce a good
performance in terms of stability, smooth and most minor overshoot.

I. INTRODUCTION

A water bath is commonly used in laboratories and manufacturing productions for experimental purpose. Some of
the known brands that are using water bath are Nestle and F&N. The objective of this apparatus is to control precisely
the temperature of the water in the vessel. It is crucial to reach the desired temperature points quickly and to avoid
large overshoot. Lack of proper control will result in defective products or damage to the plant. Hence, a suitable
temperature controller for a water bath is one of the industry's standard requirements.

A conventional controller such as PI and PID controller are classical control algorithms in process control. It has
been widely used for decades due to its robustness and effectiveness for a wide range of operating conditions.
However, significant disadvantages of these conventional controllers are prone to the change in system parameters,
delays and non-linearities. In order to overcome these issues, numerous studies have been to implemented another
alternative technique [1]. One of the proposed ideas is to design the controller using artificial intelligence (AI)
technique such as Fuzzy Logic (FL), Artificial Neural Network (ANN) or hybrid. Therefore, this paper discussed
designing a water bath control system using a fuzzy logic controller (FLC).

Fuzzy logic is widely used in real-life applications such as washing machine, oven and air-conditioning. Due to its
advantages, fuzzy logic also has been used in many industrial applications in process control. One of the major
advantages is that this technique can operate rationally to produce acceptable results in a complex system, even dealing
with inaccurate inputs [2]. Hence, the fuzzy logic can be used in designing the temperature controller for the water
bath.
II. THEORETICAL BACKGROUND

A.Basic Configuration of Fuzzy Logic Controller

The fuzzy logic controller has successfully designed by engineers is based on fuzzy set theory. FLC system
architecture consists of four components that are fuzzification, rule base, inference and defuzzification [3]. Figure 1
displayed the basic configuration of the fuzzy logic controller.

Figure 1. Fuzzy logic controller architecture

First and foremost is fuzzification. Fuzzification is transforming crisp sets into fuzzy sets. Crisps are always referred
to as the input values of FLC, and it should be agreed with the fuzzy values so that the FLC can read the process. A
fuzzy partition that spans the input domain for each input variable must be constructed, and it determines how many
terms exist in a set.

The second stage is rule base, and sometimes it also can be called the knowledge base. Any knowledge related to the
process to be controlled defined in this stage. According to Honda & Ohsato in [3], the common practice to develop
fuzzy rules is by combining some of the methods below;

1. The knowledge of the operator and control engineers experience


2. Based on the operator's control actions
3. Based on the fuzzy modelling of the process
4. Based on the learning process
The inference is a decision-making process in the system. The FLC used membership function (MF), fuzzy set
operation, and rule base to operate efficiently. After computes the value for the consequent part, it then undergoes
either one of the inference processes (e.g., max-min, product-max or product-sum). Min operator used when the two
inputs operated with AND while max is applied during the aggregation method. Max-min is a common approach
where the output membership function clips to the corresponding minimum value between the MF value due to the
rule's condition [4].

Defuzzification is a final stage where it is the reverse of fuzzification. Defuzzification determines the crisp output
by resolving the fuzzy set output. There are five defuzzification methods: centroid, bisector, mean of maximum, largest
of maximum, and the smallest of maximum [5]. This paper focused on the mean of maximum (MoM) defuzzification
method due to its accuracy and simple calculation. In MoM, the defuzzified value can be computed by using the
formula in equation 1. The method is graphically represented in Figure 2 below.

Generally, the formula is


𝑆𝑂𝑀 + 𝐿𝑂𝑀
μ= (1)
2

Where
μ is the final defuzzified value
SOM is the smallest of maximum
LOM is the largest of maximum

Figure 2. Graphical representation of MoM defuzzification method [6]

B.Defining the Membership Functions

The equation for each membership function for every input and output must be identified to evaluate any FLC.
Usually, the membership function has its own piecewise functions depending on its shape. In this section, the
triangular and trapezoidal shape will be discussed. Refer figures and equations below for more details.
Figure 3. Membership of triangular shape

0, 𝑥 ≤ 𝑎 𝑜𝑟 𝑐 ≥ 𝑥
𝑥−𝑎
, 𝑎≤𝑥≤𝑏
𝜇𝐴 (𝑥) = 𝑏 − 𝑎 (2)
𝑐−𝑥
, 𝑏≤𝑥≤𝑐
{𝑐 − 𝑏

Figure 4. Membership of trapezium shape

0, 𝑥 < 𝑎 𝑜𝑟 𝑥 > 𝑑
𝑥−𝑎
, 𝑎≤𝑥≤𝑏
𝑏−𝑎
𝜇𝑃 (𝑥) = 1, 𝑏≤𝑥≤𝑐
𝑑−𝑥 (3)
{𝑑 − 𝑐 , 𝑐≤𝑥≤𝑑

The equation in 2 and 3 is beneficial when evaluating any FLC. The detailed explanations were shown in the next
section by making the developed FLC as an example.

III. METHODLOGY

This section discussed the designing process of a fuzzy logic water bath controller. The controller is named as WBS,
which will improve the system outcome. The controller controls the output voltage of the water bath using the
knowledge base that was decided earlier. The designing process of the controller and the system model involved
several stages have been described below.
A.Fuzzy Inputs, Output and Linguistic Variables

Table 1 Fuzzy inputs, output and linguistic variables of WBS controller


Inputs Output
Temperature error, et Rate of change of error, ∆et Control voltage, u
Negative Big (NB) Negative Big (NB) Negative Big (NB)
Negative Medium (NM) Negative Medium (NM) Negative Medium (NM)
Negative Small (NS) Negative Small (NS) Negative Small (NS)
Zero (ZE) Zero (ZE) Zero (ZE)
Positive Small (PS) Positive Small (PS) Positive Small (PS)
Positive Medium (PM) Positive Medium (PM) Positive Medium (PM)
Positive Big (PB) Positive Big (PB) Positive Big (PB)

The fuzzy WBS controller was adopted from a typical fuzzy controller with two inputs and one output. Each of
them has seven linguistic variables (LV), which can be referred to Table 1. The inputs are temperature error (Et) and
rate of change of error (∆Et), while the output is the control signal (u). Three of them are having the same linguistic
variables, which are negative big (NB), negative medium (NM), negative small (NS), zero (ZE), positive small (PS),
positive medium (PM) and positive big (PB).

B.Fuzzy Membership Functions

The fuzzy set of WBS controller has the same range [-1 1] for the inputs while the output was limited to the range
of [0 5]. The membership function for all the variables uses a typical triangular shape except for the negative big and
positive big variables using the trapezoidal shape. The seven fuzzy sets are utilised with equal based and overlapped
more than 25%. The figures below demonstrate the membership function for each input and output.

Figure 5. Temperature error (Et) membership functions


Figure 6. Rate of change of error (∆Et) membership functions

Figure 7. Control signal (u) membership functions

After creating the membership functions in MATLAB fuzzy inference system (FIS), each of them could be defined
using the formula in equation 2 and 3. For example, the membership functions for each linguistic variables in input Et
are described below. Since the input ∆Et has the same range and MF's shape, each LVs will have the same equation
described in input Et.
0, 𝑥 > −0.6
1, − 1 ≤ 𝑥 ≤ −0.9
𝜇𝑁𝐵 (𝑥) = { −0.6 − 𝑥
, −0.9 ≤ 𝑥 ≤ −0.6
−0.6 − (−0.9)

0, 𝑥 ≤ −0.9 𝑜𝑟 𝑥 ≥ −0.3
𝑥 − (−0.9)
, −0.9 ≤ 𝑥 ≤ −0.6
𝜇𝑁𝑀 (𝑥) = −0.6 − (−0.9)
−0.3 − 𝑥
, −0.6 ≤ 𝑥 ≤ −0.3
{−0.3 − (−0.6)

0, 𝑥 ≤ −0.6 𝑜𝑟 𝑥 ≥ 0
𝑥 − (−0.6)
, −0.6 ≤ 𝑥 ≤ −0.3
𝜇𝑁𝑆 (𝑥) = −0.3 − (−0.6)
0−𝑥
, −0.3 ≤ 𝑥 ≤ 0
{ 0 − (−0.3)

0, 𝑥 ≤ −0.3 𝑜𝑟 𝑥 ≥ 0.3
𝑥 − (−0.3)
, −0.3 ≤ 𝑥 ≤ 0
𝜇𝑍𝐸 (𝑥) = 0 − (−0.3)
0.3 − 𝑥
{ 0.3 − 0 , 0 ≤ 𝑥 ≤ 0.3

0, 𝑥 ≤ 0 𝑜𝑟 𝑥 ≥ 0.6
𝑥−0
, 0 ≤ 𝑥 ≤ 0.3
𝜇𝑃𝑆 (𝑥) = 0.3 − 0
0.6 − 𝑥
{0.6 − 0.3 , 0.3 ≤ 𝑥 ≤ 0.6

0, 𝑥 ≤ 0.3 𝑜𝑟 𝑥 ≥ 0.9
𝑥 − 0.3
, 0.3 ≤ 𝑥 ≤ 0.6
𝜇𝑃𝑀 (𝑥) = 0.6 − 0.3
0.9 − 𝑥
{0.9 − 0.6 , 0.6 ≤ 𝑥 ≤ 0.9

0, 𝑥 < 0.6
𝑥 − 0.6
𝜇𝑃𝐵 (𝑥) = { , 0.6 ≤ 𝑥 ≤ 0.9
0.9 − 0.6
1, 0.9 ≤ 𝑥 ≤ 1
For the output u, since the range is different from the inputs, it leads to slightly different piecewise functions. Refer
below equations for output u piecewise functions.

0, 𝑢>1
1, 0 ≤ 𝑢 ≤ 0.25
𝜇𝑁𝐵 (𝑢) = { 1 − 𝑢
, 0.25 ≤ 𝑢 ≤ 1
1 − 0.25

0, 𝑢 ≤ 0.25 𝑜𝑟 𝑢 ≥ 1.75
𝑢 − 0.25
, 0.25 ≤ 𝑢 ≤ 1
𝜇𝑁𝑀 (𝑢) = 1 − 0.25
1.75 − 𝑢
{ 1.75 − 1 , 1 ≤ 𝑢 ≤ 1.75

0, 𝑢 ≤ 1 𝑜𝑟 𝑢 ≥ 2.5
𝑢−1
, 1 ≤ 𝑢 ≤ 1.75
𝜇𝑁𝑆 (𝑢) = 1.75 − 1
2.5 − 𝑢
{2.5 − 1.75 , 1.75 ≤ 𝑥 ≤ 2.5

0, 𝑢 ≤ 1.75 𝑜𝑟 𝑢 ≥ 3.25
𝑢 − 1.75
, 1.75 ≤ 𝑢 ≤ 2.5
𝜇𝑍𝐸 (𝑢) = 2.5 − 1.75
3.25 − 𝑢
{3.25 − 2.5 , 2.5 ≤ 𝑥 ≤ 3.25

0, 𝑢 ≤ 2.5 𝑜𝑟 𝑢 ≥ 4
𝑢 − 2.5
, 2.5 ≤ 𝑢 ≤ 3.25
𝜇𝑃𝑆 (𝑢) = 3.25 − 2.5
4−𝑢
{ 4 − 3.25 , 3.25 ≤ 𝑢 ≤ 4

0, 𝑢 ≤ 3.25 𝑜𝑟 𝑢 ≥ 4.75
𝑢 − 3.25
, 3.25 ≤ 𝑢 ≤ 4
𝜇𝑃𝑀 (𝑢) = 4 − 3.25
4.75 − 𝑢
{4.75 − 4 , 4 ≤ 𝑢 ≤ 4.75

0, 𝑢<4
𝑢−4
𝜇𝑃𝐵 (𝑢) = { , 4 ≤ 𝑢 ≤ 4.75
4.75 − 4
1, 4.75 ≤ 𝑥 ≤ 5
C. Fuzzy Rules

The rules base can be formed according to our desired outcome, and it has been tabulated in Table 2. There were
49 rules developed for this controller since there are 7 inputs x 7 inputs. In FIS, these rules can be developed using
rule editor as shown in Figure 8 while the surface viewer in Figure 9. Besides, this system also using the Max-Min
approach for the inference process.

Table 2 Fuzzy rule base for WBS controller

Et
Rules for u
NB NM NS ZE PS PM PB

NB NB NB NB NB NM NS ZE

NM NB NB NB NM NS ZE PS

NS NB NB NM NS ZE PS PM

∆Et ZE NB NM NS ZE PS PM PB

PS NM NS ZE PS PM PB PB

PM NS ZE PS PM PB PB PB

PB ZE PS PM PB PB PB PB

Figure 8. The rule editor for knowledge base in WBS controller


Figure 9. The surface viewer for WBS controller

Figure 10. The chosen inference method for the WBS controller

D. Defuzzification

The process of mapping fuzzy sets into a crisp value is called defuzzification. To demonstrate this process, we need
to evaluate the rule. Rule evaluation can be done manually using the theoretical method or using the rules viewer
feature in FIS. In this paper, both methods are shown in order to verify the manual calculation. As mentioned in the
previous section, this controller used the mean of maximum (MoM) method for defuzzification. Take the example for
the input Et is 0.4 and ∆Et is -0.8 as shown in Figure 11.
Figure 11. The intersection when Et = 0.4 and ∆Et = -0.8

When the Et is equal to 0.4, it intersects with two MFs in blue colour that is 𝜇𝑃𝑆 and 𝜇𝑃𝑀 . From the intersection,
𝑥 values can be calculated using the suitable piecewise equation. Then,

0.60 − 0.40 2
𝜇𝑃𝑆 (Et) = = ,
0.3 3

0.4 − 0.3 1
𝜇𝑃𝑀 (Et) = =
0.3 3

When the ∆Et is equal to -0.8, it intersects with two MFs in red colour that is 𝜇𝑁𝐵 and 𝜇𝑁𝑀 . From the intersection,
𝑥 values can be calculated using the suitable piecewise equation. Then,

−0.60 − (−0.8) 2
𝜇𝑁𝐵 (∆Et) = = ,
0.3 3

−0.8 + 0.9 1
𝜇𝑁𝑀 (∆Et) = =
0.3 3

From above four equations leads to four rules that need to evaluate,
1. Et is positive small AND ∆Et is negative big
2. Et is positive small AND ∆Et is negative medium
3. Et is positive medium AND ∆Et is negative big
4. Et is positive medium AND ∆Et is negative medium

Since the antecedent part is connected by AND operator, we use min operator to evaluate the strength of each rule:
2 2 2
Rule 1: min ( , ) =
3 3 3
2 1 1
Rule 2: min ( , ) =
3 3 3
1 2 1
Rule 3: min ( , ) =
3 3 3
1 1 1
Rule 4: min ( , ) =
3 3 3
Since this controller used the mean of maximum (MoM) defuzzification technique. Then, the maximum strength of
the rule need to be determined by
2 1 1 1
Maximum rule = max ( , , , )
3 3 3 3
2
= ( this correspond to rule 1)
3

Rule 1: If the Et is positive small and ∆Et is negative big, then u is negative medium. To find out the final
defuzzification value, take the average of 𝜇𝑁𝑀 (𝑢). The 𝜇𝑁𝑀 (𝑢) provides two piecewise functions of

u1 − 0.25 2
𝜇𝑁𝑀 (𝑢) = =
0.75 3
3
u1 =
4

1.75 − u2 2
𝜇𝑁𝑀 (𝑢) = =
0.75 3
5
u2 =
4

The final value can be obtained by using equation 1. The final u value is
3 5
+
𝑢=4 4
2
𝑢=1

The rule viewer can validate the result in the FIS. The simulation outcome obtained was portrayed in Figure 12.
From the figure, it shows that the calculated result obtained similarly to the simulation value. In brief, the rule
evaluation method shown to defuzzification is valid.

Figure 12. The rule evaluation using simulation


E.Designing Water Bath Model in Simulink

Designing the water bath model in Simulink is based on a simple closed-loop system. It also can be modified from
the common fuzzy-PID controller for any type of control system. The water bath model using a fuzzy logic controller
designed in Simulink was shown in Figure 13.

Figure 13. The water bath model designed in Simulink

The system was adopted from the previous author's Fuzzy-PID control system [7], [8]. However, some modification
needs to be done to ensure the output produces a reliable outcome. The WBS controller acted as the main controller
in the closed-loop system, and it will tune the voltage output online before go through the plant model. The transfer
function is stated in equation 4.
0.26
𝐺(𝑠) = (4)
𝑠 + 0.9969

The transfer function G is derived from the continuous time of the water bath temperature control system and has
been Laplace transform to make it fit into the system. By taking some constant values, the equation can be expressed
as shown in the equation above. Besides, the final simulated discrete-time linear equation for the control plant also
can be in the form as shown in equation 5. However, in the Simulink model, this paper used the transfer function in
equation 4. The more profound discussion about this derivation can be analysed in the reference paper [8].

(5)
𝑦(𝑘 + 1) = 0.988𝑦(𝑘) + 0.222𝑢(𝑘)

IV. RESULTS & DISCUSSIONS

A water bath control system was designed as presented in the previous section using FLC. The desired temperature
was customised using the signal builder feature in Simulink. It was portrayed in Figure 14 and Figure 15 demonstrated
the simulation result of the water bath temperature controller. In Figure 16 and Figure 17 shows the detailed
temperature outcome for the water bath.
Figure 14. The desired temperature for water bath

Figure 15. The simulation graph of the water bath model

Figure 16. The simulation result of the water bath model when the desired temperature was 40°C
Figure 15. The simulation result of the water bath model when the desired temperature was 65°C

There was two different temperature which was 40°C and 65°C for a different period. Based on the figures above,
this system produced acceptable outcomes when there are changes in the temperature set point. In details, the outcome
produced approximately 39.5°C when the setpoint was 40°C for the period of 10 seconds to 35 seconds. Besides, the
system able to reach approximately 64.2°C when the setpoint was 65°C for the period of 35 seconds to 80 seconds.
Therefore, we can conclude that this model is rational when it comes to outcomes. However, several factors need to
consider and improve to achieve the best result.

V. CONCLUSION
The gain parameters of FLC can be tuned for this water bath model to get the best result. The tuned parameter,
which is GE=0.01, GDE=0.01, GU1=20 and GU2=250, needs to re-tune to improve current performance. In terms of
overshoot time and system stability is not considered. Therefore, for future recommendation, this system should be
considered all the parameters needed to get an accurate result. In conclusion, the designed system is satisfactory with
the desired temperature and sudden changes.

REFERENCES
[1] O. P. Verma, R. Singla, and R. Kumar, "Intelligent Temperature Controller for Water Bath System," World Acad. Sci. Eng. Technol. Int.
J. Comput. Information, Syst. Control Eng., vol. 6, no. 9, pp. 1232–1238, 2012.
[2] A. Masoumi and I. Azad, "The Challenges and Advantages of Fuzzy Systems Application," no. May, 2020, doi:
10.13140/RG.2.2.22310.96328.
[3] N. HONDA and A. OHSATO, Fuzzy Set Theory and Its Applications, vol. 13, no. 2. 1986.
[4] S. Javidbakht, "Design of a Controller To Control Light Level in a Commercial Office," p. 105, 2007.
[5] "Fuzzy Inference Process - MATLAB & Simulink." https://www.mathworks.com/help/fuzzy/fuzzy-inference-process.html (accessed
Feb. 02, 2021).
[6] "Fuzzy Methodologies for Automated University Timetabling Solution Construction and Evaluation by Hishammuddin Asmuni , MSc,"
no. June, 2014.
[7] H. Liao, X. Sheng, and D. Yang, "Design of adaptive lighting system based on fuzzy PID," Proc. 30th Chinese Control Decis. Conf.
CCDC 2018, pp. 1543–1547, 2018, doi: 10.1109/CCDC.2018.8407372.
[8] H. G. Verma, Om Prakash, "Fuzzy Logic Based Water Bath Temperature Control System," vol. 2, no. 4, pp. 333–336, 2012.

You might also like