Design and Implementation of an Intelligent ANFIS Controller on a Raspberry Pi Nano-Computer for Photovoltaic Pumping Intended for Drip Irrigation

: For several decades, many countries have favored irrigation as a means of regulating, diversifying, and increasing agricultural production to meet the growing domestic demand for food, and even to generate exportable surpluses. As with most Mediterranean countries, Tunisia has inherited a long tradition in irrigation; thus, the management of the scarcity of water resources poses a very important challenge that is gradually increasing due to the effects of climate change undergone by the region and confronting the agricultural sector. Aiming at a new model of sustainable development, ensuring the optimization of water resources management, as well as the protection of natural resources and the environment, this work proposed the modern design of a photovoltaic pumping chain dedicated for drip irrigation, which is controlled using an intelligent neuron-fuzzy controller with an ANFIS architecture and implemented on a Raspberry Pi platform. Thanks to this design, the efﬁciency of the pumping chain increased exponentially to a value of approximately 95%, achieving water pumping optimization while exploiting renewable energy resources, thus guaranteeing the longevity of water resources, as well as the continuity of diversiﬁed agricultural production.


Introduction
The Tunisian strategic geographical location distinguishes the country with a mild climate and a mixture of geological features such as deserts, mountains, and flat lands.
The water that can be mobilized in Tunisia is estimated to be 4766 million m 3 /year, consisting of 55% of surface water collected mainly in the North and 45% of groundwater mainly located in the Center and the South [1].
Irrigated agriculture consumes 80% of available water resources, while 14% is allocated to drinking water and 6% to industry and tourism, as shown in Figure 1 [2].
According to the Office of Planning and Hydraulic Balances (2016), irrigated agriculture represents 37% of agricultural production (8% of the useful agricultural area, 27% of agricultural employment, and 20% of the export value) [2].
However, the country has 450 m 3 /inhabitant/year of water, which is below the water stress threshold (i.e., 500 m 3 /inhabitant/year), which means a serious problem of the need for water resources by 2025.
Thus, the right to water is now threatened, and it has become essential to preserve this resource and rationalize its exploitation.
Moreover, the results of the new projections published in 2018 for Tunisia by the National Institute of Meteorology (INM) indicate an increase in annual temperature forecasts for 2050 and 2100 compared to the period of 1971-2000 [2].
Consequently, average temperatures are expected to rise between 2.1 • C and 2.4 • C by 2050, and between 4.2 • C and 5.2 • C at the end of 2100; these results also predict a decrease in annual accumulations of precipitation varying between −1% and −14% in 2050 and between −18% to −27% in 2100 [2].
Thus, Tunisia would be subject to a more arid climate, gradually affecting the north of the country, as presented in Figure 2:  The decrease in rainfall would lead to a drop in water resources estimated at 28% in 2030, which would mainly affect groundwater. This risks the overexploitation of groundwater, increasing the price of access to water and degrading its quality.
Therefore, it is urgent to encourage changes in agricultural practices and innovations to meet the challenges of climate change.
Another emerging issue and at the heart of global debates in recent years is the development of renewable energies. It is no longer a choice in itself but a necessity given the three-dimensional impact of this sector, namely: economic, whose challenges are the reduction in the energy bill and the creation of jobs; environmental, as it will reduce CO 2 emissions, one of the main factors of global warming; and social, by impacting education, health, access to drinking water, and agriculture [3,4].
Regarding the Tunisian energy situation, it is marked by limited energy resources, a drop in energy production, and a strong increase in demand, hence the gap between energy production and national demand and the appearance of a deficit in the primary energy balance, which reached 49% in 2018 against 15% in 2010 [5].
Research was carried out in order to rationalize fossil resources use and to optimize water pumping control. The first studies focused on monitoring the pumping stations by means of traditional controllers such as PD or PID (proportional and derivative controller or proportional, integral and derivative controller, respectively) or their combination with scalar and vector controllers [6,7]; subsequently, a new concept emerged called a sliding mode robust controller [8].
Indeed, those controllers have well regulated the hydraulic pumping stations, but they also showed a lack of performances in term of stability, rapidity, and precision.
As a solution, and regarding the revolutionary dominance of artificial intelligence in almost all fields, research works have been directed toward regulators based on fuzzy logic [9], artificial neuronal networks [10], as well as their association known by fuzzy neuronal controllers [11].
Different models have been designed and met the challenge of improving and optimizing hydraulic pumping stations, except that the complexity of those chains poses a huge problem of unsuitable investment cost for agriculturists, hence the inspiration to provide an intelligent and efficient drip irrigation system, owning a simple architecture, and the ability to meet the functional and economic needs of beneficiaries.
This work also proposed the implementation of the ANFIS intelligent controller on an embedded Raspberry Pi target, not only for its performances compared to previous cards [12,13], but especially for its subsequent use in the IoT (Internet of Things) concept, as this platform offers internet connectivity without need of connected expensive sensors employment, thus the important scientific, economic, and social contributions of this manuscript.

