Renewable Energy Integration Into Cloud & IoT-Based Smart Agriculture

Water is becoming scarcer. The unmonitored control and the extensive use of fossil fuel in water-table pumping for irrigation exacerbate global warming and harm the environment. Along with the rapid population growth and the concomitant increase in the demand for food, optimal usage of water-table and energy is becoming a must and indispensable for sustainable agriculture. In this context, Smart Agriculture (SA) is emerging as a promising field that leverages ICT (Information and Communication Technology) to optimize resources’ usage while enhancing crops’ yields. In this paper, we present an integral SA solution that leverages cost-effectiveness. Commercial solutions are costly and thus become impossible to adopt by small and medium farmers. Our solution revolves around three main axes: 1. Smart Water Metering promotes optimal usage and conservation of water-table (a.k.a., groundwater) via real-time data collection and monitoring using a Cloud-based IoT (Internet of Things) system; 2. Renewable-Energy integration promotes energy-efficient agriculture by reducing reliance on fossil fuels in water-table pumping, and 3. Smart Irrigation to promote good crops quality and quantity without harming the soil and the water-table ecosystems. Our solution has been deployed and tested in a real-world Smart Farm testbed. The results have shown that the adoption of our SA system reduces the amount of water consumption (with a traditional irrigation system) up to 71.8%. Finally, our solution is open-source and can be easily adopted and adapted by other researchers to promote the setting of a dedicated Cloud-based platform for water-table usage, especially in arid and sub-Saharan countries.


I. INTRODUCTION
Water is the basis and the main engine of life on earth. Humans use water for industrial purposes, sanitation, and irrigation. In the last decades, the annual water withdrawal ranged between 11 billion and 15 billion cubic meters per year, out of which 69 % is used in agriculture [1]. Unfortunately, most of this water is wasted because of inadequate irrigation control systems. As in most arid and sub-Saharan countries, agriculture in Morocco is the largest consumer of fresh water, especially after launching the Green Plan The associate editor coordinating the review of this manuscript and approving it for publication was Emrecan Demirors . program in April 2008 [2]. This program aims to promote agriculture as an efficient sector capable of advancing the economy, fighting poverty, and preserving many people in rural areas efficiently and sustainably. Within the framework of this program, the government provided many facilities and assistance to farmers and investors in irrigated agriculture to provide enough basic food for local consumption and export promotion programs. However, the level of Smart Agriculture penetration in Morocco remains very low.
In addition, investors in the irrigated agricultural projects started sounding alarms of severe depletion of groundwater on the horizon [3] and the lack of a cost-effective realtime data collection in irrigation systems in farming fields VOLUME 10, 2022 This work is licensed under a Creative Commons Attribution 4.0 License. For more information, see https://creativecommons.org/licenses/by/4.0/ that will enable them to benefit from the advanced modern technologies. There is a need to develop a cost-effective and sustainable data acquisition system for smart agriculture applications in sub-Saharan fields for sustainable, efficient, and smart agriculture. The system should use renewable energy and the latest Information and Communication Technologies (ICT) that can sustain the aridity of an agricultural environment. When combined with reasonable control and management and data analytics, the data acquisition system can play an essential role in increasing agricultural productivity and improving the quality of crops. Most importantly, unlike the traditional methods of irrigated agriculture that widely use underground water reservoirs and resort to fossil fuels, especially gas, as a source of energy. Smart agriculture (SA) exploits modern management systems to rationalize water consumption and adopt renewable energies as a source of energy, thus rendering the agricultural sector eco-friendly.
In this paper, we are presenting an integral and cost-effective SA solution. When approached from a Cyber-Physical System (CPS) perspective [4], our solution relies on four main ICTs: 1. A Wireless Sensors Network (WSNs) monitor, in real-time, the plant environmental conditions, e.g., weather and soil conditions, 2. A Wireless Actuators Network (WAN) acts upon electric appliances such as water pumps and light bulbs, 3. A Cloudbased IoT platform for real-time data storage, processing, and visualization; and 4. A Fuzzy Logic Control module decides on monitoring irrigation durations based on the real-time acquired differences between desired and ambient soil moisture. We deployed our open-source software solution for data acquisition, actuation, and control. We built our cost-effective sensors and actuators using off-the-shelf cheap nano-Arduinos. Finally, we leveraged an existing free Cloud-based IoT platform, e.g., NodeRED [5].
In this paper, and by considering optimal water-ground usage, renewable energy integration, and open-source ICTbased smart irrigation, we aim to contribute towards the smooth penetration of Smart Agriculture into underprivileged sub-Saharan countries. We are further envisioning, through this work, to set a solid cornerstone for establishing a dedicated Cloud-based and HPC (High-Performance Computing) platform [6] to collect real-time data about water-table usage. This data, which falls under the big data category, as it bears the big data 3Vs (Volume, Velocity, and Variety) [7], and along with appropriate Big Data Analytics tools, will tremendously assist in promoting eco-friendly smart agriculture.
The paper contributions are as follows: -We present a real-world, cost-effective, and easy-todeploy general architecture for a Smart Farm testbed that the research community can easily adopt and adapt for further testing and improvement. -We detail how to use open-source software and leverage Cloud Computing for wireless sensor data storage and processing.
-We demonstrate the integration of our developed cost-effective wireless sensors and actuators using offthe-shelf hardware in a real-world case study. -We show how integrating renewable energy into smart farms paves the path towards adopting our solution in off-grid sites, e.g., arid and sub-Saharan areas. -We prove that by adopting fuzzy logic into smart drip irrigation, our system reduces water consumption by up to 71.8%, thus contributing to sustainable water-table usage.
The rest of the paper is organized as follows. The background is presented in Section 2, and the related work is overviewed in Section 3. The general system architecture and design are described in Section 4. In Section 5, we discuss the results and evaluate the findings. Finally, in Section 6, we conclude and present our future work.

