DESIGN AND IMPLEMENTATION OF FLC APPLIED TO A SMART GREENHOUSE

Greenhouse cultivation needs an accurate modelling and an optimised control system to ensure an adequate microclimatic condition for plants. It represents a complex task due to the high number of input factors. For this reason, an improved intermediate modelling was established under the platform of the MATLAB/Simulink environment to simulate the energy balance and the fuzzy logic controller (FLC) in order to promote a suitable microclimate through the control of the relevant actuators which have been installed in the greenhouse. In addition, the control of the system has been improved through the integration of the Internet of things for data monitoring and recording in real time. The system was designed, prototyped, and tested in Tunis province of Tunisia. Our contribution through this work represents the implementation of the FLC on a Raspberry Pi 3, and the management of the agriculture through the use of a digital innovation (IoT). All this has allowed us not only to supervise, control and reduce the energy cost of electrical load but also to improve the productivity and quality of the greenhouse cultivation.


INTRODUCTION
Global energy demand will have almost doubled by the end of the next decades, and the demand for water and food is also expected to increase by more than 60% (Ahemd et al., 2016). A serious global issue should be resolved to satisfy food security and the future global demand. Open field growing has been identified as a significant obstacle, mainly in countries with unsuitable weather conditions. However, greenhouses offer a proven alternative to protect the canopy from disease and adverse climatic conditions, but the problem of a such solution is its energy consumption which should be decreased by an optimised control system (Anand, 2016;Atia & El-Madany, 2016) and a meticulous design which takes care of several factors (Belkadi et al., 2019;Chhaya et al., 2017): solar radiation, temperature, wind speed, humidity, cover materials, etc.
To fulfil these needs, several control strategies including complex and sophisticated algorithms have been developed and discussed in the literature, such as fuzzy systems that have obtained considerable benefits. Some researchers have been interested in the use of adaptive predictive command, proportional-integral-derivative controllers (Ge et al., 2016;Ma et al., 2019), PI-SSOD and SSODPI techniques (Malathi et al., 2017), the genetic algorithm (Manonmani et al., 2017), and nonlinear adaptive PID control (Maurya & Jain, 2016). However, these techniques need to be enhanced to improve the control efficiency of their systems. Other researchers have been interested in control by adaptive neural network neuro-fuzzy technology control (ANFIS), artificial neural network control (ANN) (Mohamed & Hameed, 2014), or hybrid systems using artificial intelligence to control the greenhouse microclimate (Orujova et al., 2018). These systems have shown success, but these systems remain inefficient since neural networks do not produce the necessary information regarding their findings, which restricts the analysis of the current phenomena. A decentralised fuzzy logic controller has been implemented (Pawlowski et al., 2016;Rycerski et al., 2017). The model has shown reliable target tracking compared to the traditional techniques of control.
The challenge of this study consists, first of all, in controlling and supervising the parameters of the greenhouse by adopting an efficient control system capable of regulating the internal parameters of the Engenharia Agrícola, Jaboticabal, v.40, n.6, p.777-790, nov./dec. 2020 greenhouse in real time and offering the possibility of recording the data for possible improvement. Hence, there is a need to implement an IoT system. Another major challenge consists in miniaturising the current fuzzy logic control solutions which are mainly equipped with a computer and Matlab software, in order to reduce the investment costs and make it standalone.
In the first section of this paper, we studied the energy balance inside the greenhouse. Secondly, a fuzzy logic control technique was implemented to overcome the phenomenon of the nonlinearity and complexity of the system. Finally, a smart automated system has been implemented and used for IoT data monitoring and manual control for critical intervention.

Smart greenhouse architecture
In this section, we present an overview of the designed system. Figure 1 illustrates a synoptic diagram of the different components of the studied system. FIGURE 1. System overview.
Our system is based on a star network topology, in order to facilitate the integration of new devices and/or the extension of existing structures, as well as limiting the risk of having an entire system down and any communication problems. In order to verify the effectiveness of the control of our system, we should first of all check the accuracy of the interaction between the different components of the system, which is essentially based on the energy balance.

Energy balance design
Our model, named BGHM, has been developed to combine the traditional parameters involved in the heat transfer equation such as Qsr, Qcd-cv, and Qinf (Tuncer et al., 2017;Xiaoli & Peng, 2011;Zhang et al., 2019;Zeng et al., 2012;Xiong et al., 2012) and the addition of a new amount of heat transfer that has been neglected by the majority of previous studies, such as Qli, Qp, Qf, and Qlw.
Heat gain from solar radiation -Qsr: This quantity represents the heat gain from the short-wave solar radiation. It depends mainly on the solar intensity, the greenhouse area, and the transparency of the covering material. This quantity is expressed according to [eq (1)]. sr sr f

