**1. Introduction**

The Gulf Cooperation Council (GCC) nations and Saudi Arabia are already classified as water-scarce countries, with only Oman above the extreme scarcity threshold of 500 cubic meters per capita per year [1]. The growth of agricultural production is greatly affected by climate change, urban population concentration, crop diseases, and greenhouse emissions, all of which highlight the need to meet the growing demand for food and energy. With water resources already scarce, the Middle East and North Africa regions will be particularly vulnerable to climate change [2]. Saudi Arabia is one of the largest arid countries without permanent rivers or lakes in the Arabian Peninsula [3,4]. In some parts of the region, temperatures can reach more than 50◦ Celsius (C) (122◦ Fahrenheit (F)), resulting in extremely hot and dry conditions. The country has one of the poorest natural renewable water resources [5]. Renewable natural resources can be affected by a range of variables, including water demand in different sectors and the effects of global warming. There is a recurring theme in research papers on water resources and agriculture related to climate

**Citation:** Habib, S.; Alyahya, S.; Islam, M.; Alnajim, A.M.; Alabdulatif, A.; Alabdulatif, A. Design and Implementation: An IoT-Framework-Based Automated Wastewater Irrigation System. *Electronics* **2023**, *12*, 28. https:// doi.org/10.3390/electronics12010028

Academic Editors: Antonio Cano-Ortega and Francisco Sánchez-Sutil

Received: 10 November 2022 Revised: 8 December 2022 Accepted: 11 December 2022 Published: 22 December 2022

**Copyright:** © 2022 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https:// creativecommons.org/licenses/by/ 4.0/).

change. Because of global warming, water adaptation measures have been considered to ensure food production and people's access to water, and the preservation of ecosystems. Further, the worsening drought conditions in the peninsular countries have created a need for increasing the water supply from alternative sources and the implementation of water conservation. Moreover, humans and the environment should be assured of their safety as a result of water scarcity or water quality and supply in the face of intensifying climate-related impacts. There are various risks associated with climate change, including water shortages, water quality reductions, soil salinity increases, biodiversity loss, irrigation requirements, and the cost of emergency and remedial action to make sure that farmers plant a crop with a guarantee of success and generating income. Agriculture is the biggest consumer of water in Saudi Arabia, amounting to up the 70% of the total water use, creating a demand for optimization strategies. The number of studies focusing on reducing irrigation water consumption has increased because of the introduction of smart water management. In addition to social, economic, and climate change policies, technological innovations can improve water management, according to some studies [6].

Because of the ever-increasing demand for food necessities and the diminishing supply of those necessities, there is always room for improvement in the production of agricultural produce through the adoption of an agro-tech-based system. Only through cultivation can such things be provided. There is no doubt that this is an imperative factor in human societies when it comes to increasing and maintaining the demand for food production. However, the scarcity of land and water has resulted in a decreasing volume of water available on farms. Therefore, farmers are using irrigation to supplement their water supply system through using high-tech-based systems. It is possible to define irrigation as the science of artificially applying water to land or soil. The methods unfolding in the agriculture sector are related to what is termed precision agriculture capable of estimating the chemistry of the soil to determine the water needs to raise a given crop for productive yield. This means that plants are to be provided with water according to the type of soil to be irrigated. The virgin fertility of the soil is also being investigated using sensor technology. This is in conjunction with the collection and study of the characteristics of the soil moisture dynamics profile. The purpose is to use this data as feedback to improve farming efficiency [7]. The use of renewable energy-powered technology in Seawater Reverse Osmosis (SWRO) desalination plants has had an impact on the preparation for embracing Industry 4.0 in every sector with promising results benefitting humans and agriculture [8,9].

An IoT-enabled framework for automated farming is essentially a network consisting of sensory electronics installed and distributed on the farm at specific locations and connected through a bi-directional communication channel with the management center equipped with related hardware devices harnessed through purposefully developed programming modules. This kind of agriculture is growing in quality, sustainability, transparency, and cost-effectiveness to maximize crop production with lower labor costs. Herein, we propose a system that uses WSN to retrieve environmental data in real time in order to optimize irrigation timing implementation.