A. SMART AGRICULTURE AS A CYBER-PHYSICAL SYSTEM
The rapid technological developments of the Internet of Things (IoT), WSN, and Embedded Systems in recent years have enabled the development of modern systems and applications that have completely changed our lives. CPSs are among the most powerful of these modern systems, and Smart Agriculture is a CPS.
CPS refers to systems that ideally integrate software and hardware components to perform precise tasks. A formal definition states: ''Cyber-Physical System is defined as transformative technologies for managing interconnected systems between its physical assets and computational capabilities'' [8].
As shown in Fig. 1, the general CPS architecture combines embedded computing, wireless sensors, and actuators networks to monitor and control the physical environment and give it the ability to adapt itself to new conditions in real-time through feedback loops. Its ability to combine different technologies and make them integrated has made CPS a crucial technological revolution that brings innovation to multiple industries by replacing traditional processes in many application areas with new and modern ones.
Smart agriculture is one of the most promising CPS applications that will positively affect human life. SA can preserve a significant amount of water and energy through its ability to monitor multiple resources such as irrigation and solar energy systems. As a CPS, it replaces the traditional agricultural system with a smart and modern one that provides accurate agricultural management by collecting and processing data related to the plant, the weather, and the soil, in real-time mode and using precise control methods. The interaction of the main components of SA as a closed-loop control CPS is depicted in Fig. 2. This figure includes the field, the control center, the Wireless Sensors and Actuators Network (WSAN), and the drip irrigation system.

B. WIRELESS SENSOR NETWORKS (WSN)
The rapid developments in wireless communication technologies, micro-electromechanical systems, and digital electronics have given rise to WSN [9]- [11]. The latter consists of sensor nodes that monitor the agricultural environment needed data, such as temperature, humidity, soil moisture, motion, and pressure, and send through a gateway towards the data processing server(s). This data can be hosted locally or remotely in the Cloud [12]. Once processed and analyzed, it becomes information that can be visualized (e.g., using plots and charts) and sent to the control unit to react upon and take actions, e.g., switching On/Off water pumps and drip irrigation motors. One of the main advantages of WSN is that it reduces the cost of wiring and makes it practical and easy. According to some studies, WSN will have the ability to eliminate from 20% to 80% of the installation costs [13].
The general structure of a wireless sensor node is depicted in Fig. 3 and consists of four units [14]: -The Sensing Unit consists of sensor modules that sample the environmental conditions of the deployment field. -The Processing Unit consists of a microcontroller with a CPU and memory to run code and process the data. -The Transmission Unit: This unit modulates digital data and sends it wirelessly. Several wireless technologies are adopted for this unit. In our deployment, we are using ZigBee [15]. -The power Supply Unit is the Lithium-ion (Li-ion) battery that powers the wireless sensor node.

