The Application of Fuzzy Control in Water Tank Level Using Arduino

—Fuzzy logic control has been successfully utilized in various industrial applications; it is generally used in complex control systems, such as chemical process control. Today, most of the fuzzy logic controls are still implemented on expensive high-performance processors. This paper analyzes the effectiveness of a fuzzy logic control using a low-cost controller applied to a water level control system. The paper also gives a low-cost hardware solution and practical procedure for system identification and control. First, the mathematical model of the process was obtained with the help of Matlab. Then two methods were used to control the system, PI (Proportional, Integral) and fuzzy control. Simulation and experimental results are presented.


INTRODUCTION
The extraordinary development of digital processors (Microprocessors, Microcontrollers) and their wide use in control systems in all fields have led to significant changes in the design of control systems.Their performance and low cost make them suitable for use in control systems of all kinds that require a lot more capabilities and performance than those provided by the analog controllers.
In certain industry branches, the liquid level control problem is often encountered.The nature of the liquid and friction of control mechanism and other factors make the system nonlinear [1,2].In nowadays, the best-known industrial process controller is the PID controller because of its simplicity, robustness, high reliability and it can be easily implemented on any processor, but using a PID controller is not fully convenient when it comes to dealing nonlinear systems [3,4].But these systems can be successfully controlled using fuzzy logic controllers because of their independency from the mathematical model of the system.
In this paper, PI (Proportional, Integral) and fuzzy logic controllers are applied to water level control system; the proposed fuzzy controller has better performance than conventional control methods with a simpler algorithm that can be easily implemented on a microcontroller.The PI and fuzzy controllers are implemented on Arduino, which is an open source development board.This paper is organized as follows: in the next section, a description of the system is presented.The system identification phase and the mathematical model are presented in the 3 rd section; the 4 th section describes the PI controller implementation, the simulation, and experimental results are presented.In the 5 th section a general description of a fuzzy logic controller implementation, simulation, and experimental results are presented.The conclusion is given in the last section II.SYSTEM DESCRIPTION Adjusting a liquid level in a tank is the main objective of this work, the structure of the entire system is as shown in Fig. 1.The system consists of a water tank, a liquid level sensor, a pump based on a 12V direct current motor, an electronic circuit (Arduino and a DC/DC step-down converter).The structure chart of the water tank level system is shown in Fig. 2 which the liquid flows into the top of the tank with the help of a dc motor pump and leaves from the bottom, through a pip equipped with an adjustable valve to adjust manually the flow rate of the liquid leaving the tank and to simulate leaks (disturbances).
The Arduino is used as an acquisition board in identification phase, once the mathematical model of the system is obtained, the Arduino will play the role of an independent controller.A computer is needed to display signals and to impose set points for the controller; the computer will communicate with the Arduino through the RS232 communication protocol.www.ijacsa.thesai.org

III. SYSTEM IDENTIFICATION
To obtain the mathematical model of the process, the Arduino board was used as an interface between the computer and the system.The computer is equipped with software that can store incoming samples from the board."MATLAB identification toolbox" shown in Fig. 3 has been used to process the samples and to obtain the mathematical model of the system.Fig. 3. Graphical user interface (GUI) of the identification tool box Fig. 4 shows the open loop response of the system to a constant input u(t), 15.8cm is the final value of the output y(t) to a 7.6cm input.This difference between u(t) and y(t) corresponds to the steady-state error of 8.2 cm.That is why a controller is needed to minimize the steady-state error.The transfer function of the system was found with the help of MATLAB identification toolbox, and it is as follows: Fig. 4. Response of the system Fig. 5 represents a comparison between system response and transfer function response to the same input.And it can be seen that the transfer function response, almost matches the real system response.

IV. PI CONTROLLER
A Proportional-Integrate-Derivative controller (PID) is a control mechanism, the role of this controller is to minimize the error between a set point and the system response, the control algorithm contains three terms proportional, integrate and derivative term [5,6].The most popular controller industrial field is the PI (Proportional-Integrate) controller, and it is a special case of a PID controller, it has only two constant parameters K p and K i , where K p is the proportional gain and K i is the integral gain [7,8].The control algorithm u(t) and the controller transfer function C(p) are given by the following equations: The design of the PI controller was done using Matlab/Simulink, and it was based on the mathematical model obtained from the identification phase.The simulation is shown in Fig. 6; it was used to test the performance of the controller, the gains (K p and K i ) were calculated using pole placement method, (K p = 1.145 and K i = 0.015).Fig. 7 shows the results obtained by the simulation.