The rest of the paper consists of a discussion of related work in Section 2, and an outline of the intelligent communication system in Section 3, the monitoring flowchart in Section 4, Data collection in Section 5, with design dashboard in Section 6, while implementation of test scenarios for real-time implementation are described in Section 7, the results and discussion in Section 8, and conclusions and further work are given in Section 9.

#### **2. Related Work**

The Kingdom of Saudi Arabia, with a total area of 2.25 million km2, is a large country, bordered by Jordon and Iraq and Kuwait in the north, on the east by the Gulf, Bahrain and the United Arab Emirates, on the south by the Sultanate of Oman and Yemen, and in the west by the Red Sea, giving it a coastline of 1750 km. Saudi Arabia is on its way to achieving self-sufficiency in poultry and dairy products [10,11].

Automatic farming systems are based on the collection of data related to soil moisture content, the temperature profile of an indoor covered agriculture farm shed, rainfall data, and intra-field wind speed profiles [12,13]. The related data archives are stored in a computer server that is capable of providing climate prediction, soil condition analysis, and disturbance analysis [14,15].

A fuzzy controller was used by Jamroen et al. to adjust irrigation taking into account the moisture index and water stress [16] by continuously monitoring the soil moisture content and crop water variability. Lloret et al. have used flooding methods to carry out irrigation automatically by observing remotely crop variables and climatic conditions using an application [17] that allows the farmer to remotely control water gates in the water canals. Based on the difference in environmental leaf temperatures and light intensity in hydroponic crops under temperature control between 28 and 32 degrees Celsius, Puengsungwan et al. propose a method for determining root stress in soilless cultivation. According to their proposal, the obtained patterns are divided into regions representing natural roots, stress roots, and rotten roots. Using IoT technologies, they were able to reduce the system's response time from 5 min to less than 60 s. In addition, they increased detection efficiency from 85% to 95% compared to a method that uses the Easy Leaf Area application to determine the drop in leaf area [18].

A variety of irrigation systems have been used in soil and soilless crops. Different approaches exist to estimate irrigation requirements in soil cultivation, highlighting the importance of monitoring and controlling the temperature, soil moisture, evapotranspiration, and water stress index used for operating micro-sprinklers, drip irrigation, and ventilation fans. Several authors, including González-Amarillo [19] and Fernández-Ahumada [20], use humidity or temperature measurements to properly maintain conditions within an agricultural shed by turning on all related irrigation, ventilation, and heating systems. By measuring daily evapotranspiration, Mohamed [21] and Poyen [22] estimate irrigation requirements. Mohamed employs the Penman–Monteith method, whereas Poyen includes the capability of automatically selecting between Hargreaves and Samni, Kharufa, and Penman–Monteith methods according to the type of climate and geographical factors by employing modern technologies and intelligent systems for improving water productivity and conservation. These are some examples (among many others) of how the word "smart" is used in works and prototypes that show different capabilities and features. In an effort to solve the problem of one-size-fits-all qualification, the research community has proposed different taxonomies that classify smart artifacts based on their features [23]. Bin Ahmadon et. al. consists of two major phases in their paper. Phase one is design, and phase two is implementation. Here are the scenarios for two major phases in which a service must be implemented in a different [24].

Agro-IoT was an agricultural IoT project that ran from 2015 to 2020 and featured an architecture that consists of six layers, including sensors, actuators, wireless nodes, etc. In addition, there is a network layer that includes communication protocols, an intermediate layer for software, an application layer for data analysis and prediction, and a user layer where results are communicated to farmers, experts in the field, and the supply chain. Among the goals of the project were real-time monitoring of low-scale greenhouses, early disease detection, identification of crop varieties, optimizing irrigation facilities, and pesticide use and fertilizers efficiency. Similarly, solar precision agriculture is seen as a four-layer IoT architecture, consisting of the sensory layer, the network layer that takes into account IoT nodes and base stations, the decision layer that involves server services, workstations, business and knowledge bases, and the application availability layer that provides information for researchers, experts, and farmers [25,26].