C. INTERNET OF THINGS (IoT)
With the rapid advancement in ICT, today's era has left the concept of the internet far behind, and a new concept has emerged: the IoT. There are many definitions of IoT set by many organizations working globally. ITU-T (International Telecommunication Union Telecommunication Standardization Sector) has defined IoT as ''Global infrastructure for Information Society, enabling advanced services by interconnecting (physical and virtual) things based on existing and evolving, interoperable information and communication technologies'' [13]. [16] defines IoT as a technology that combines the internet and existing resources to control devices. This control is ensured by using various IoT communication technologies such as Bluetooth, ZigBee, Long-Range (Lora), Zensys Wave (Z-Wave), SigFox, Wi-Fi, GPRS, 4G, and 5G [17]. Even though IoT is mainly about connecting and automating things (objects) over the internet, human intervention gives this concept the possibility of existence. The interrelationship between the three sections that make up the IoT is illustrated in Fig.4.
IoT is witnessing continuous progress and has a promising future. Statistics indicate that the number of IoT-connected VOLUME 10, 2022 devices is expected to rise to 43 billion devices by 2023 [18]. Furthermore, the total IoT market worldwide was worth around $ 389 billion in 2020, and it is expected to rise to more than one trillion US dollars in 2030 [19]. This optimistic future vision reinforces the necessity to develop newer communication technologies that enable the synchronization of the largest possible number of new devices with sensors over the internet. Fig.5 shows the persistent increase in connected devices/things over the internet for ten years (2015-2025) [20]. Given that IoT is a fertile research area that both the academic and industry sectors are interested in, all indications show an urge to deploy novel technologies to cope with the rapid increase in IoT deployment and adoption. In this regard, 5G and its Massive Machine Type Communication (mMTC) component is excellent news for the IoT market, and it will have a significant impact on it [19]. Through mMTC, 5G networks will inevitably improve the reliability and performance of many vital ICT-related domains of substantial interest to society, such as smart mobility, smart grid, smart buildings, and smart agriculture. The following section presents some critical IoT applications in SA.

D. IoT APPLICATIONS IN SMART AGRICULTURE
IoT and connected objects have invaded our daily lives in all fields, from smart TVs to connected cars: all our activities are facilitated by these new tools, which significantly increase our comfort. All studies confirm that the potential of connected things is enormous. For example, a study done by Fortune Business Insight indicates that the global IoT market size is projected to reach $ 1,854.76 billion by 2028. It is set to exhibit a Compound Annual Growth Rate (CAGR) of 25.4% during the forecast period between 2021 and 2028 [21]. The applications of IoT are numerous and cover many areas. The most appealing IoT applications in Agriculture are presented next.

1) SMART GREENHOUSES
Greenhouse farming enhances the quality and quantity of crops production through manual control of environmental conditions [22]. A smart greenhouse can be created using IoT by deploying sensors and motors that intelligently monitor and control the climate conditions based on the needs of the plants [23]. Several operations will be automatic by adopting this innovative agricultural system, such as opening and closing windows, adjusting the cooling and heating system, and turning on/off light bulbs. Thus, manual intervention is no longer required.

2) SMART IRRIGATION MANAGEMENT
The currently adopted irrigation methods are somewhat advanced and depend on watering at specific times, which does not require much human intervention. Still, at the same time, it involves a high degree of guesswork and can be very wasteful in terms of water and energy consumption. Some field parts are under or over irrigated even with modern irrigation systems. Besides, although farmers would stop irrigation systems when expected to rain, sometimes they do not check the weather to adjust their schedules accordingly. The smart irrigation management system can consider all of this by using precision farming methodologies and IoT-enabled sensors that monitor soil moisture levels, humidity, and temperature everywhere in the field. The control based on this data automatically adjusts irrigation schedules. It also provides the exact amount of water where and when needed to create optimal conditions for the plant for a better yield without wasting water and energy.

3) INTEGRATION INTO SMART GRID
Renewable energy integration into Smart Agriculture would serve as a bias to link Smart Farms to Smart Grids (SG) [17]. Smart farms are both energy producers and consumers. An SG is an electricity distribution network that promotes the flow of information between suppliers and consumers to adjust the flow of electricity in real-time and allows more efficient management of the electricity network [24], [25]. Smart grid benefits from the significant development that IoT and embedded systems are witnessing to optimize energy production, distribution, consumption, and storage. It improves the energy efficiency of the assembly by minimizing line losses and optimizing the yield of the means of production used, taking into consideration the real-time consumption.