V. FUZZY LOGIC CONTROLLER
The Fuzzy Logic controller consists basically of four parts: fuzzification interface, knowledge base, inference engine, and a defuzzification interface.Fig. 9 shows the basic configuration of a fuzzy logic controller.Each of these parts plays a different role in the control process and affects the performance of the controller and the behavior of the whole system.The fuzzification is the transformation of numerical data from the input to linguistic terms.The knowledge base provides necessary information for all the components of the fuzzy controller [9][10][11].The fuzzy inference engine or the logical decision-making is the core (brain) of the controller.It is capable of simulating the decision-making of human beings.At the end of the inference step, the obtained result is a fuzzy value that cannot be directly used to control the process, so the value should be defuzzified to obtain a crisp value, and that is the role of the defuzzification interface.The fuzzy logic controller usually works with more than two input signals, the system error e(k) and the change rate in the error Δe(k).The error of the system is defined as the difference between the set point y r (k) and the plant output y(k) at a moment k: The variation of the error signal at the moment k is given by the following equation: The configuration of the proposed fuzzy controller is shown in Fig. 10.In1 is the system error, and In2 is the variation of the error signal.The simulation shown in Fig. 11 was used to test the performance of the fuzzy controller and to determine the controller gains.The design of the table below (Table .2) was based on the principles of a basic control system which are: If the error is big, and the error rate changes quickly, then the controller should eliminate the error quickly and if the error is small, and the error rate change is not fast, then the controller should eliminate the error slowly and if the error is zero, and the error rate doesn't change, then the control command should be zero.The labels inside the table are the linguistic variables.The labels in Table 2 are as follows: NG = very low, EZ = zero and PG = very high.
The values of the controller constants were found after preforming simulations in Matlab.Table 3 shows the constants values.The result of the last simulation is presented in Fig. 14.After the controller was designed and tested in Matlab/Simulink, it was implemented on Arduino to control the system.Fig. 15 presents the behavior of the system with a fuzzy logic controller.The system was subjected to disturbances (in simulation and experiment).It is seen from Figs. 7, 8, 14 and 15 that the fuzzy controller had better performance and stability in every given set point and fast error compensation.

VI. CONCLUSIONS
This paper proposed a low-cost solution to apply fuzzy logic control for a water tank level control system using an Arduino, and using it also as a low-cost acquisition board for system identification.The main objective of this work has been reached, which is to test the effectiveness of fuzzy logic control using Arduino, by comparing it to a PI controller.The general structure of both controllers (PI and fuzzy) were presented in this work.The simulations and experimental results showed the superiority of fuzzy control over the conventional control systems.

Fig. 2 .
Fig. 2. Structure chart of water tank control system

Fig. 5 .
Fig. 5. Comparison between system response and transfer function response to the same input

Fig. 7 .
Fig. 7. Behavior of the process with a PI controller (simulation) After the controller had been designed and tested in Matlab/Simulink, the function of the controller mentioned earlier was implemented in Arduino to control the system.Fig 8 presents the behavior of the system with PI controller.

Fig. 8 .
Fig. 8. Behavior of the process with a PI controller (experimental results)

Fig. 9 .
Fig. 9. Basic configuration of a fuzzy logic controller

Fig. 10 .
Fig. 10.Fuzzy controller in a closed loop system

Fig. 11 .
Fig. 11.Simulink model Using Matlab toolbox "fuzzy logic toolbox", shown in Fig. 12, a fuzzy logic controller was designed containing two inputs (error and error derivative) and one output.The proprieties of our controller are given in the Table.1. 1.

Fig. 12 .
Fig. 12. Graphical user interface of the fuzzy logic toolbox The chosen membership functions of output and input signals are all similar; they are shown in Fig. 13.

Fig. 14 .
Fig. 14.Behavior of the process with a fuzzy controller (simulation)

Fig. 15 .
Fig. 15.Behavior of the process with a fuzzy controller (experimental results)

TABLE I .
PROPRIETIES OF THE FUZZY LOGIC CONTROLLER