The implemented irrigation solution developed in this research is not restricted to the control of irrigation systems. It also analyzes every component of the system, from water pipes to sprinklers, to detect leaks and malfunctions, while improving efficiency and reducing costs. The proposed solution uses Wireless Sensor Networks (WSN) to collect realtime information data directly in the field to verify the existing conditions. By combining

this information with weather forecasts, evapotranspiration from soil and other surfaces and plants, and farm specifications, artificial intelligence algorithms are able to determine how much water is needed for a particular section of the farm by adjusting the irrigation controller accordingly.

#### **3. Intelligent Communication Systems**

As shown in Figure 1, the IoT-based irrigation system consists of six main elements: Data Acquisition, Data Monitoring, Communication, Data Processing, Storage, and Visualization.

**Figure 1.** Block diagram of the IoT-based irrigation system.

#### *3.1. Data Acquisition*

An array of sensors must be used to obtain data from soil moisture sensors, rainfall sensors, ambient humidity sensors, and temperature sensors, among other devices. The various sensors used to monitor crops are configured with a variety of threshold values. This corresponds to the type of crop being monitored and depends on the type of sensor. Since the sensors sense and acquire data at intervals, the measurements will be sent through Wi-Fi modules to be processed according to the parameters of each of the measurements.

#### *3.2. Data Monitoring*

A supervisory system is required to manage and monitor the information gathered by the sensors (temperature, rainfall, and moisture), as well as on crops and their cycles. A Graphical User Interface (GUI) is used to display the information that is stored in the database. A statistical analysis of the amount of water consumed by crops with respect to their dates and sections has been carried out as a result of monitoring. Finally, all data are requested through the use of web services, which are made available on the Internet for access by authorized personnel.

#### *3.3. Communication Networking*

The sensors are connected to Arduino microcontroller development boards that use ESP8266 Wi-Fi modules to communicate with the database, and everything is done via the cloud since the entire solution relies on the cloud for connectivity. The database is not directly connected to the sensor because it is not secure. Data is entered into the database using a Web Service (WS). The Wi-Fi module transmits two fields: (1) the identification number (ID), and (2) the value of the sensor. Each type of sensor is assigned a unique ID based on its IP address and a unique number. As an identifier, it serves the purpose of identifying the source of information. The data is processed to determine if irrigation is required. The watering schedule is updated when it is determined that watering is necessary based on the interpretation of the information. An electronic valve is incorporated into the irrigation system and is controlled by the Arduino via the Wi-Fi module. Since the Wi-Fi Module does not have a public IP address, it cannot be identified from the cloud, and therefore requests cannot be sent from the cloud to the module. In the same manner, the Wi-Fi module continuously queries the web service for information. The valve is activated in response to an update in the WS with the time the system was powered on. The Wi-Fi module is assigned a static IP address whenever it is connected to an Internet gateway, making it easier to access from the Internet. In order to monitor data in a timely manner, data visualization along with database information is required. A web application for data visualization has been used in this case study, but other methods may also be employed.

Previous projects used the data collected in order to increase the productivity of the garden or farm, as well as to reduce the amount of water used. Although these ideas are useful in theory, they may not be able to be implemented in a practical scenario. In our system, the algorithm enables the system to understand how much water should be applied to the field based on the moisture in the field; however, the field is watered only when moisture levels are low. Using this approach, we were able to save approximately 25% of our budget. Despite this, our previous systems lack a certain level of reliability, which can be attributed mainly to the selected sensors. In addition, they need to be tested in a larger scenario. In order to improve results and to make sure that the solution works in multiple environments, the wireless network will play a crucial role in ensuring its effectiveness.

#### *3.4. Data Processing*

Soil moisture, temperature, and rainfall are received as sensor data in the form of three integer values. Decisions regarding the crop can be made based on the information provided by this data. It is necessary to note that the valve will only open if the soil moisture is below the level required for the crop. In the case of sprinkler irrigation, the water temperature will determine whether irrigation is required. The system will not permit the watering of the plants in the event of rain. The valve can either be opened or no action taken depending on the values collected by the sensors.

