EMBEDDED FUZZY CONTROLLER FOR APPLICATION IN IRRIGATION SYSTEMS

This paper describes the modeling, implementation, and evaluation of a control system based on an embedded fuzzy controller for application in irrigation systems. The motivation for the development of this system comes from the need to offer farmers resources that provide a reduction in water and electricity consumption in irrigation, which contributes to reducing production costs and preserving natural resources. The proposed control system aims to keep the water flow constant, as close as possible to the desired value and independent of load variations. A single-board computer, with the fuzzy controller software, a frequency inverter to control the speed of the irrigation motor pump system, and a flow sensor to measure the water flow, was used to implement the system. The proposed control system was evaluated in laboratory and field experiments to simulate real operating conditions. The results showed that the system presents satisfactory performance, representing a viable alternative for application in general irrigation systems.


INTRODUCTION
Irrigation systems are critical to maintaining the modern standard of living all over the world. Current levels of food production would not be possible without their use. Irrigation systems allow for greater productivity per area, independence from rainfall for production, and a higher number of production cycles per year (Guilhoto, 2007).
Irrigation can cause negative environmental impacts, such as leaching of nutrients and potentiated erosion, despite the benefits provided. However, these impacts do not necessarily result from the irrigation application itself, but from how it is performed. Positive environmental impacts and improvements in sustainability can be achieved using the appropriate irrigation technique for agricultural cultivation (Lichtenberg, 1988).
In addition, irrigation systems often require large amounts of water and electricity to operate, which are often wasted due to system inefficiency. One way to minimize the effects caused by irrigation and increase its efficiency is to use advanced irrigation systems, which include some form of process control.
However, there are barriers to adopting these advanced irrigation systems to amplify benefits and limit losses. The main limitations are the initial investment required and periodic maintenance. These limitations affect particularly small and medium producers, which are the majority in Brazil (Guilhoto, 2007).
One of the critical elements in an irrigation system is the centrifugal pump, which is mechanical equipment, usually driven by an electric motor and which converts the applied power into flow. The power required for the pump to reach a given flow rate is a function of the head of the system. In general, the flow provided by the pump in irrigation systems is dependent on the number of water emitters and the required energy demand.
Hydraulic controls, which consist of equipment capable of introducing additional hydraulic head losses to artificially increase the head of the system and thus reduce the flow, can be used for a given desired flow. However, this type of control causes energy waste since part of the power applied to the system is lost in the form of a pressure drop.
Pump control in irrigation systems can also be performed by electrical or electronic equipment, and various types of control can be used. Conventional control methods are based on mathematical modeling of the system to be controlled. These methods have been successfully used in several areas (Fang et al., 2006). However, most physical systems in the real world are dynamic and non-linear, which makes their modeling difficult or often unfeasible.
The so-called fuzzy control represents an alternative to the use of conventional control methods. One of the main features of fuzzy control, which is based on the theory of fuzzy systems (Kinsner et al., 2009), is to provide a formal methodology for representing, manipulating, and implementing human heuristic knowledge about how to control a system (Guo et al., 1999).
The focus in the design of conventional controllers is to obtain a model described by differential equations, while the focus in the design of a fuzzy controller is to obtain an intuitive understanding of how to better control the process and transfer this information directly to the controller. Fuzzy control has been successfully used in several areas due to its advantages over conventional controllers, especially in the industrial area (Assmann et al., 2017;Batista et al., 2011;Batista et al., 2015).
In recent years, fuzzy controllers have also been proposed in the literature for application in irrigation with different objectives. Miqoi et al. (2014) presented an intelligent irrigation system based on fuzzy control, in which the water pressure in each branch of the irrigation system is kept stable by controlling the pump rotational speed. A pressure sensor is used in each branch to transmit the water pressure to the controller. This system was evaluated only in computer simulation to demonstrate the increase in irrigation efficiency by the use of fuzzy control.
Nnamani (2021) demonstrated a fuzzy controller for use in the simultaneous control of water circulation and heating in a greenhouse. The water is kept in circulation employing a pump and the greenhouse is heated using a gas heater. This controller was implemented in an embedded system and installed on a test platform for performance evaluation. Kushagra et al. (2018) presented a comparison between different types of control applied to irrigation from classic PID controllers (proportional, integral, and derivative) to intelligent controllers, such as the fuzzy controller. The authors suggested an advanced control system that monitors a set of environmental variables to determine the amount of applied water. This system was evaluated only conceptually, without any demonstration of practical application. Eldain et al. (2017) presented a fuzzy controller for use in the simultaneous control of water pressure and flow in an irrigation system. The fuzzy controller was specifically designed for an irrigation system whose mathematical model was known a priori. This controller was evaluated in computer simulation and experiments using a test bench that emulates the irrigation system. Putra (2005) demonstrated an irrigation control system based on fuzzy control, which controls the amount of applied water from the measurement of soil moisture in the irrigation system. An experimental irrigation plant was used to evaluate this system and specifically demonstrate water savings compared to the traditional irrigation management technique.
Moreover, Belkadi et al. (2020) suggested a fuzzy control system to promote an adequate microclimate in greenhouses by controlling the water, heating, and cooling applied to the environment. This system was implemented in software using the MATLAB/Simulink platform for model validation. A prototype was also implemented in an embedded system for performance evaluation but tested only in an experimental greenhouse.
This study proposes a control system based on a lowcost and easy-to-implement embedded fuzzy controller, aiming at its application in irrigation systems, especially by small and medium-sized producers so that they can obtain greater benefits from irrigation and become more competitive in agricultural production market. This system aims at a higher control in the use of water in irrigation, assisting in reducing water and electricity consumption and, consequently, increasing irrigation efficiency.
The remainder of this study is structured as follows: the second section presents the proposed control system; the third section presents the embedded system developed to implement the control system; the fourth section presents the results obtained from experiments; and the fifth section presents the conclusions.