Photovoltaic Pumping System
The agricultural irrigation techniques shown in Figure 3 represent the methods of providing water to crops and are classified as surface irrigation (basin, furrow, and board irrigation), sprinkler irrigation, and micro-irrigation.
Despite the antiquity of the surface water irrigation method, farmers are still maintaining its usage as a lucid, effortless, and low-priced technique, as water conserving practices, such as drip irrigation, demand further costs for the sake of investment in installation, maintenance, and energy [14,15].
Due to the minimum number of countries in Africa that financially support farmers to invest in drip irrigation, the rate of the use of motorized techniques remains low ( Figure 4) [16].
Accordingly, the investigation into how to harmonize farmers' expenses and incomes substitutes a critical concern to settle.
On the other hand, Tunisia intends to increase its energy reserves by intensifying the exploitation of its natural deposit in renewable energy, as illustrated in Figure 5 [17][18][19][20].
Investigating an evaluator such as MCDA (the multi-criteria decision analysis) is mandatory to determine which renewable energy to use in our application in terms of quality and received score [21].
According to Figure 6, the energy produced by PV modules is considered more efficient compared to other renewable energy resources; thus, its investment presents a promising field in order to reduce the use of fossil fuels.  However, several criteria must be taken into consideration before implementing the photovoltaic installation, in particular, the climatic factors of the region.
In this work, three different regions of Tunisia were studied for the purpose of installing photovoltaic pumping systems: Tunis, as a northern region; Kairouan, as a central region; and Tozeur, as a southern region, as indicated in Figure 7.  Average daylight, sunshine, high and low temperatures, and rainfall are described in Figures 8-10.
June represents the month with the longest days with an average daylight of 14.7 h in Tunis, 14.4 h in Kairaouan, and 11.7 h in Tozeur, while the month with the shortest days is December with an average daylight of 9.7 h in Tunis, 9.9 h in Kairaouan, and 6 h in Tozeur.
Warmest months, with the highest average high temperature, are July and August with 34.4 • C in Tunis, 36.8 • C in Kairaouan, and 39 • C in Tozeur, while the month with the lowest average high temperature is January with 16.2 • C in Tunis, 16.9 • C in Kairouan, and 16 • C in Tozeur.  The highest number of rainy days in Tunis is estimated as 9 days in January; nevertheless, Kairaouan and Tozeur only benefited from 5 rainy days spread over several months of the fall or winter period. Yet, July presents the month with the lowest number of rainy days for all the regions, varying from 1 to 0 days. Thus, the Tunisian climatic characteristics present a very promising natural deposit for investment in the photovoltaic solar energy sector, especially in the central and southern regions for pumping.
The proposed photovoltaic system presented in Figure 11 consists of a photovoltaic generator followed by a three-phase inverter, supplying a three-phase motor pump connected to pipes and valves.  For this installation, the tanks are always connected to each other and on the same plane; thus, Therefore, the flow equation becomes [22]: The control is ensured thanks to a Raspberry Pi platform connected to a network of sensors in order to control the inverter according to the data collected (temperature, irradiation, and water flow), which allows the characterization of this system by an optimal, economical, and flexible structure.

Design and Implementation of the Intelligent Controller
The intelligent neuron-fuzzy controller aims to create an optimized fuzzy interference system using supervised learning methods; there are three fuzzy neural architectures: the Nomura architecture, the LSC architecture, and the ANFIS architecture adopted for this work.
The Adaptative-Network-based Fuzzy Inference System (ANFIS) is a multi-layered network whose connections are not weighted, or all its weights are equal to 1.
In this design, the ANFIS controller output is connected to the input of a classic scalar controller, as shown in Figure 12: The irradiance Ec, temperature Ta of the photovoltaic panel, and the rate of water Q measured at the pump's output were used as inputs of the ANFIS controller. The frequency fs represented the ANFIS controller's output.
To train the ANFIS network, 54 datasets of irradiation Ec, temperature Ta, flow rate Q, and frequency fs were measured with the help of a FPGA board [23], on July 2020, as shown in Figures 13 and 14:  In order to simulate the intelligent ANFIS controller, it is helpful to:
Build the Fuzzy Inference System (FIS) file. Regulator structure, treated in the MATLAB-Simulink environment, is presented in Figure 16. The input membership functions of temperature, irradiance, and measured water flow rate are represented in Figure 17: Figures 18 and 19 represent the surface between two inputs and the output (Ta and Ec), (Ta and Q), (Ec and Q), and the ANFIS controller rules: Concerning Raspberry Pi, it serves as a very cheap nano-computer ( Figure 20) that runs Linux, but it also provides a set of GPIO (general purpose input/output) pins enabling the control of electronic components for physical computing and the Internet of Things (IOT) exploration [24][25][26][27].
Raspberry Pi is also characterized by its small size, high clock speed, onboard network, multitasking capabilities, large flash memory (SD card), USB inputs, operating system, and diversity of development environments (Scratch, IDLE, etc.) [28,29].
The components used for this application are: Raspberry Pi Model B+, DHT22 digital temperature and humidity sensor, KY-018 analog irradiation sensor, YF-S201 water flow sensor, moisture sensor, 9 V battery (external power), PWM control shield, mini water pump, I2C 1602 LCD, T-cobbler, breadboards, 4.7 KΩ and 10 KΩ resistors, jumper wire kit, Ethernet cable, X25 soarer charging data cable, and a computer. The Fritzing electrical diagram is presented in Figure 21.
Download and Run the python code (respecting a precise algorithm introduced in Figure 22).