#### *3.5. Storage*

Databases are necessary to store information about crop types, sensors, moisture, and statistical data. The database used in the application is schematically as shown in Figure 2. The purpose of this structure is to store information about crops, their cycles, and the order in which each irrigation should be performed. Furthermore, information about the monitored sections is saved, as well as that of the sensors associated with each section. The system uses the IoT to determine the amount of water needed for every crop in every cycle using a "smart irrigation" system. Instead of creating another smart irrigation controller, in this work, we have created a smart sustainable irrigation solution. This solution also analyzes every component of the system, from the pipes that supply the water to the sprinklers. This is because it analyzes their interaction. During this analysis, the aim is to detect potential leaks or malfunctions, improve efficiency and reduce costs in a sustainable way in line with the requirements of a circular economy.

#### *3.6. Visualization*

The administrator will be able to control the variables (sensor data), as well as irrigate the crop in order to ensure that the resulting data are presented in an appropriate manner. There are different irrigation configurations for each type of crop when it comes to visualization and interaction with users. When this is not possible, the possibility of adjusting the configuration of crops is available based on a predetermined composition.

**Figure 2.** Flowchart of the IoT-based irrigation system.

#### **4. Flowchart**

Initially, the user interacts with the irrigation system using a mobile application or any other connected interface to extract data regarding the current soil conditions and moisture in order to change the state of the irrigation system. The sensor node/mote measures the soil moisture, temperature, and humidity of the surrounding environment of—in this case of this study—each date palm tree.

The information can be received using an automated system as shown in Figure 2. Users can make a decision with respect to watering based on the data available/provided on the application or system. The method will lead to accurate agricultural techniques to closely monitor the conditions of the field and use real-time data to realize the most efficient irrigation.

#### **5. Data Collection and Connection**

All sensor nodes have been installed and are connected to the network master node. The node will send information packets to every sensor hub bearing the sensor hub ID if communication is present in the node. After acquiring the data packets from the sensors, the measured values of soil parameters are analyzed—for example: Soil moisture assessment (30%). A pH value is used to determine whether the soil is acidic or alkaline. The sensors assess the quality of the equipment, and these quality values are stored in the memory of the Arduino microcontroller unit (MCU). In response to these stored values, the MCU responds by performing specific actions according to the listed conditions. When data packets are received from the sensor node, the MCU transmits them wirelessly to the master node, thereby participating in the Internet of Things (IoT) environment activities.

#### **6. Designed Monitoring Dashboard**

The dashboard can be thought of as a server that can be designed using a mobile device, as shown in Figure 3. Using the dashboard, the user will be able to monitor the amount of water flow, and parameters such as temperature and humidity. In addition, users are also able to turn on/off the water pump just by operating the monitoring dashboard. There is a control button (On/Off) shown in Figure 4 that shows the installed applications with the dashboard.

**Figure 3.** Dashboard display of the mobile device application.

**Figure 4.** Implementation of IOT-based systems at medium and large scales.

The sensor and electronics are powered by DC power derived from solar panels, and the amount of power generated is determined by the rating of the solar panels. As shown in Figure 3, the solar system produces DC power for charging the battery via the charging kit. This power can be directed to the inverter by the inverter circuit. The inverter is needed to convert the DC power to AC because older water pumps run on AC power. In order to implement this system, we have used a number of hardware components, such as: (a) Solar panels, (b) Charging kits, (c) Batteries, and (d) Inverters. It has become possible to implement the software on a mobile phone. However, the oversized bloated network model is not conducive to the deployment of the device's software.

#### **7. Real-Time Implementation**

A schematic diagram of the automated irrigation system is shown in Figure 1. The system is designed with devices capable of controlling water delivery, a management unit, a soil moisture sensing unit, and an on-spot processing unit, as shown in Figure 4.