Proposed control system
The control system proposed in this study employs the fuzzy controller in a closed-loop control system, as shown in Figure 1. The fuzzy PD (proportional-derivative) controller model, which has gained popularity in the application of induction motor control to drive centrifugal pumps, such as those used in irrigation systems, was chosen for this study.
Its main advantages over other controllers are reduced computation time, faster projects, and fewer errors (Baburajan & Ismail, 2017). In the block diagram, the controller inputs are the error and the error variance, represented by e(t) and de(t)/dt, respectively. These inputs are calculated from the reference, represented by r(t). The input and output of the plant are represented by u(t) and y(t), respectively. The fuzzy controller consists of four main parts: a rule base, which represents the knowledge of how to control the system in the form of fuzzy if-then rules; an inference mechanism, which evaluates which control rules are relevant at any given moment and decides which should be the input to the plant; the fuzzification interface, which modifies the inputs to be interpreted and compared with the fuzzy rules in the rule base; and the defuzzification interface, which converts the conclusions reached by the inference engine into plant inputs.
In this control system, the fuzzy controller can be seen as an artificial decision-maker, which operates in a real-time closed-loop control system. The controller takes the plant output y(t), compares it with the reference input r(t) to determine the error e(t) and the error variance de(t)/dt, and then decides which one should be the plant input u(t) to achieve the desired goal, which, in this case, is to keep the plant output as close as possible to the reference value.
The designer must create the rule base from information obtained from experts in the process to design the fuzzy controller and must also choose the inference mechanism to be used, as well as specify the fuzzification and defuzzification interfaces. All these choices will affect the controller performance, which must be evaluated after the project by some analysis method or even by simulation or experimentation (Guo et al., 1999).
The control system shown in Figure 2 is suggested to allow the use of a fuzzy controller in irrigation systems. The system consists of the following components: the fuzzy controller (implemented in a computer system), a frequency inverter, a motor-pump assembly, a flow sensor, and two interfaces associated with the inverter and the sensor.
The motor-pump assembly is the equipment capable of moving water in the pipeline. It simply accelerates its maximum rotation without any control, moving the largest volume of water possible through the pipe at the shortest possible time. A frequency inverter, which is the equipment that controls the electric power in the motor and, consequently, controls the water volume moved by the pump, is used to allow the control of the water volume to be applied in irrigation.
The electric power in the motor is determined by the control signal produced by the fuzzy controller and applied to the frequency inverter input. This signal is produced by measuring the water flow in the pipeline through the flow sensor. The function of the fuzzy control is to determine the electric power in the motor to keep the water flow in the pipe constant and as close as possible to the reference value to be defined by the system user.
The inverter and sensor interfaces consist of electronic circuits, necessary to match the characteristics of the signals received and sent by these components with the characteristics of the outputs and inputs of the computer system, respectively. In addition, the interfaces also contribute to the protection of the computer system against possible electrical disturbances.
Rule base Fuzzy controller Control system implementation An embedded system was developed especially for this application for the implementation of the proposed control system. The system hardware is based on a Single Board Computer (SBC). In this study, the Beaglebone Black board (https://beagleboard.org/black), which belongs to a low-cost open-source hardware platform focused on embedded system applications, was chosen because of its resources (such as processor, memory, and interfaces), availability, and the amount of technical documentation available. Figure 3 shows the Beaglebone Black board and Table 1 shows its main characteristics.
A WEG CWF-10 Easydrive frequency inverter was used in this study (https://static.weg.net). This model is part of a family of inverters intended for controlling and varying the speed of three-phase induction electric motors up to 5.0 hp. They have various software features and interfaces for local or remote operations.  This inverter model was chosen mainly due to its ease of interfacing with the control system, as it has a 0-10V analog input that allows controlling the output frequency remotely. Figure 4 shows the CWF-10 Easydrive frequency inverter. The interface circuit shown in Figure 5 was designed for connecting the frequency inverter to the Beaglebone Black board. The board does not have analog outputs, but a digital output was used to produce a PWM (Pulse Width Modulation) signal, which is converted by the circuit into a DC voltage whose value is directly proportional to the duty cycle of the PWM signal.
The circuit consists of an active low pass filter (Ponnambalam et al., 1999), formed by the operational amplifier (U2A) and RC network (R4 and C1) connected to the non-inverting input. The input PWM signal with an amplitude of 3.3 V is isolated from the circuit by the optocoupler (U1) and then amplified by the transistor (Q1). This signal has its amplitude limited to 10 V by a Zener diode (D1), being applied to the input of the active low pass filter, which then supplies a DC voltage variable from 0 to 10V at the output of the circuit. This circuit is powered by an external 12V power supply. The flow sensor chosen in this study is the YF-DN50, capable of measuring a flow from 0 to 200 L/min in 2″ diameter pipes (https://www.whiteint.co.nz). The flow sensor provides information regarding the measured flow in the form of a square-wave voltage signal whose frequency is directly proportional to the flow. This sensor model was chosen mainly due to its low cost compared to other sensor models of the same type. Figure 6 shows the YF-DN50 sensor. The interface circuit shown in Figure 7 was designed to connect the sensor to the Beaglebone Black board. It consists of a Schmitt Trigger comparator (Ponnambalam et al., 1999), formed by the operational amplifier (U2A) and resistive networks connected to the non-inverting input (R1, R2, R4, R6). The square-wave voltage signal provided by the sensor with an amplitude of 5 V is converted by the comparator into a signal with an amplitude of 12 V and applied to the optocoupler (U1), which provides the isolated output signal of 3.3 V amplitude. This circuit also favors the elimination of noise in the sensor signal. This circuit is powered by an external 12V power supply. FIGURE 7. Interface for the flow sensor.
The embedded system software has the main code, which consists of the implementation of the fuzzy controller, and auxiliary codes, which perform functions such as reading the flow sensor signal and generating the PWM signal for the frequency inverter.
The Mamdani-type fuzzy inference system, which is characterized by using fuzzy sets in both the antecedents and the consequents of the rules and is one of the most used in the applications of fuzzy systems, was chosen to implement the fuzzy controller in this study (Kinsner et al., 2009). The definition of the fuzzy rule base was performed using the strategy called grid partition, in which the universe of discourse of each input variable is divided into a certain number of uniformly distributed membership functions. In this case, seven triangular membership functions were used for each input variable in a universe of common discourse between [−1, 1]. Figure 8   The number of fuzzy rules in a Mamdani-type fuzzy inference system is equal to p n (p is the number of membership functions per input and n is the number of inputs) and, in this case, the rule base is composed of 49 rules. Table 2 shows the rule base, in which each rule is defined by the intersection of a row and column. For example, the first rule can be described as: If (error is LN) AND (error variance is LN) Then (output is LN) The center area defuzzification method was chosen to calculate the output value of the fuzzy controller. This method allows obtaining the crisp value (numerical value) from the fuzzy value produced at the controller output (Kinsner et al., 2009). This conversion is necessary because the control system output signal is used as the plant control signal.
The fuzzy controller response can be represented by the surface shown in Figure 9, sometimes called the "control surface". This surface represents the nonlinearity implemented by the fuzzy controller, being affected by all its main parameters. FIGURE 9. Control surface of the fuzzy controller.
The system software was developed using the GNU/Linux Debian 10 operating system and Python 3 programming language. The Adafruit Beaglebone I/O Python API library was also used (https://github.com/adafruit/adafruit-beaglebone-iopython). This library allows access to the hardware resources (such as digital inputs and outputs and PWM outputs) of the Beaglebone Black board from programs written in Python language.

Results of experiments
A prototype of the control system proposed in this study was assembled and evaluated in laboratory and field experiments.
Laboratory experiments were conducted at the Laboratory of Electronics, located at the State University of Montes Claros (UNIMONTES), and aimed to prove the system's functionality. Devices were used to simulate the inputs and outputs of the system and measuring instruments to observe the signals. The experiments showed that the system worked according to the design.
Field experiments were conducted at the experimental area located at the Institute of Agricultural Sciences (ICA) of the Federal University of Minas Gerais (UFMG) and aimed to evaluate the system performance. A hydraulic plant consisting of a motor pump set powered by a 220V three-phase voltage, a water reservoir, valves, and pipes was prepared to allow the experiments to be carried out. The pump is used to take water from the reservoir, which circulates through a pipe with derivations, being directed back to the reservoir. Thus, the plant allows tests to be carried out for as long as necessary. The valves were used to simulate the load increase in the irrigation system and reproduce operating conditions found in a real system.
The experiments were divided into four different scenarios, aiming to evaluate the control system performance in four different operating conditions. The performance metrics used were the relative error (E) and the mean absolute error (MAE), defined in (1) and (2), respectively, where ^ is the measured value, is the reference value, and is the number of samples.
In the first scenario, the control system was evaluated in the operating condition of the irrigation system with open-loop control under no-load condition. The controller in open-loop control does not use the information from the plant output (feedback) to perform the control. In this case, for a given reference input value, the plant output is expected to reach that value after a given time. Figure 10 shows the result of this experiment. The reference value of the flow for this experiment was adjusted to 25, 75, and 125 L/min at pre-defined time intervals. The result shows that the measured value of the flow presents a difference relative to each reference value during the entire time interval in which the experiment was carried out. Moreover, the relative error varies considerably with each adjusted reference value and a mean absolute error of 17.2 L/min was obtained.
In the second scenario, the control system was evaluated in the operating condition of the irrigation system with open-loop control under load condition. In this case, the load is added by closing valves installed in the water outlet pipe. Figure 11 shows the result of this experiment. The same reference values for the flow and time intervals of the experiment conducted in scenario 1 were used for this experiment. The result was similar to that of scenario 1, but the differences between reference and measured values were lower with the load addition. However, the relative error varies considerably in this experiment with each adjusted reference value. Furthermore, the mean absolute error value was equal to 11.7 L/min.
The results obtained in the experiments carried out in scenarios 1 and 2 show that an irrigation system operating without the effective action of a control system cannot obtain precise control of the water flow.
In the third scenario, the control system was evaluated in the operating condition of the irrigation system with closed-loop control under no-load condition. Unlike open-loop control, the controller under closed-loop control uses information from the plant output to perform the control. In this case, the controller action aims to reduce the difference between the reference value and the measured value so that the plant output is as close as possible to that desired. Figure 12 shows the result of this experiment. The same reference values for the flow and time intervals of the experiments performed in the previous scenarios were used for this experiment. The result of the experiment shows that the measured value of the flow was close to the reference value at each time interval. It also shows a lower variation in the relative error for each adjusted reference value. A lower mean absolute error was also obtained, which was equal to 5.1 L/min.
In the fourth scenario, the control system was evaluated in the operating condition of the irrigation system with closed-loop control under load condition. In this case, the load addition was performed as in the scenario 2 experiment. Figure 13 shows the result of this experiment. The same reference values for the flow and time intervals of the experiments performed in the previous scenarios were used for this experiment. The result was similar to that of scenario 3, which demonstrates that the measured value of the flow remained close to the reference value at each time interval even with the load addition. A reduction in the variation of the relative error for each reference value was also observed, as well as a lower mean absolute error, in this case equal to 4.8 L/min.
The results obtained in the experiments conducted in scenarios 3 and 4 demonstrate that the control system applied to an irrigation system was efficient in controlling the water flow since both the variation of the reference value of the flow and the load addition had little influence on the process.

CONCLUSIONS
The control system using the embedded fuzzy controller proposed in this study presented a satisfactory performance in controlling the water flow in irrigation systems. The results demonstrate that the control system can maintain the water flow close to the reference value even with the load variation in the system.
Considering the equipment and components used to implement the system, the control system is viable for application in irrigation systems in general, especially for small and medium-sized producers, who can achieve better results in agricultural production with low investment.
For future studies, we suggest the evaluation of the control system using other fuzzy controller models, such as a controller based on neuro-fuzzy networks or evolutionary fuzzy systems. The use of the control system in other larger projects, such as an agricultural production management system, is also suggested. Finally, we also suggested the comparison of the control system with traditional systems applied in complete crop cycles and with different crops.