Results and Discussion
The simulation results were obtained by simulating the Simulink models over a period of 10 s, which is represented in Figure 23:  Figure 24 shows a comparison between flow rate evolutions delivered by the ANFIS regulator (Qanfis) and a fuzzy regulator (Qf).
After having simulated the controlled photovoltaic irrigation system using the intelligent ANFIS controller, and after having visualized the desired behavior (flow rate reached its optimum value close to 34 L/min), the next step dealt with the controller implementation on the Raspberry Pi platform by means of the Python code ( Figure 25).  Based on the same database, a program was created that allows one to browse the data using the sensors and subsequently display the values captured, as well as the frequency fs, which presents the output of the intelligent controller block (Figure 26) and runs the motor-pump with an adequate speed. The photos below were taken while displaying the temperature, sunshine value, frequency occurred, and pump speed mode with a delay of 3 s for each display.
In the Table 1 below, an example of a comparative study is presented; it consists of taking the results of a vector and fuzzy regulators combination and then applying them as an input database for the studied ANFIS regulator by means of two different membership functions (triangular and Gaussian) in the MATLAB environment, in addition to the experimental results of the ANFIS controller implementation. As a consequence of the pumping chain dedicated to irrigation simulations, the water flow delivered by the pump was optimized to 34 L/min, in front of 29.06 L/min, for the same system and under the same conditions but by using a PI regulator linked to a scalar control (time and energy gain), and 33 L/min for a pumping chain of more complex architecture and admitting a vector control combined with a fuzzy regulator [43] (investment cost gain). Thus, under optimal conditions (T = 25 • C and Ec = 1000 W/m 2 ), this system showed a gain in efficiency ranging from 2.9% (33 L/min) to 13.9% (29.06 L/min).
Moreover, the comparison between the simulations and experimental results, under the same conditions, affirmed that the values found were very close, resulting in a low error estimated at 0.1%. Thus, the Raspberry Pi device ensured a stable behavior, as well as a robust and very promising control compared to the targets previously used such as ASICs, FPGAs, DSPs, microcontrollers, or SOCs. As a result, the concordance between the simulated and measured results was verified.
Thanks to this application, it is possible to feed the maximum of crops with the minimum of water delivered to the outlet of each dripper; it helps to irrigate, for example, 121 olive trees and 3400 carrots distributed, respectively, over an area of 5000 m 2 and 1122 m 2 . Then, Tunisian regions, especially the central and southern regions, including Kairaouan and Tozeur, will be able to guarantee the conservation of large hydraulic resources and the minimization of polluting fossil resources use through the adoption of sustainable renewable energies, particularly solar photovoltaic energy, allowing its energy and water self-sufficiency with the least expenditure.
It is also important to mention that this design is not only promising for Tunisia, but also for any other country in the Mediterranean region, as well as the entire African continent. It therefore provides the possibility to innovate old projects and research works, including the study dedicated to the oases of Mauritania presented in [44].

Conclusions
This article focuses on the intelligent fuzzy neuron control and its implementation on an embedded target. The objective was to offer an intelligent and efficient ANFIS regulator allowing the control of a photovoltaic pumping system dedicated to drip irrigation, as well as its implementation on the Raspberry Pi 3 Model B+ platform.
The system response was stable, fast, and optimized with an efficiency of 95%, despite the robustness of antecedent regulation methods such as fuzzy logic, sliding mode, or adaptive control. This work proved a valuable contribution thanks to the dynamics of the system in front of fluctuating and improvised climatic correlations such as shading or the sudden drop in temperature.
In addition, the material design is ready to be invested in the IOT concept; the perspectives of this research work will therefore be focused on the phenomenon of smart irrigation.