E. CLOUD-BASED BIG DATA ANALYTICS PLATFORMS
This study uses Node-RED, an open-source flow-based programming tool that allows wiring hardware devices, application programming interfaces (APIs), and online services. We used the built-JavaScript-based library on Node.js to develop the application. We wired pre-programmed nodes represented by appropriate icons and created the application's different needed functional IoT components.
Node-RED contains several node types, each of which has a specific function. For instance, the debug-out nodes are used to monitor the flow. The inject nodes trigger a flow manually by clicking on it or automatically at regular intervals. The function nodes allow JavaScript code to be run on the messages passed through it. Furthermore, dashboard nodes allow us to display data [26].
In this work, we wired up input, output, and processing nodes to create needed flows for data preprocessing, processing, storage, and controlling the water pumps and the lighting system, as well as sending alerts. The deployed Node-Red flow construction of our irrigation control system is depicted in Fig. 6.

III. RELATED WORK
Several studies have been carried out in Smart Agriculture (SA). Authors in [27] covered state of the art in SA systems from a big data perspective. Their work aimed at introducing big data processing into SA. Besides, the authors presented a detailed evolution of the different agricultural systems was presented. It showed that SA could explore the full potential of information communication technology (ICT) by using various data sources.
In [28], D. Glaroudis et al. provided a detailed survey about the most used messaging protocols in IoT applications. Based on the up-to-date references, they introduced, analyzed, and compared six protocols: Advanced Message Queuing Protocol (AMQP), Message Queuing Telemetry Transport (MQTT), Constrained Application Protocol (CoAP), Extensible Messaging and Presence Protocol (XMPP), WebSocket, and Data Distribution Service (DDS). The performance comparison was based on throughput, latency, power consumption, bandwidth, reliability, and security. The main challenges that are and will be raised by SA applications were also presented in this paper to provide a solid basis for realistic implementation options for SA applications.
Authors in [29] highlighted the importance of IoT and WSN in precision agriculture. The development of a low-cost system that monitors, controls, and makes decisions, was presented. According to the results, the deployed system showed meaningful improvement in the efficiency of resources usage and crops production.
Another model of a low-cost, effective irrigation system for enhancing cotton production using wireless sensors was proposed in [30]. The proposed wireless sensor showed excellent efficiency in monitoring the soil water tension, thus implementing an effective irrigation scheduling protocol.
Authors in [31] deployed small-sized and low-cost WSN nodes to improve potato yield by monitoring the field. This study presented a model for irrigation management based on mathematical estimations of the agricultural parameters. The obtained results ensure better crop yield quality even under stressful environmental conditions. Besides, the irrigation system efficiency showed an increase that goes up to 10%.
In [32], the authors concluded that environmental conditions monitoring is crucial to increasing agricultural yield. In this direction, a smart system was deployed to monitor soil moisture, temperature, humidity, and the movement of animals in the field. The system used Arduino-based sensors. Besides, the suggested system deployed an Android mobile application that schedules the irrigation, visualizes real-time data, and alerts the farmer in case of any discrepancy. The IoT-based SA system farmer-friendly, which is an intelligent system for monitoring the concentration of nitrates in groundwater without human intervention, has been established in [33]. The proposed approach was based on WSN using Wi-Fi and LoRa for data communication. The results demonstrated that the model is ambitious and can be adopted by the farmers on large scales.
The authors in [34] performed an experimental comparison of IoT devices with solar energy harvesting. For the sake of the comparison, they used three different communication technologies: Wi-Fi, LoRaWan, and ZigBee. The results proved that LoRaWan was the best solution for agricultural monitoring when prioritizing network lifetime. The research work in [35] defined SA as the application of modern ICT into agriculture. They presented the usable IoT hardware and software for smart agriculture and shared interesting results. A practical solution for sustainable irrigation in hyper-arid regions was proposed in [36]. The suggested solution is based on fuzzy logic combined with WSN. According to the results, vast amounts of water and energy were saved through effective irrigation scheduling and management processes. For environmental sustainability, authors in [37] developed a system that retrieves real-time data and uses it to accurately determine the amount of water needed to irrigate the garden. The results of this real-world prototype showed savings between 26% and 34% in water consumption. Still, the results depend on whether the temperature sensor is used alone or humidity and soil moisture sensors.
Similar to Industry 4.0 [38], ''Agri-Food 4.0'' was introduced in [39]. Inspired by the concept of ''agriculture 4.0'', it aims to meet the challenge of enhancing the performance of the agricultural supply chain using efficient and effective methods and procedures. The authors have conducted a comparative analysis of more than 100 research papers on the new technologies and the latest available supply chain approaches. This analysis aims to prospect the future of Agri-Food and answer the relevant outstanding questions, e.g., how Agri-Food can better support supply chain decision-making?
Escamilla-García et al. in [40] proposed the use of artificial neural networks (ANNs) in precision agriculture. According to the authors, these models can be developed to adapt to new technologies such as IoT, Big Data, and Machine Learning (ML) and eventually improve the agriculture field. The feedforward architecture is predominant in most of the works analyzed in this paper, while the recurrent and hybrid neural networks are less used. The benefits and shortcomings of using ANNs in different greenhouses applications such as microclimate prediction, control of carbon dioxide, and energy expenses are also featured.
In [41], the authors proposed Agrinex, a modern irrigation mechanism that helps preserve resources by using WSAN. This mechanism can be an alternative to the traditional methods used to control agricultural irrigation. Agrinex is based on a mesh network consisting of nodes distributed in the field and act simultaneously as sensors detecting soil moisture, temperature, and humidity. Some nodes of the mesh network act as actuators that control the valves of the drip irrigation system. The results show that Agrinex is a promising start for many other WSAN applications in the agricultural sector.
A GSM-based smart irrigation system was presented in [42]. GSM was used to communicate environmental data such as the soil moisture, the temperature in the field, the solar power data, and the status of the water pumps. Fuzzy Logic control has been exploited in this study to take input from sensors (soil moisture, temperature, and humidity) and decide on the water pump status as output. This system has several advantages. The most important ones are the availability of a mobile application to remotely monitor the irrigation system and its ability to switch Off the water pumps when expected to rain. Compared to manual flooding, the results showed that this smart system proved its efficiency in conserving water and energy. A system that relies on solar energy to cope with water and energy shortages was developed in [43]. This system uses Wi-Fi technology to provide the control unit with data related to the soil and the weather in the field where they are deployed to decide whether to send a switch On command to the pumps to irrigate the area or not. Besides, the designed controller monitors the water level in the well and operates in three different modes: manual mode, mobile control mode, and fuzzy logic control mode. The developed prototype solely relied on solar energy. Moreover, it successfully proved its In [44], Y. P. Lin et. argue that the next step in the evolution in Smart Agriculture will consist of blockchain usage. They proposed an ICT e-agriculture system using blockchain infrastructure.