The remote database is an installation to store the contiguous farming data structure. Climatic parameters, including soil moisture level, are obtained from the sector of each sensory mote. Through the personal interface of the internet utility, the user can control the water valve by converting the positioning monitor to real-time climate situations within the field.

There are many factors that affect actual water usage, including the type of plants, the evapotranspiration rate, the amount of field area, the type of valves and the pipes, the distance between the valves, and the number of waterings per day. Taking all these parameters into consideration, and using Equation (1), we can calculate the actual amount of water that needs to be applied to the field.

$$\text{Time} = \frac{\text{Area} \times (\text{K}\_{\text{c}} + \text{ET}\_{\text{r}}) \times 60}{\text{F} \times \text{N} \times 100} / \text{Period} \tag{1}$$

where Time is the irrigation time in minutes, Kc is the crop coefficient (here, the coefficient ranges between approximately 7.04 mm/day and 11.7 mm/day), F is the water flow per valve in m3/h, N is the number of valves, and Area is the field area in m2.

Based on Equation (1) and how much data can be input to achieve accurate results, three analyses have been done and compared to the performance of a normal irrigation system:


There is no doubt that the concept and applications of the IoT (Internet of Things) are becoming more and more relevant in our world. This can be attributed to the fact that there is the possibility of interconnecting any object or device through the network. This can be done by using various types of communication technologies and protocols. This interconnection can be achieved by using a variety of different types of networks, some of the best-known and widely disseminated ones being WiFi (Wireless Fidelity), LTE (Long-Term Evolution), Bluetooth, and so on. Based on the proposed system, we intend to validate the implementation of a WSN environment in medium-scale crops for a specific crop variation and an area specific to the crop. The main objective of this study was to minimize the cost of the sensor devices whilst optimizing the technical characteristics that the deployed devices should have. As a result of this information, it will be possible in the future to produce on a large scale monitored and sustainable crops, as shown in Figure 5.

**Figure 5.** An overview of the output in a graphical format—soil moisture.

#### **8. Results and Discussion**

IoT applications have developed a variety of specialized communication protocols that have the potential to become long-term standards with global acceptance and that are associated with significant benefits at the time of their implementation as well. It is still critical to know the specifications and technical capabilities of each protocol in order to choose the one that is appropriate for your application and environment. Therefore, the macro project that led to the publication of this article proposed the creation of a model that could be used to analyze and simulate the behavior of the key performance indicators of the system. The information provided in this paper is structured in such a way that it becomes a very comprehensive decision-making tool that contributes to the research and development of relevant knowledge in this field as well as the implementation of it in environments.

As a result of providing the sensors with data in the form of voltage, this data is presented to the microcontroller. The microcontroller, after calibrating these values, gives us the moisture content of the soil in percentage values. The data is sent continuously from the IoT device to the online site through the wireless network to be displayed on the computer screen being used. The dashboard display is also refreshed every three seconds to make sure the real-time data availability, and just in case of possible Internet disruption, reloading page will let us know about it.

This model is designed to manage water for irrigating date palm trees. The development and improvement of date palms require a lot of water in order to grow and improve the quality of the dates at harvest time. However, it should be noted that consistent dry weather leads to insufficient water as a result of dispersal, waste, and penetration. Precise irrigation will help in achieving remarkable yields from the date palm. However, at the same time, the quality of the dates will still depend on the decision of when to harvest. Figure 5 shows the output of the proposed model in graphical form. There is no better way to display data than to use a graphical representation in the form of a diagram. Also, visual representations are much more memorable. As we not only display the moisture content (data) as text but also in visual form, this helps the user to quickly and easily notice the sudden changes in the data or information that has been displayed.

Data were collected from each sensor node of the WSN containing real-time information about the environmental conditions of the farm. The set of data collected that represents the year as a whole is shown in Figure 6. The winter season in the study area starts at the end of October and lasts until the beginning of February. November and December are the months when the weather is at its most pleasant. As a result, less water

is needed for irrigation, which is in contrast with summertime, when it is mostly dry and needs a lot more water.