Q I A =
(1) Heat gain from lighting equipment Qli represents the quantity of heat emitted by the lighting system. This amount of energy has been neglected. However, (Chouchaine et al., 2011) has shown that this heat gain has a significant impact on the energy consumption. This quantity is expressed according to [eq. (2) Heat loss due to conduction and convection -Qcdcv: This amount of energy represents the heat loss due to the conduction and the convection. It depends on many parameters because its overall heat coefficient depends on several parameters, like air velocity, wind speed, temperature, etc. This quantity is expressed according to [eq. (3)] and [eq. (4)].
Heat loss due to infiltration -Qinf: Infiltration heat is defined as the amount of energy lost inside a greenhouse. The heat can escape through fissures, opened windows or other gaps in the structure. A greenhouse is a regulated enclosure, so that excessive heat loss due to infiltration is a significant issue for the producer. This quantity is expressed according to [eq. (5) Heat loss due to long-wave radiation -Qlw: Most commonly, the thermal radiation coming from inside the greenhouse can be partially absorbed by the cover, reflected or transmitted to the outside. The long-wave heat transfer through the cover has a considerable influence on the heat loss. It could increase or decrease depending on the transparency of the installed glazing. This amount of heat can be expressed as shown in eqs (6) and (7).
Soil heat loss Qf and the heat due to the perimeter -Qp: Most of the quantity of the heat losses produced by the greenhouse soil are due to the conduction of the ground and the transfer of heat emitted by the perimeter. This quantity is determined according to [eq. (8)] and [eq. (9)].
Heat loss due to evaporation -Qevap: Evapotranspiration in particular should not be overlooked when establishing the energy balance equation, since it represents a considerable quantity of heat loss. It is generated from the plant leaves as well as from the soil surface. This quantity is expressed according to eqs (10) and (11).
This theoretical development allows us to deduce the Tin and Hin based on the heat and water balance by using eqs (12) and (13). Where: HE is the vapour transfer rate, and Hinf is the water exchange by ventilation rates.

Energy balance simulation and validation model
The developed model has been implemented in Simulink to simulate the internal temperature and internal humidity of the greenhouse; the model is represented as shown in Figure 2. Engenharia Agrícola, Jaboticabal, v.40, n.6, p.777-790, nov./dec. 2020 The evolution of the internal temperature and the internal humidity without control are displayed as shown in Figure 3 and   Figure 3 shows well that the evolution of the internal temperature depends on the variation of the external temperature. In the morning, the difference between the internal and the external temperature is more important than the difference between them at night: when the outdoor temperature reaches 28 °C, the indoor temperature increases to reach 32 °C in the morning, while at night it decreases by only 2 °C and this is expected as the solar radiation does not have an impact at night.  Figure 4 shows that the evolution of the internal and external humidity is the opposite of the variation of the temperature. They increase during the night to reach their highest level and decrease in the daytime to their lowest level, particularly when the sun's radiation is at its peak.
After simulating the internal parameters of the greenhouse, we then proceeded to the measurement of these two factors. Figure 5 represents the temperature data recorded in the web application while Figure 6 represents the overlap of the simulated and measured data in order to verify the accuracy of the designed system.
Engenharia Agrícola, Jaboticabal, v.40, n.6, p.777-790, nov./dec. 2020 FIGURE 5. Web application data of the internal measured temperature. FIGURE 6. Evolution of the simulated and the measured internal temperature. Figure 5 and Figure 6 show well that the measured internal climate parameters and the simulated ones are very close, so we can conclude that our designed system is very accurate.
After verifying the effectiveness of the developed model, we will move on to the control of the greenhouse using FLC methodology.

Fuzzy control design
Fuzzy logic is a field of mathematics and, as a result, a certain amount of fundamental concepts has been developed. These concepts are applied to explain and prove some basic principles. In order to regulate our system, a fuzzy logic controller has been carefully designed. It was realised with five steps: 1) Fuzzification of the digital inputs based on measurement of the internal parameters through the use of the input adhesion functions.
2) Applying rules to the FLC operators 3) Performing and executing implication. 4) Aggregating each output of rules into a common fuzzy set.