IV. SYSTEM ARCHITECTURE AND DESIGN
Our proposed system consists of seven main elements, see In addition to that, this platform controls the drip irrigation and lighting system within the farm. We deployed this component using a Raspberry Pi along with Node-Red. The latter is a local server containing a control unit running algorithms to decide whether to pump water from groundwater to basin via water pump #1 or from basin to the drip irrigation system via water pump #2. 3) Wireless Actuator Network (WAN): It consists of actuators carrying out decisions issued by the BDAP by switching On/Off the water pumps and the lighting bulbs. The actuators are wirelessly connected to the BDAP [46]. 4) Renewable Energy: These are solar panels that constitute the renewable power source for the farm and battery. 5) Storage Unit: The element responsible for storing extra electrical energy produced by the solar panels and reusing it when needed to operate the water pumps and lighting. It consists of a Lithium battery. 6) Control Unit: It decides whether to forward the produced electricity to the Smart Farm or store it in the batteries for future use. 7) Cluster Controller: It is responsible for collecting and filtering data related to the smart grid and sending it to the Cloud-based IoT platform in real-time mode [47]. Our proposed system is meant to cope with the rapidly growing need for water-table by controlling water pumping, overcoming the shortage in electricity by integrating renewable energy, and promoting rational usage of water by regulating drip irrigation. The following sections shed further light on the main functionalities of our system.

A. DATA ACQUISITION
The data acquisition is composed of wireless sensors and actuators. As depicted in Fig.8, a sensor node is composed of three elements: 1. Sensor modules: soil moisture sensor deployed in the field, temperature, and humidity sensor (DHT11) which measures the ambient air temperature and humidity, PIR sensor which detects the existence of humans by sensing motion, and for the fields' security reason, the fire sensor is used to detect the presence of a flame or fire, the Ultrasonic HC-SR04 sensor which measures the water level in the basin, and the AC sensor which measures pumps' power consumption. 2. Microcontroller: an Arduino Nano board that connects all the components is used in this study. 3. Communication module: It is responsible for transceiving data between sensors and the BDAP. In this study Zigbee module (Xbee series 2 S2C) was used. In anticipation of any power failure in sunlight deficiency, all nodes are powered with an IoT solar system (solar panel 20W, solar battery charger, and 25Ah battery). This method makes the WSN data acquisition system ideal for agriculture as it can be easily deployed everywhere independently of the power installation. This energy harvesting system can guarantee up to 5 days of total autonomy for each sensor node.