The first thing to note is that, in the testing period, there are no rain periods in Saudi Arabia. This means that watering is mainly done when soil moisture is less than 30%. It is also possible to note that humidity levels in Saudi Arabia are high at that time of year, which helps the soil moisture to decline more slowly. Therefore, the water used for irrigation can be less. The measurement of humidity parameters in the soil and the subsequent processing of this information constitutes a fundamental element for decision-making in the technical environments of smart agriculture. This leads, for example, to establishing the appropriate sowing and harvesting periods to improve the productivity of dates in Saudi Arabia. Smart farms are an especially significant aspect that must be addressed by systems engineering, electronic engineering, and data science. The analysis of large volumes of information using time series, big data, data mining, and other analysis methodologies allows the finding of patterns that allow intelligent decision-making. This allows us to improve and optimize different plants in the Agro sector. Thanks to the integration of the IoT and different sensors in cloud platforms, it is possible to improve many aspects related to plant growth. This includes saving on inputs and pest control.

The novelty of this work lies in the implementation of the idea through the use of components and devices available in the market as shown in Figure 6. However, it is through the development of the user interface shown in Figure 4 that the authors realized their search for real-time data acquisition. The quantifiable characterization of the soil through the use of spectral characteristics for each pixel in an image of a scene is another attractive area to be pursued for cloud-based non-intrusive irrigation systems, soil data, or underground water quality collection [27].

#### **9. Conclusions**

This proposed irrigation system can measure soil moisture and temperature as well as the atmospheric temperature of the field and can transmit the data in real-time to the user using Wi-Fi and an IoT server. The IoT-based irrigation system is superior to other irrigation systems recently proposed and developed. This is because, in the past, the process of implementing automatic irrigation was done in a traditional, luxurious, and inefficient manner, which results in a small profit margin and misfortunes in production. This paper proposes the utilization of IoT communication to develop an automated irrigation system for agricultural monitoring.

This analysis has allowed the authors to confirm that the implementation model has the capability of being more effective, accurate, and responsive in a very short period of time. Additionally, the proposed model is better than existing models based on the Internet of Things due to the advantages it offers compared to those models: by creating a dashboard based on the HTTP protocol, users will be able to change parameters such as moisture and water flow rates through IoT devices, as well as turn on/off water pumps. Future work may include the integration of sensor grids in order to be able to determine important parameters such as pH, CEC, SAR, organic constituents of the soil, and other crucial parameters. The paper is produced with a critical review of contemporary literature and the use of an algorithm to support the title. It makes a useful contribution to the body of engineering knowledge through the use of simple electronics and simple program code for application development.

**Author Contributions:** Conceptualization, S.A. and S.H.; methodology, M.I.; software, S.H. and M.I.; validation, A.M.A. and Abdullah. Alabdulatif formal analysis, S.H. and A.A. (Alabdulatif Alabdulatif); investigation, S.A. and M.I.; resources, A.A. (Abdullah Alabdulatif) and A. Alabdulatif; data curation, M.I.; writing—original draft preparation, S.A., S.H. and M.I.; writing—review and editing, S.A., A.M.A., A.A. (Alabdulatif Alabdulatif) and A.A. (Abdullah Alabdulatif) visualization, A.M.A.; A.A. (Alabdulatif Alabdulatif) and A.A. (Abdullah Alabdulatif).; supervision, S.A.; project administration, A.M.A.; funding acquisition, S.H.; All authors have read and agreed to the published version of the manuscript.

**Funding:** This research was funded by the Deputyship for Research & Innovation, Ministry of Education, Saudi Arabia for funding this research work through project number (QU-IF-2-4-5-26275).

**Institutional Review Board Statement:** Not applicable.

**Informed Consent Statement:** Not applicable.

**Data Availability Statement:** Not applicable.

**Acknowledgments:** The authors extend their appreciation to the Deputyship for Research & Innovation, Ministry of Education, Saudi Arabia for funding this research work through project number (QU-IF-2-4-5-26275). The authors also thank Qassim University for technical support.

**Conflicts of Interest:** The authors declare that there is no conflict of interest regarding the publication of this paper.