5)
Defuzzifying the aggregated fuzzy set through the use of the technique of the centre of gravity output rounded to the nearest integer in order to achieve the control of the system.
The FLC is used in this study to maintain the humidity and air temperature inside the greenhouse to their target value by activating the installed actuators installed inside the greenhouse at the suitable time with the adequate capacity. The new internal parameters could be calculated as shown in eqs (14) and (15) Hhum and Hdehum are, respectively, the humidifying and dehumidifying rates of water, and Qheater and Qventilation are, respectively, the heat gain from heating actuators and the heat loss due to activation of the ventilation actuators. The developed control model can be represented as shown in Figure 7 and Figure 8.  Figure 7 shows two FLCs which are connected to the greenhouse. The first one is mainly applied for controlling the inner temperature, and its input variable corresponds to the temperature error while its output variables correspond to the heating and ventilation rates.
The second controller is used to regulate the inner humidity, and its input corresponds to the humidity error while its output parameters correspond to humidification and dehumidification rates.  Figure 8 shows the detailed Simulink block modelling used for controlling the inside parameters of the greenhouse, where the red blocks correspond, respectively, to the actuators used for the regulation of the inner temperature and humidity.

b) Temperature FLC Rules
The FLC rules used for the control of the temperature are presented as shown in Table 1.

c) Temperature FLC Data
By referring to Figure 12, we can deduce that the FLC successfully controls the internal temperature of the greenhouse, which is maintained and regulated around the target set points 20 (°C).

Humidity FLC a) Humidity FLC Memberships
The membership functions of the developed FLC applied to the internal air temperature and the internal humidity are given as shown in Figs. 15-17. Engenharia Agrícola,Jaboticabal,v.40,n.6,nov./dec. 2020  The FLC rules used for the control of the humidity are presented as shown in Table 2. By referring to Figure 18, we can deduce that the FLC successfully controls the internal humidity of the greenhouse, which is maintained and regulated around the target set points (70%).

SYSTEM IMPLEMENTATION
A prototype of the studied agricultural greenhouse system was designed, implemented and tested in Tunis province of Tunisia. The shape of the designed system is a small evan span (w = 200 mm, L = 500 mm, H = 300 mm) covered by a 2 mm glass material.
The proposed prototype as shown in Figure 21 was equipped within a Raspberry Pi 3, with two DHT11 sensors to monitor the internal and external humidity and temperature. We have also installed and connected the required actuators in order to regulate the internal humidity and temperature (heater, fan, humidifier, dehumidifier). FIGURE 21. Dehumidification rate.

FLC implementation on the Raspberry Pi 3
The fuzzy logic controller was implemented on a Raspberry Pi 3 that regulates and supervises the environmental factors inside the greenhouse through the use of the Python language and the use of the skfuzzy module.    We conclude that for an input temperature error ΔT of −5, i.e. for a set point temperature of 5 °C higher than the measured temperature, the output of the recorded control is 75% for heating and 21.4% for ventilation. Figure 24 shows the input and the output of FLC implemented on the Raspberry Pi through the use of the Python language.   The simulation results of the two figures show that the actuators, relative to the heating and the ventilation systems, operate, respectively, in the ranges [5.40] and [60.90], which agree closely with the values displayed in Table 1.  By referring to Figure 27 and Figure 28, we notice that for a set point temperature of 5 °C higher than the measured temperature, the output of the recorded control is 75% for heating and 21% for ventilation.
As a conclusion, we deduce that we have a good agreement between the results of the simulated FLC through the Matlab software and the FLC implemented on the Raspberry Pi.

CONCLUSIONS
This research has shown that the climatic conditions inside the greenhouse are not necessarily favourable for plant development. This is why we have set up an IoT system to control and supervise the internal parameters of the greenhouse. Indeed, we first developed an improved model called BGHM to estimate the internal parameters of the greenhouse. The system showed excellent accuracy with a defect rate of only 7%. Then, we implemented a fuzzy logic control system, which showed its efficiency. This controller allowed us to regulate the internal temperature and humidity through proper management and control of the actuators in order to obtain the desired values. Finally, we implemented the FLC designed on the Raspberry Pi using the Python language and the skfuzzy module. This technique has achieved the same values as the FLC simulated by the Matlab programme and allowed us to miniaturise the system in order to reduce the total price of the proposed solution and make it standalone.