B. SENSOR NODE CONFIGURATION
The WSN was implemented as a mesh topology using a scalable and reliable firmware named Digimesh. Each sensor node can act as a sensor and a router in this configuration using the Ad-hoc On-demand Distance Vector (AODV) routing protocol [10]. In the current study, five wireless sensor nodes were deployed. These send real-time data to the BDAP every 15 minutes through the gateway device (sink node) that connects the WSN and the BDAP, see Fig. 9.
The wireless actuator nodes we used to control the water pumps are smart relays (Sonoff with integrated ESP8266 Wi- Fi Card [48]). These are WiFi-based wireless smart switches that operate with a voltage range of 90-250v AC and a wireless frequency of 2.4GHz and are compatible with a wide range of appliances. We adopted this smart switch as it is cost-effective, reliable, and provides an integrated Wi-Fi module. In addition, ensuring communication with the BDAP as the Wi-Fi connection might not be available. We enhanced the data acquisition and control unit by replacing Sonoff's smart relay module with a standard relay 5V connected to an Arduino Nano microcontroller equipped with a GSM/ GPRS module or a Zigbee module. Fig.10. shows the wireless sensors used to collect data from the field, Fig.11. shows the wireless sensors used to monitor the water level in the basin and the water pump's energy consumption, and Fig.12 shows the wireless actuator nodes that act on the water pumps to switch them On/Off.

C. BIG DATA ANALYTICS PLATFORM
Big Data Analytics Platform (BDAP) is the backbone of the proposed system. The developed BDAP is based on Node-RED and tested locally on a RaspberryPi 3 board running Raspbian OS. Besides, we installed the message broker Eclipse-Mosquitto that implements the IoT publish-subscribe messaging protocol (MQTT). Following are the main functionalities of our BDAP.

1) REAL-TIME DATA COLLECTION AND STORAGE
The BDAP receives real-time data from three sources.
1. DigiMesh sensors network is distributed in the field to collect and send data to the gateway. This data is then forwarded to the BDAP through the USB serial port. 2. Wireless sensor/actuator nodes are deployed in groundwater sources and basins. They are connected to Wi-Fi using the ESP8266 module, and they communicate with BDAP using the MQTT communication protocol.  3. OpenWeatherMap online forecasting portal: it provides up to 5 days forecast of temperature, humidity, wind speed, pressure, and precipitation.

2) REAL-TIME DATA VISUALISATION
The proposed BDAP contains a NodeRED dashboard that displays the acquired data from the different sources through a user-friendly graphical user interface (GUI). The main characteristics of the GUI are: 1. Visualizing data over short, medium, and long-term periods (daily, monthly, and yearly) in charts form. 2. Allowing the user to remotely act on the pumps by switching them On/Off via graphical command buttons. 3. Securing data access by prompting the user to authenticate through password-secured sessions. Fig.13 depicts the interactive real-time control GUI, which displays the real-time soil moisture average, temperature average, water level in the basin, irrigation duration, rain precipitation, and the state of water pumps (On/Off). The NodeRED dashboard was deployed using flowchart programming.

3) REAL-TIME IRRIGATION AND WATER LEVEL CONTROL
The control flow of the proposed smart irrigation system is presented in Fig.14. It has two primary sequences: 1. Irrigation control (in green), and 2. water level control (in blue).

a: REAL-TIME IRRIGATION CONTROL
We are adopting fuzzy logic in deploying this component, and we dubbed it the Fuzzy Irrigation Control Unit (FICU). The BDAP starts by retrieving predicted precipitation data for the next 24 hours from OpenWeatherMap. Depending on provided data, two cases are possible: 1. If it is predicted to rain, the FICU decides to switch Off the basin waterpump#2 as the rain will likely irrigate the field. 2. else, the FICU proceeds as follows: a. It retrieves the actual soil moisture and ambient temperature (T a ) from the wireless sensor nodes and computes their average values. b. The computed average soil moisture is compared to the desired one that varies depending on the plant type. In this study, the desired soil moisture is set to 60%. c. The FICU computes a new variable named Soil Moisture Difference (SMD). SMD is the difference between the real-time soil moisture average and the desired one. d. If SMD is ≤ 0, FICU uses SMD and Ta to generate the irrigation duration (I d ) based on the rules mentioned in Table 1. For instance, ''If SMD < 0, and T a is Cold, then I d is set to Short''. Then, waterpump#2 is turned On for I d minutes to irrigate the field. e. If SMD > 0, the waterpump#2 is turned Off. The use of T a alongside SMD by FICU is meant to reduce water evapotranspiration at high temperatures. FICU comprises four components, see Fig.15: 1. fuzzification module, 2. The Max-Min Inference Engine, 3. The Mamdani-type rule base module, and 4. The Centroid defuzzification module.
The inputs and output membership functions of the FICU are depicted in Fig. 16. The fuzzification/defuzzification of inputs/output is done using trapezoidal and triangular membership functions.
Only three membership functions were used for each input to improve the program execution speed and avoid the memory backlog [36]. However, five membership functions were used for the output to cover all variations of I d .

b: REAL-TIME WATER LEVEL CONTROL
Drip irrigation using basins is the most used irrigation method in agriculture. This method has several advantages and drawbacks as well.
• Advantages: -Collecting rainwater: by collecting rainwater, water table resources are saved, and energy use is reduced. -Improving water quality: when water is kept in basins, it becomes more oxygenated, thus becoming more beneficial for the plants [49]. • Drawbacks: -Permanent supervision cost: This is the sole drawback. Conventional Water Level (WL) control requires permanent human supervision, increasing the cost of the products. Our BDAP monitors WL in basins based on real-time data provided by a WL sensor to minimize the additional cost due to supervision.
The blue part in Fig.14 shows the WL control flowchart. Once the field is watered, the BDAP checks the WL value of the basin.
-If WL < 50 %, waterpump#1 is turned On. Then, water is pumped from the groundwater source to fill the basin to the maximum. Once at maximum, a switch Off command is sent to waterpump#1.
The whole water irrigation and water level control process is regularly repeated (see Fig.14). We fixed the cycle duration to one hour.   The solar system used in this study is shown in Fig. 17. It consists of a DC/AC inverter, an AC/DC inverter, electrical protection, and a lithium battery.
The real-world deployment of the proposed SA system is depicted in Fig.18. The setup consists of solar panels, WSN, IoT solar panels with batteries and water pumps.

V. RESULTS & DISCUSSIONS
In order to evaluate our system, real-time data was continuously collected remotely via the settled WSN over five days in July 2020. Collected data include soil moisture, temperature, irrigation duration, water level, solar panels energy production, and the energy consumption of waterpump#2. The relevant data variances are depicted in figures 19, 20, 21, 22, and 23. In Fig. 19, depicting the temperature and soil moisture variances, we notice that the day temperature rose to 40 • C, and the nocturnal temperature ranged between 15 and 20 • C.
Unlike conventional irrigation systems (depicted in Fig. 20), the soil moisture is optimal and closer to the desired value (60%), and it stays within the range of 57%-65%. In conventional irrigation systems, represented in Fig. 20, the soil moisture varies from 0%-100%.  In Fig. 20, we track the real-time soil moisture in traditional irrigation systems within five days. This method consists of irrigating the field for two consecutive hours daily. The results, in fig. 20, underpin the following drawbacks: • The plant is either over or under irrigated since the soil moisture varies between those extreme values, and the optimal value (60%) is not maintained for an extended period.
• The quality and quantity of the yield would be negatively affected since the soil moisture reaches 0% for at least five hours each day.
• High water and energy consumption: in five days, 2400L were consumed, which is equivalent to 480L/day for an area of 25m 2 . The last average is used later to evaluate our system compared to conventional irrigation in the same region.
Our proposed system reacts to weather changes with high precision. It raises the soil moisture to 65% during high temperatures (to avoid evapotranspiration losses) and does not exceed 62%-63% in low temperatures.
To study the impact of the irrigation duration on soil moisture, we tracked the relevant variances as depicted in Fig.21. Accordingly, whenever there is a decrease in soil moisture, the FICU computes the desired irrigation period to meet the desired moisture value and sends a switch On signal to the wireless actuator attached to waterpump#2.
Accordingly, the higher the temperature is, the longer the irrigation duration becomes. When raising the irrigation periods, the evapotranspiration losses are reduced, and as a result, the desired soil moisture is continuously maintained. Thus, better conditions are provided to the plant, consequently increasing the yield's quality and quantity.
Monitoring and controlling the water level in the basin is crucial for controlling the drip irrigation system. In this experiment, we continuously track the basin water, which varies according to the irrigation periods computed by the FICU. For instance, as shown in Fig.22, when the water level  exceeds the set threshold (50% in our case), waterpump#1 is turned Off; otherwise, waterpump#1 is switched On until the basin is reached entirely complete. Thus, the obtained results are consistent with the water level control previously presented in section IV.
We used a water pump with a water flow rate of 240 L/hour in our experiment. Within five days, the total I d was 169 minutes, and 676 L were consumed during this time. This rate is equivalent to 135.2 L/day consumed over the same area of 25 m 2 . Accordingly, our proposed smart agriculture system provides the field with an average of 54 m 3 / hectare per day. This water consumption is 3.55 times lower than in the traditional irrigation system, and thus the energy consumption as well since used pumps are electrical ones.
Therefore, we conclude that the traditional irrigation system is ineffective in maintaining soil moisture at the desired value. In addition, it is wasting water and energy resources.
The real-time energy consumption of waterpump#2 measured by AC sensor and the real-time solar panels' energy production measured by a smart energy meter within five days are presented in Fig.23. We notice from this figure that the maximum energy consumption and maximum solar energy production are reached simultaneously (between 12:00 pm and 4:00 pm). From this figure, we also conclude  that the integration of solar energy is suitable for smart agriculture without implementing an extensive storage system(batteries).
In the design of our SA prototype, the cost has been reduced to the minimum possible to make it affordable and widely adopted even by small and medium farmers. The unit price for every single component is presented in Table 2.
The total cost of designing our SA Prototype with a Rasp-berryPi, five wireless sensor nodes, 5 IoT solar panels and batteries, two smart relays, and a Zigbee gateway is $ 609, which is much cheaper than other existing solutions in the market. The proposed SA system is an up-and-coming solution for many reasons: • Better quantity and quality production. • Less energy and water consumption. • Cost-effectiveness.
• Designed to promote scalability.

VI. CONCLUSION
This paper developed, presented, and deployed an opensource and easy-to-deploy smart agriculture system with the main drivers of cost-effectiveness, water consumption optimization, and renewable energy integration. The deployed SA system leverages up-to-date ICT. We used IoT devices for data acquisition and control (sensors and actuators). We also used Cloud Computing for data processing, visualization, and data storage. Besides, we recurred to fuzzy logic to implement a fuzzy irrigation control unit that decides on the appropriate I d (Irrigation Duration) based on real-time processed data. This approach saves water and energy and provides adequate conditions for the plants, thus optimizing crops' yield. Furthermore, this allows better monitoring for the water level in the basin and adheres to the conventional eco-friendly trend of sustainable agriculture through its total reliance on solar energy.
The case study results show that our proposed solution is promising compared to the traditional irrigation system due to its cost-effectiveness and ability to reduce water/energy consumption by 71.8%.
As future work, we are paving the way towards scaling up our system by deploying our solution in several farms in the region, allowing our BDAP (Big Data Analytics Platform) to collect big real-time data about water-table usage in the region. Thus appropriate irrigation strategies can be derived and analyzed. Besides, we plan further experimentation to enhance solar energy production and storage. We will also integrate LoRa wireless sensors/actuators network and develop a machine learning system that predicts soil moisture, energy production, and energy consumption within a few days. The machine learning algorithm can adapt to different crop requirements in moisture levels and improve crop yield. DRISS BENHADDOU received the Ph.D. degree in optoelectronics from the University of Montpellier II, France, and the Ph.D. degree in computer networks and telecommunications from the University of Missouri. He is currently a Professor and a Fulbright Scholar at the University of Houston, where he is actively involved in a broad range of research activities in smart systems development, wireless and optical networking space, optical instrumentation, and the IoT application. In addition, he is spearheading the development of a new state-of-the-art wireless and optical networking research laboratory at the University of Houston (https://uh.edu/tech/won/). He has four years of industry experience working with Sprint and Lambda Optical Systems Inc., where he played a key role in systems integration activities. He has published more than 130 peer-reviewed publications. VOLUME 10, 2022