# Development of a Wireless Sensor Network and IoT-based Smart Irrigation System

Authors: Juliana Ngozi Ndunagu; Kingsley Eghonghon Ukhurebor; Moses Akaaza; Robert Birundu Onyancha
Journal: Applied and Environmental Soil Science
 (2022)

---

## Abstract

This study proposes a smart irrigation system (SIS) using the drip method, which was designed and implemented using wireless sensor networks and an open-source Internet of Things (IoT) cloud computing platform (“Thingspeak.com”) for data collection, storing, data analytics, and visualization. The methodology incorporates the integration of hardware and software components to make irrigation decisions based on web resources like the weather forecast from “weather.com” and sensor values from soil samples. The data collected are then analyzed at the edge server and updated every 15 minutes. Based on the threshold value, the system starts pumping water or stops the irrigation process depending on the irrigation schedule. A web application was developed to display the result so that we could monitor and control the system using an android application edge or a web browser. Based on the data recorded and measured, the data are in comma-separated values (CSV) format and contain 143731 entries with 10 columns. The sample size used contains 5722 rows and 6 columns from the result of our machine learning algorithms using Microsoft Excel and Jupyter Notebook to process and evaluate the performance of the drip SIS, considering the soil moisture, soil temperature, sunlight, rain, and pump. The results confirm the threshold metrics classification evaluation, and some of the metrics computed from our confusion matrix are shown in the classification summary results, showing the accuracy to be 89%, the misclassification rate (error rate) is equal to 10%, the sensitivity is equal to 79%, the specificity is equal to 93%, and the precision of the model is 81%. The evaluation, when compared to K-nearest neighbours usingK = 6 and K = 1, shows the prediction accuracy to be 97% and 98%. The results indicate the system is highly efficient and reliable in performing irrigation and managing water resources and can be adopted in rural areas to boost agricultural productivity.


---

## Body

## 1. Introduction

According to the United States Census Bureau, the current universal population is estimated to be around 7.6 billion people, up from 7.2 billion people in 2015 [1, 2]. The world’s population is anticipated to reach about 10 billion persons by 2050 [3, 4]. To keep up with the exponential population growth, the “United Nations Food and Agriculture Organization (FAO)” report predicted that global food production would need to increase by virtually 70% in 2050 compared to that of 2006 [3, 4]. Africa’s population will geometrically raise to about 2.5 billion by 2050, from its current 1.2 billion in 2015 [1, 2]. Undoubtedly, there is going to be a shortage of food owing to the enormously increasing population. Therefore, it is crucial to continuously develop and explore innovative agricultural techniques [3–12].The importance of a smart irrigation system (SIS) as well as the issue dealing with water efficiency in agriculture productivity comes into focus here because of the pressing need to consistently increase agricultural productivity levels [13–17]. Irrigation can be described as the process of supplying water to land to enable plants to grow. Water bodies are channelled through canals, ditches, pipes, or natural streams. According to Bjorneberg [18], over the years, different irrigation techniques have been in practice to satisfy the irrigation requirements for positive crop growth in certain areas. The three foremost techniques of irrigation are, namely, drip/micro, surface, and sprinkler [19, 20]. Water flows over the soil (land) for surface irrigation. Sprinkler irrigation supplies water to crops by sprinkling or spraying water from moving or fixed systems. Micro-irrigation supplies water with frequent, small applications, usually wetting a portion of the field. Another minor irrigation technique is the subirrigation method. Here, the water level is raised to or held near the crop root zone employing ditches or subsurface drains to supply the water.Nigeria’s irrigation capacity ranges from 1.5 to 3.2 million hectares. According to recent estimates, there are approximately 2.3 million hectares in total, with over 1 million hectares in the north [21]. Only about 40% of the 142–106 hectares irrigated by public schemes are actually accurately irrigated [21]; 32% for irrigated areas managed or controlled by the River Basin Development Authorities (RBDAs) and 55% for those managed or controlled by states [21]. This low rate can be attributed to the need for rehabilitation in most schemes—which accounts for 80% of the equipped area; high operation, upkeep, and maintenance costs; fuel shortages; or technical weakening of infrastructure and pumps. On the other hand, some known irrigation methods have the disadvantages of high labour costs, the cost of setting up an irrigation project and system, poor water management and control, erosion, water runoff and percolation losses, spot top and fixture costs, not appropriate for odd-shaped comedians, potential wander and evaporation losses, and waterlogging, which can lead to mosquito breeding and other parasites [22].According to Penchalaiah et al. [23], farmers estimated the maturity of the land and reserves to create revenue in ancient times. A farmer’s life is becoming increasingly challenging due to reduced humidity levels, water levels, and specific climatic circumstances. The wireless sensor network (WSN) is made up of sensor nodes that can detect, communicate with computers, and communicate wirelessly [24]. The field uses WSN technology to manage and monitor the environment and soil conditions. WSNs are employed in agriculture for a variety of reasons, including high interpretation, increased harvest yield, minimal energy usage, and data distribution. Agriculture relies heavily on effective water management [25]. Water scarcity and high pumping costs make good water management even more important. To improve the use of water resources and increase productivity, one automatic irrigation system (AIS) is now deployed [25]. This one component of the irrigation system enables development in areas where water is scarce. In this method, efficient watering system planning yields the best efficiency while using the least quantity of water [23, 25].In areas where water is scarce, water management is critical. Agriculture is also affected, as a substantial volume of water is dedicated to that purpose [25, 26]. As a result of the potential impacts of global warming, water adaptation methods are being considered to assure the availability of water for food production and consumption. As a result, the need for studies that aimed at reducing water usage in the irrigation process has increased over time. Commercial sensors for agricultural irrigation systems are quite expensive, making this type of device unaffordable for smaller farmers. Manufacturers as well as the users are now interested in low-cost sensors that may be connected to nodes to create cost-effective irrigation control and agricultural monitoring systems [25, 26].Hence, this study focused on designing and implementing a SIS controller for use with drip irrigation owing to its cost-effectiveness and efficiency. Drip irrigation entails laying emitter-equipped tubing alongside plants on the ground. Water drips softly into the root zone from the drippers. Because moisture levels are regulated at an ideal range, plant production and quality improve. Drip irrigation also prevents disease by minimizing water contact with the leaves, stems, and fruit of plants; allows the rows between plants to remain dry, improving access and reducing weed growth; saves time, money, and water due to the system’s efficiency; reduces labour; increases effectiveness on uneven ground; and reduces water and nutrient leaching below the root zone. The design focused on using a microcontroller ESP8266 system on a chip acting as the coordinator module and moisture and temperature sensors acting as the transmitter module. The system uses a cloud computing (CC) platform and an open-source Internet of Things (IoT) MATLAB platform called “ThingSpeak” for collecting, storing, and transmitting data. The sensor values are received and compiled by the microcontroller, which then sends them to the “ThingSpeak cloud” via the HTTP protocol. When the soil threshold moisture value is low in the morning or evening, the system automatically waters the plants, unless it is raining. It is programmed to collect, store, and analyze environmental parameters such as rain, temperature, and humidity in order to actuate autonomous responses (i.e., start and stop the pump). When the anticipated, desired or required soil moisture content is reached, the system automatically stops the irrigation process, saving water and energy. We can monitor and control the system using a web application.The rest of the section of the study is structured into the following four main sections: Section2 will focus on existing systems, the concept of IoT, wireless sensor network (WSN), data analytics, and “ThingSpeak,” their overall functionality and history, and future prospects of such systems. Section 3 will focus on the development methodologies used to conduct the research. Data collection and system analysis processes are discussed. Section 4 will place much emphasis on the implementation of the research, which is analyzed and discussed. Section 5 will emphasize the discussion of findings and a summary of the study.


## 2. Literature Review

The need to automate irrigation and agricultural activities and use the limited or inadequate battery power of a node competently has led to several hardware and software advances in the sensor network area [27]. This study by Kagalkar [28] found that SIS was designed to fulfil the water supplies or necessities of the plants by monitoring the soil moisture as well as other ecological parameters. The system was tested with potatoes to see how well it worked. The potato plant’s water requirements were 500 mm to 700 mm per area a day. The soil moisture was set to 300–600, which was predicated on IoT. Every 30 seconds, it logs the sensor data to the CC platform “ThingSpeak.com.” The analysis was shown in graph form, and the farmer could remotely monitor and control the water pump over the Internet using a Wi-Fi module to access the web interface on an Android application. As mentioned by Santhiya et al. [29], in the design of SIS, the Arduino UNO microcontroller and Android are connected with a personal computer, data mining, and CC to store the data that are read by temperature and humidity sensors. The graph generated in the web application makes easy analysis and the drip is managed. The proposed or planned system turns “ON/OFF” the drip utilizing Bluetooth.The project developed by Kashif and Poonguzhali [30] was an automatic irrigation system (AIS), which waters the crops based on sensing the dryness of the land or soil. It uses wireless transmission techniques, that is, RF transmission technique, mobile phones to receive SMS and to update users about the condition of the plant. Web technology is used to view sensor values, which aid monitoring and control to curtail the wastage of water utilized in the irrigation progression. This process also helped to improve the agricultural production.This study “IoT-based Smart Agriculture” developed by Gondchawar and Kawitkar [31] shows all observations and experimental tests demonstrate that the development is a broad solution to field actions, irrigation issues, and storage issues, by employing remote-controlled robots, SIS, and a smart warehouse management system, respectively. These processes will be done by means of any remote smart device or computer connected to the Internet, and the processes will be carried out by interfacing sensors, Wi-Fi or ZigBee modules, cameras, and actuators with microcontrollers and Raspberry Pi.The research environment is more persuaded towards research at the software level as it has several possibilities, opportunities, and great potential to yield momentous results. Data collected by sensors are removed by several applications, which set up data flow or communication of data in the network. As mentioned by Sarkar et al. [32] in their work, they developed smart agriculture using IoT and different sensors for implementing or executing the smart agricultural and monitoring systems by utilizing various sensors within the agricultural field, pH sensor, moisture sensor, humidity sensor, and proximity sensor for analyzing and sending data to the Raspberry Pi remotely, which is then sent to Krishi Helpline for plant or crop monitoring for maximum or optimal production of crops or plants.


### 2.1. Overview and Use of IoT

Ashton [33] coined the term “IoT,” and RFID-based item identification systems were also invented in the same year. According to Kashif and Poonguzhali [30], IoT research is still early. As a result, there is no universally accepted definition for IoT. Cabine [34] described “IOT as the ever-growing network of physical objects that feature an IP address for Internet connectivity and the communication that occurs between these objects and other internet-enabled devices and systems.” It is also referred to as machine-to-machine (M2M), sky net, or Internet of everything, things having identities and virtual personalities operating in smart spaces using intelligent interfaces to connect and communicate within social, environmental, and user contexts. A variety of scholars provided the definitions below as adopted and modified from Silverio-Fernández et al. [35] and Sethi and Sarangi [36]:(i)
“Things have virtual personalities that operate in smart spaces using intelligent interfaces to connect and communicate within social, environmental, and user contexts.”(ii)
“The semantic origin of the expression is composed of two words and concepts: IoT, where the Internet can be defined as a global network of interconnected computer networks based on a standard communication protocol, the Internet suite (TCP/IP),” and “thing” is an unidentified object. As a result, the term “IoT” refers to a “global network of interconnected, uniquely addressable objects based on standard communication protocols.”(iii)
“IoT enables people and things to connect anytime, anywhere, with anything and anyone, ideally over any path or network and using any service.”Other definitions are as follows:(i)
“A dynamic global network infrastructure with self-configuring capabilities based on standard and interoperable communication protocols where physical and virtual ‘Things’ have identities, physical attributes, and virtual personalities and use intelligent interfaces, and are seamlessly integrated into the information network [37].”(ii)
“Things having identities and virtual personalities operating in smart spaces using intelligent interfaces to connect and communicate within social, environmental, and user contexts [38].”According to Cabine [34], “things in the IoT can refer to a wide variety of devices such as heart monitoring implants, biochip transponders on farm animals, automobiles with built-in sensors, or field operation devices that assist firefighters in search and rescue. Current market examples include smart thermostat systems and washer/dryers that utilize Wi-Fi for remote monitoring.” The US National Intelligence Council (NIC), in their description of IoT in April 2008, considers IoT as one of the 6 Disruptive Civil Technologies. The IEEE ranks IoT number 1 in the list of “Top Trends for 2013.” The IoT promises to be the most disruptive technological revolution since the advent of the World Wide Web. According to Cabine [34], “projections indicate that up to 100 billion uniquely identifiable objects will be connected to the Internet by 2020.”The implementation of a SIS made it possible to monitor, manage, and control various variables in agriculture, thanks to technological advancements in sensor networks (SNs). Recent advances in sensor and wireless radio frequency (RF) machineries, as well as their merging with the Internet, have opened up a slew of new possibilities for agricultural sensor systems. The IoT and SN are two of the most important technologies driving the development of SIS. The technology issues with SIS revolve around improving the SN’s efficiency and the system’s ability to function and perform efficiently. NS to explicate important environmental patterns and integrate their data streams not only to display or record information, but also to stimulate human and self-sufficient (autonomous) responses, will result in increased agricultural efficiency. The IoT architecture adopted and designed for this study is shown in Figure1.Figure 1
IoT architecture designed for this study.


## 2.1. Overview and Use of IoT

Ashton [33] coined the term “IoT,” and RFID-based item identification systems were also invented in the same year. According to Kashif and Poonguzhali [30], IoT research is still early. As a result, there is no universally accepted definition for IoT. Cabine [34] described “IOT as the ever-growing network of physical objects that feature an IP address for Internet connectivity and the communication that occurs between these objects and other internet-enabled devices and systems.” It is also referred to as machine-to-machine (M2M), sky net, or Internet of everything, things having identities and virtual personalities operating in smart spaces using intelligent interfaces to connect and communicate within social, environmental, and user contexts. A variety of scholars provided the definitions below as adopted and modified from Silverio-Fernández et al. [35] and Sethi and Sarangi [36]:(i)
“Things have virtual personalities that operate in smart spaces using intelligent interfaces to connect and communicate within social, environmental, and user contexts.”(ii)
“The semantic origin of the expression is composed of two words and concepts: IoT, where the Internet can be defined as a global network of interconnected computer networks based on a standard communication protocol, the Internet suite (TCP/IP),” and “thing” is an unidentified object. As a result, the term “IoT” refers to a “global network of interconnected, uniquely addressable objects based on standard communication protocols.”(iii)
“IoT enables people and things to connect anytime, anywhere, with anything and anyone, ideally over any path or network and using any service.”Other definitions are as follows:(i)
“A dynamic global network infrastructure with self-configuring capabilities based on standard and interoperable communication protocols where physical and virtual ‘Things’ have identities, physical attributes, and virtual personalities and use intelligent interfaces, and are seamlessly integrated into the information network [37].”(ii)
“Things having identities and virtual personalities operating in smart spaces using intelligent interfaces to connect and communicate within social, environmental, and user contexts [38].”According to Cabine [34], “things in the IoT can refer to a wide variety of devices such as heart monitoring implants, biochip transponders on farm animals, automobiles with built-in sensors, or field operation devices that assist firefighters in search and rescue. Current market examples include smart thermostat systems and washer/dryers that utilize Wi-Fi for remote monitoring.” The US National Intelligence Council (NIC), in their description of IoT in April 2008, considers IoT as one of the 6 Disruptive Civil Technologies. The IEEE ranks IoT number 1 in the list of “Top Trends for 2013.” The IoT promises to be the most disruptive technological revolution since the advent of the World Wide Web. According to Cabine [34], “projections indicate that up to 100 billion uniquely identifiable objects will be connected to the Internet by 2020.”The implementation of a SIS made it possible to monitor, manage, and control various variables in agriculture, thanks to technological advancements in sensor networks (SNs). Recent advances in sensor and wireless radio frequency (RF) machineries, as well as their merging with the Internet, have opened up a slew of new possibilities for agricultural sensor systems. The IoT and SN are two of the most important technologies driving the development of SIS. The technology issues with SIS revolve around improving the SN’s efficiency and the system’s ability to function and perform efficiently. NS to explicate important environmental patterns and integrate their data streams not only to display or record information, but also to stimulate human and self-sufficient (autonomous) responses, will result in increased agricultural efficiency. The IoT architecture adopted and designed for this study is shown in Figure1.Figure 1
IoT architecture designed for this study.


## 3. Materials and Methods

### 3.1. Specification of Adopted and Designed IoT Components

Several microcontrollers that can be used, but the ESP8266 NodeMCU development board has been adopted in this study (Figure2). The ESP8266EX includes a Tensilica L106 32-bit RISC processor that consumes very little power and runs at a maximum clock speed of 160 MHz. Thanks to the real-time operating system (RTOS) and Wi-Fi stack, 80% of the processing power is available for user application programming and development, which combines elements of easy programming with the Arduino IDE (C++). It includes an 802.11 b/g/n HT40 Wi-Fi transceiver, allowing it to connect to a Wi-Fi network and interact with the Internet, as well as create its own network for other devices to connect to. There is also 128 Kb of RAM and 4 Mb of Flash memory (for program and data storage), which is more than enough to handle the large strings that make up web pages, JSON/XML data, and anything else we throw at IoT devices.Figure 2
E8266 node microcontroller unit pinout SP (as adopted from SPhttps://www.make-it.ca/nodemcu-details-specifications/).A resistance temperature device (RTD) DS18B20 waterproof temperature sensor was used in this study (Figure3). This sealed digital temperature probe lets one precisely measure temperature in wet environments with a sample 1-wire interface. The DS18B20 provides 9- to 12-bit (configurable) temperature readings over a 1-wire interface, so that only one wire (and ground) needs to be connected to a central microprocessor.Figure 3
Temperature sensor probe (as adopted fromhttps://www.med-linket.com/products/temperature/?gclid=Cj0KCQjwyYKUBhDJARIsAMj9lkEILNuL8rZfc7x9BLNb4a3nYZhb-Gw2XWm2SDcb1uyk50hrph80JxwaAi4XEALw_wcB).A corrosion-resistant soil moisture sensor was incorporated to measure the moisture content of the soil (Figure4). It contains two probes: the positive (+) end is connected to the positive power supply, and the negative (−) end is connected to the negative pole of the power supply. The blue potentiometer adjusts clockwise/counter-clockwise to decrease the probe detection sensitivity. It will show that the adjustment range has been tested, and at the time, the indicator is on. AO is an analogue (voltage) output, which can be directly detected by the AD port of the microcontroller.Figure 4
Corrosion-resistant soil moisture sensor (as adopted fromhttps://www.google.com/search?q=Corrosion+resistant+soil+moisture+sensor&sxsrf=ALiCzsYyihdrRw4DnK5bNiEfeVGnJA).A real-time clock (RTC) DS3231 RTC was adopted in this study (Figure5). It is an I2C RTC with an integrated temperature-compensated crystal oscillator (TCXO) and crystal that is low cost and extremely accurate. The device has a battery input and maintains accurate timekeeping even when the device’s main power is lost. The RTC keeps track of seconds, minutes, hours, days, dates, months, and years. For months with fewer than 31 days, the date at the end of the month is automatically adjusted, including leap year corrections. The clock has a 24-hour or 12-hour format, as well as an active-low AM/PM indicator.Figure 5
RTC DS3231 RTC (as adopted fromhttps://learn.adafruit.com/adafruit-ds3231-precision-rtc-breakout).The Sim800L GSM module was used in this study. It is easy to connect to Arduino and other microcontroller units. It has a 100% high quality, 3.75% work voltage, Quad-Band 850/900/1800/1900 MHz network support that would work on GSM networks in all countries around the world, and a transistor-transistor logic serial interface that is compatible with 3.3 V and 5 V. Pinout for the Sim800L GSM module is shown in Figure6.Figure 6
Sim800L GSM module pinout (as adopted fromhttps://components101.com/wireless/sim800l-gsm-module-pinout-datasheet-equivalent-circuit-specs).The Nokia 5110 LCD display was incorporated in this research. The module was designed to work with the long-lasting Nokia 5110 mobile phone, as the name suggests. The PCD8544 is a low-power CMOS LCD controller/driver that is designed to drive a graphic display with 48 rows and 84 columns. It includes on-chip generation of LCD supply and bias voltages, resulting in low-power consumption, making it suitable for power-constrained applications. The LCD only uses 6 to 7 milliamps in its normal state. All the components were interfaced on a PCB board. Components are typically soldered to the PCB in order to connect them electrically and mechanically. The number of pinouts on the LCD and a description of each pinout are shown in Figure7.Figure 7
The Nokia 5110 LCD pinout (as adopted fromhttps://components101.com/displays/nokia-5110-lcd).


### 3.2. Data Collection

The SIS was designed and implemented as an IoT device used for automated modelling and sequential data collection of real-time measurements of environmental parameters such as soil moisture values, soil temperature values, sunlight, rainfall, temperature, humidity, and pump action using an adaptive sampling technique [25, 26]. This technique enabled the collection of samples from a small vegetable garden in Abuja, Nigeria. The workflow followed in the development of SIS is as follows:(1)
Boot the system.(2)
Get soil temperature and soil moisture data from sensors.(3)
Search and connect to Wi-Fi and create a hotspot (smart farm).(4)
Restart the system if the Wi-Fi connection fails.(5)
Download the weather forecast for your current location (Abuja); this includes the amount of sunshine, humidity, rainfall, and atmospheric temperature.(6)
If any download fails, restart the system (jump to 1).(7)
Upload soil data as well as a weather forecast to the ThingSpeak channel.(8)
Restart the system if the upload fails.(9)
Refresh all of the data on the LCD.(10)
If the system boot time is less than one minute, send a start-up SMS and make a phone call.(11)
If there is an incoming GSM call, then send SMS and call.(12)
Check the RTC for the time of day.(13)
If the time of day (x) is (7 × 11) OR (7 × 11) AND the soil moisture threshold value AND the rainfall (50%).(14)
Update soil data (soil temperature and soil moisture).(15)
If the time between the last download and upload was more than 15 minutes, skip to step 5; otherwise, skip to step 9.The classification model was designed to manage real-world data and logical levels are used to classify data, categorizing the various parameters and evaluating and meeting the water requirements for a crop. The data values collected every 15 minutes were sent to the IoT CC platform “ThingSpeak” to predict the threshold status of water requirements. The data-driven approximation model, known as the data model, approach was used. The model uses a response from the emulator for design optimization, analysis, exploration, and performance evaluation. Improving the workflow involved following the iterative process in the sequential design, with an adaptive sampling algorithm selecting data points in each iteration, guided by a dataset that has already been retrieved and stored in the cloud (see Figures8 and 9). From Figure 8, we can view the information collected by the SIS downloaded from the CC platform “ThingSpeak.com” using Microsoft Excel and processed using Jupyter Notebook and Python to extract information.Figure 8
The first 10 rows of the dataset.Figure 9
The last 10 rows of the dataset.


### 3.3. Implementation of Software and Hardware

The implementation of the SIS involves the integration of both hardware and software components, which was required as one of the methodologies to be followed. For hardware design, we used physical components, which are necessary to implement the new system. This system was broken down into different units as listed below: power control unit, GSM module unit, moisture and temperature sensor unit, RTC unit, microcontroller unit, LCD display unit, and the printed circuit board (PCB). The software design approach involves sets of tools that are required to run the system effectively. They include the following:(i)
Arduino IDE for Firmware design using C/C++(ii)
An application browser such as Internet Explorer or Netscape Navigator.(iii)
Use Notepad++ for web interface design using HTML, CSS, and JavaScript programs to run it.(iv)
An Internet service provider (ISP) or a Wi-Fi modem to facilitate logging into the system.(v)
Python for over-the-air (OTA) upload of data collected and system update.(vi)
Use the ThingSpeak channel for data visualization.(vii)
Anaconda and Jupyter Notebook for data analysis.(viii)
Using the ES8266 (SOC) system on chip as the system web serverThe approach involves breaking down a system into smaller units to get more insight into its compositional subsystems in a reverse engineering way. Figure10 shows the block and circuit diagram of the SIS.Figure 10
The block and circuit diagram of the SIS.


### 3.4. Working Mechanism of the SIS

The proposed SIS was designed and implemented with the capability to make smart decisions when water is required by plants considering environmental factors such as rain, sunlight, temperature, humidity, soil moisture, soil temperature, and weather forecast. There is an apparent relationship between these environmental factors, and all of the logical relationships between these environmental factors will be determined by the SIS design, and it is crucial for the implementation of the SIS system. The data values collected every 15 minutes to predict the threshold status of water requirement are sent to the IoT CC platform “ThingSpeak,” a platform for data collection, storage, analytics, and visualization. The data model is designed to manage real-world data and logical levels are used to classify data, categorizing the various parameters and evaluating and meeting the water requirements for a particular plant. Sensor data and weather forecast data are used to make smart decisions for watering plants based on the ontology, and a machine learning model is used to evaluate the performance of the system and can be deployed with the ontology to make smarter decisions to actuate autonomous responses (i.e., start and stop the pump). A web application can be used to monitor and control system response. Figure11 shows the working prototype of the SIS.Figure 11
The working prototype of the SIS.


### 3.5. System Coding and Implementation

Different hardware and software tools were used in the design and implementation of the SIS, but the central focus here is using the IoT to produce autonomous responses using data analytics. However, in this project, we focus on the utilization of “ThingSpeak,” a MATLAB platform for data collection, data visualization, data processing, and analysis (MATLAB tool, adopted fromhttps://www.mathworks.com). The system was programmed so that it uses data retrieved from the system to perform irrigation.


## 3.1. Specification of Adopted and Designed IoT Components

Several microcontrollers that can be used, but the ESP8266 NodeMCU development board has been adopted in this study (Figure2). The ESP8266EX includes a Tensilica L106 32-bit RISC processor that consumes very little power and runs at a maximum clock speed of 160 MHz. Thanks to the real-time operating system (RTOS) and Wi-Fi stack, 80% of the processing power is available for user application programming and development, which combines elements of easy programming with the Arduino IDE (C++). It includes an 802.11 b/g/n HT40 Wi-Fi transceiver, allowing it to connect to a Wi-Fi network and interact with the Internet, as well as create its own network for other devices to connect to. There is also 128 Kb of RAM and 4 Mb of Flash memory (for program and data storage), which is more than enough to handle the large strings that make up web pages, JSON/XML data, and anything else we throw at IoT devices.Figure 2
E8266 node microcontroller unit pinout SP (as adopted from SPhttps://www.make-it.ca/nodemcu-details-specifications/).A resistance temperature device (RTD) DS18B20 waterproof temperature sensor was used in this study (Figure3). This sealed digital temperature probe lets one precisely measure temperature in wet environments with a sample 1-wire interface. The DS18B20 provides 9- to 12-bit (configurable) temperature readings over a 1-wire interface, so that only one wire (and ground) needs to be connected to a central microprocessor.Figure 3
Temperature sensor probe (as adopted fromhttps://www.med-linket.com/products/temperature/?gclid=Cj0KCQjwyYKUBhDJARIsAMj9lkEILNuL8rZfc7x9BLNb4a3nYZhb-Gw2XWm2SDcb1uyk50hrph80JxwaAi4XEALw_wcB).A corrosion-resistant soil moisture sensor was incorporated to measure the moisture content of the soil (Figure4). It contains two probes: the positive (+) end is connected to the positive power supply, and the negative (−) end is connected to the negative pole of the power supply. The blue potentiometer adjusts clockwise/counter-clockwise to decrease the probe detection sensitivity. It will show that the adjustment range has been tested, and at the time, the indicator is on. AO is an analogue (voltage) output, which can be directly detected by the AD port of the microcontroller.Figure 4
Corrosion-resistant soil moisture sensor (as adopted fromhttps://www.google.com/search?q=Corrosion+resistant+soil+moisture+sensor&sxsrf=ALiCzsYyihdrRw4DnK5bNiEfeVGnJA).A real-time clock (RTC) DS3231 RTC was adopted in this study (Figure5). It is an I2C RTC with an integrated temperature-compensated crystal oscillator (TCXO) and crystal that is low cost and extremely accurate. The device has a battery input and maintains accurate timekeeping even when the device’s main power is lost. The RTC keeps track of seconds, minutes, hours, days, dates, months, and years. For months with fewer than 31 days, the date at the end of the month is automatically adjusted, including leap year corrections. The clock has a 24-hour or 12-hour format, as well as an active-low AM/PM indicator.Figure 5
RTC DS3231 RTC (as adopted fromhttps://learn.adafruit.com/adafruit-ds3231-precision-rtc-breakout).The Sim800L GSM module was used in this study. It is easy to connect to Arduino and other microcontroller units. It has a 100% high quality, 3.75% work voltage, Quad-Band 850/900/1800/1900 MHz network support that would work on GSM networks in all countries around the world, and a transistor-transistor logic serial interface that is compatible with 3.3 V and 5 V. Pinout for the Sim800L GSM module is shown in Figure6.Figure 6
Sim800L GSM module pinout (as adopted fromhttps://components101.com/wireless/sim800l-gsm-module-pinout-datasheet-equivalent-circuit-specs).The Nokia 5110 LCD display was incorporated in this research. The module was designed to work with the long-lasting Nokia 5110 mobile phone, as the name suggests. The PCD8544 is a low-power CMOS LCD controller/driver that is designed to drive a graphic display with 48 rows and 84 columns. It includes on-chip generation of LCD supply and bias voltages, resulting in low-power consumption, making it suitable for power-constrained applications. The LCD only uses 6 to 7 milliamps in its normal state. All the components were interfaced on a PCB board. Components are typically soldered to the PCB in order to connect them electrically and mechanically. The number of pinouts on the LCD and a description of each pinout are shown in Figure7.Figure 7
The Nokia 5110 LCD pinout (as adopted fromhttps://components101.com/displays/nokia-5110-lcd).


## 3.2. Data Collection

The SIS was designed and implemented as an IoT device used for automated modelling and sequential data collection of real-time measurements of environmental parameters such as soil moisture values, soil temperature values, sunlight, rainfall, temperature, humidity, and pump action using an adaptive sampling technique [25, 26]. This technique enabled the collection of samples from a small vegetable garden in Abuja, Nigeria. The workflow followed in the development of SIS is as follows:(1)
Boot the system.(2)
Get soil temperature and soil moisture data from sensors.(3)
Search and connect to Wi-Fi and create a hotspot (smart farm).(4)
Restart the system if the Wi-Fi connection fails.(5)
Download the weather forecast for your current location (Abuja); this includes the amount of sunshine, humidity, rainfall, and atmospheric temperature.(6)
If any download fails, restart the system (jump to 1).(7)
Upload soil data as well as a weather forecast to the ThingSpeak channel.(8)
Restart the system if the upload fails.(9)
Refresh all of the data on the LCD.(10)
If the system boot time is less than one minute, send a start-up SMS and make a phone call.(11)
If there is an incoming GSM call, then send SMS and call.(12)
Check the RTC for the time of day.(13)
If the time of day (x) is (7 × 11) OR (7 × 11) AND the soil moisture threshold value AND the rainfall (50%).(14)
Update soil data (soil temperature and soil moisture).(15)
If the time between the last download and upload was more than 15 minutes, skip to step 5; otherwise, skip to step 9.The classification model was designed to manage real-world data and logical levels are used to classify data, categorizing the various parameters and evaluating and meeting the water requirements for a crop. The data values collected every 15 minutes were sent to the IoT CC platform “ThingSpeak” to predict the threshold status of water requirements. The data-driven approximation model, known as the data model, approach was used. The model uses a response from the emulator for design optimization, analysis, exploration, and performance evaluation. Improving the workflow involved following the iterative process in the sequential design, with an adaptive sampling algorithm selecting data points in each iteration, guided by a dataset that has already been retrieved and stored in the cloud (see Figures8 and 9). From Figure 8, we can view the information collected by the SIS downloaded from the CC platform “ThingSpeak.com” using Microsoft Excel and processed using Jupyter Notebook and Python to extract information.Figure 8
The first 10 rows of the dataset.Figure 9
The last 10 rows of the dataset.


## 3.3. Implementation of Software and Hardware

The implementation of the SIS involves the integration of both hardware and software components, which was required as one of the methodologies to be followed. For hardware design, we used physical components, which are necessary to implement the new system. This system was broken down into different units as listed below: power control unit, GSM module unit, moisture and temperature sensor unit, RTC unit, microcontroller unit, LCD display unit, and the printed circuit board (PCB). The software design approach involves sets of tools that are required to run the system effectively. They include the following:(i)
Arduino IDE for Firmware design using C/C++(ii)
An application browser such as Internet Explorer or Netscape Navigator.(iii)
Use Notepad++ for web interface design using HTML, CSS, and JavaScript programs to run it.(iv)
An Internet service provider (ISP) or a Wi-Fi modem to facilitate logging into the system.(v)
Python for over-the-air (OTA) upload of data collected and system update.(vi)
Use the ThingSpeak channel for data visualization.(vii)
Anaconda and Jupyter Notebook for data analysis.(viii)
Using the ES8266 (SOC) system on chip as the system web serverThe approach involves breaking down a system into smaller units to get more insight into its compositional subsystems in a reverse engineering way. Figure10 shows the block and circuit diagram of the SIS.Figure 10
The block and circuit diagram of the SIS.


## 3.4. Working Mechanism of the SIS

The proposed SIS was designed and implemented with the capability to make smart decisions when water is required by plants considering environmental factors such as rain, sunlight, temperature, humidity, soil moisture, soil temperature, and weather forecast. There is an apparent relationship between these environmental factors, and all of the logical relationships between these environmental factors will be determined by the SIS design, and it is crucial for the implementation of the SIS system. The data values collected every 15 minutes to predict the threshold status of water requirement are sent to the IoT CC platform “ThingSpeak,” a platform for data collection, storage, analytics, and visualization. The data model is designed to manage real-world data and logical levels are used to classify data, categorizing the various parameters and evaluating and meeting the water requirements for a particular plant. Sensor data and weather forecast data are used to make smart decisions for watering plants based on the ontology, and a machine learning model is used to evaluate the performance of the system and can be deployed with the ontology to make smarter decisions to actuate autonomous responses (i.e., start and stop the pump). A web application can be used to monitor and control system response. Figure11 shows the working prototype of the SIS.Figure 11
The working prototype of the SIS.


## 3.5. System Coding and Implementation

Different hardware and software tools were used in the design and implementation of the SIS, but the central focus here is using the IoT to produce autonomous responses using data analytics. However, in this project, we focus on the utilization of “ThingSpeak,” a MATLAB platform for data collection, data visualization, data processing, and analysis (MATLAB tool, adopted fromhttps://www.mathworks.com). The system was programmed so that it uses data retrieved from the system to perform irrigation.


## 4. Results and Discussions

The SIS master node controller controls the processes using the workflow. The sensor devices and web logs or data files are submitted (using the nativePython library). To track results, an integrated web service built with ThingSpeak was created using the LCD interface or visualized using a web interface to monitor results. It displays the content of the output directory processes and the model data, including channel information, model graphs or plots, and configuration used over the HTTP protocol, which was aggregated into a web page. ThingSpeak sets up a WebSocket to collect and process the log messages of events. It also uses the Java Logging API, which sends the message to the WebSocket. The GSM module aids in sending SMS to a mobile, which is also used to monitor system status. For each field, the channel is updated and the visualization can be viewed in Figures 12–14 for the soil temperature, soil moisture, and rainfall, respectively.Figure 12
Soil temperature.Figure 13
Soil moisture.Figure 14
Rainfall.From Figure12, the soil temperature drops with time as the day light/sunshine goes down. From the figure, the temperature dropped from 23° to 21° after 4:00 pm.From Figure13, the graph shows the variations in the water content in the soil as it flows down with time. The highest value of soil moisture was reached.From Figure14, it is evident from the graph that no rainfall was recorded between these times. As this research depends on using rain information to predict irrigation schedules, the system will wait for rain to water the plant if there is a possibility of rain.The data from sensors (i.e., moisture and temperature, humidity reading), sprinkler/pump state, and web (i.e., rain, sunshine, temp) are loaded from the SIS and displayed on the LCD. The data (system status) are output on the LCD. The LCD display (output) is shown in Figure15.Figure 15
LCD output.The ESP8266 Node MCU can execute as a whole standalone system, reducing stack overhead on the main application processor. It is used as a web server to display system status on my web interface. The ESP8266 can interface with other systems to provide “Wi-Fi and Bluetooth functionality.” It can be viewed when you connect to the SIS Wi-Fi and then open the web browser and enter 192.168.4.1. It displays the result as a set of tables showing the output for each event, as shown in Figure16.Figure 16
Web interface display.However, the “A6 GSM Module” provides a serial port to communicate through GPRS, sending information in phone calls and text messages. The void A6_sms_send() function enables sending SMS to my phone number. It can also make calls using the void ctrl_call() function to alert you that the system is now active or activated for irrigation, monitoring, and control, as shown in Figures17 and 18.Figure 17
SMS.Figure 18
Call management.


### 4.1. Techniques for Model Evaluation and Analysis

Data analysis was developed for effective system performance. A web application is employed to monitor and control the status of the system. A supervised machine learning approach was used according to Mohammad and Sulaiman [39]. There are threshold metrics for classification evaluations using the confusion matrix as our model evaluation matrix. There is a list of rates that are computed from the confusion matrix for a binary classifier and multiclass classification as shown in Table 1.Table 1
The threshold metrics for classification evaluations.
MetricsFormulaEvaluation focusAccuracy (acc)tp+tn/tp+fp+tn+fnIn general, the accuracy metric measures the ratio of correct predictions over the total number of instances evaluated.Error rate (err)fp+fn/tp+fp+tn+fnMisclassification error measures the ratio of incorrect predictions over the total number of instances evaluated.Sensitivity (sn)tp/tp+fnThis metric is used to measure the fraction of the positive patterns that are correctly classified.Specificity (sp)tn/tn+fpThis metric is used to measure the fraction of the negative patterns that are correctly classified.Precision (p)tp/tp+fpPrecision is used to measure the positive patterns that are correctly predicted from the total predicted patterns in a positive class.Recall (r)tp/tp+tnRecall is used to measure the fraction of the positive patterns that are correctly classified.F-measure (FM)2×p×r/p+rThis metric represents the harmonic mean between recall and precision values.Geometric-mean (GM)tp×tnThis metric is used to maximize thetp rate and tn rate, and simultaneously keeping both rates relatively balanced.Averaged accuracy∑i=1itpi+tni/tpi+fni+fpi+/iThe average effectiveness of all classes.Averaged error rate∑i=1ifpi+fni/tpi+fni+fpi+/iThe average errors of all classes.Averaged precision∑i=1itpi/tpi+fpi/iThe average of per-class precision.Averaged recall∑i=1itpi/tpi+fni/iThe average of per-class recall.AveragedF-measure2×pm×rm/pm+rmThe average of per-classF-measure.Note: Each class of data;tpi—true positive for Ci; fpi—false positive for Ci; fni—false negative for Ci; tni—true negative for Ci; and m—macro-averaging.


### 4.2. Summary of Evaluation Results

Based on the data analysis, the following major finding was discovered: the first feature could be summarized by the “confusion matrix” in Table2.Table 2
The “confusion matrix” table.
Predicted “ON”Predicted “OFF”Actual “ON”TP = 2386FP = 811Actual “OFF”TN = 188FN = 191Represented as “true positive (TP) = 2386, true negative (TN) = 188, false positive (FP = 191), and false negative (TN) = 188.” The results from the confusion matrix are shown in the classification summary results, which shows the accuracy to be 0.89, which is high, the misclassification rate (error rate) is equal to 0.1, the sensitivity is high and is equal to 0.79, the specificity is equal to 0.93, and the precision of the model is 0.81.The evaluation is compared with another machine learning algorithm like K-NN usingK = 6 and K = 1. The prediction accuracy was evaluated, and it shows that KNN is 0.97 and 0.98. k = 6 and k = 1 have a higher score for prediction accuracy. This implies that the smart system irrigation system has a high accuracy capable of predicting the water needs of plants up to 98%.The advantages of the SIS controller design used in this study when compared to other previous designs are evident owing to its cost-effectiveness and efficiency. It is, however, suggested that more advancement of this SIS controller design should be prospectively given appropriate attention subsequently.


## 4.1. Techniques for Model Evaluation and Analysis

Data analysis was developed for effective system performance. A web application is employed to monitor and control the status of the system. A supervised machine learning approach was used according to Mohammad and Sulaiman [39]. There are threshold metrics for classification evaluations using the confusion matrix as our model evaluation matrix. There is a list of rates that are computed from the confusion matrix for a binary classifier and multiclass classification as shown in Table 1.Table 1
The threshold metrics for classification evaluations.
MetricsFormulaEvaluation focusAccuracy (acc)tp+tn/tp+fp+tn+fnIn general, the accuracy metric measures the ratio of correct predictions over the total number of instances evaluated.Error rate (err)fp+fn/tp+fp+tn+fnMisclassification error measures the ratio of incorrect predictions over the total number of instances evaluated.Sensitivity (sn)tp/tp+fnThis metric is used to measure the fraction of the positive patterns that are correctly classified.Specificity (sp)tn/tn+fpThis metric is used to measure the fraction of the negative patterns that are correctly classified.Precision (p)tp/tp+fpPrecision is used to measure the positive patterns that are correctly predicted from the total predicted patterns in a positive class.Recall (r)tp/tp+tnRecall is used to measure the fraction of the positive patterns that are correctly classified.F-measure (FM)2×p×r/p+rThis metric represents the harmonic mean between recall and precision values.Geometric-mean (GM)tp×tnThis metric is used to maximize thetp rate and tn rate, and simultaneously keeping both rates relatively balanced.Averaged accuracy∑i=1itpi+tni/tpi+fni+fpi+/iThe average effectiveness of all classes.Averaged error rate∑i=1ifpi+fni/tpi+fni+fpi+/iThe average errors of all classes.Averaged precision∑i=1itpi/tpi+fpi/iThe average of per-class precision.Averaged recall∑i=1itpi/tpi+fni/iThe average of per-class recall.AveragedF-measure2×pm×rm/pm+rmThe average of per-classF-measure.Note: Each class of data;tpi—true positive for Ci; fpi—false positive for Ci; fni—false negative for Ci; tni—true negative for Ci; and m—macro-averaging.


## 4.2. Summary of Evaluation Results

Based on the data analysis, the following major finding was discovered: the first feature could be summarized by the “confusion matrix” in Table2.Table 2
The “confusion matrix” table.
Predicted “ON”Predicted “OFF”Actual “ON”TP = 2386FP = 811Actual “OFF”TN = 188FN = 191Represented as “true positive (TP) = 2386, true negative (TN) = 188, false positive (FP = 191), and false negative (TN) = 188.” The results from the confusion matrix are shown in the classification summary results, which shows the accuracy to be 0.89, which is high, the misclassification rate (error rate) is equal to 0.1, the sensitivity is high and is equal to 0.79, the specificity is equal to 0.93, and the precision of the model is 0.81.The evaluation is compared with another machine learning algorithm like K-NN usingK = 6 and K = 1. The prediction accuracy was evaluated, and it shows that KNN is 0.97 and 0.98. k = 6 and k = 1 have a higher score for prediction accuracy. This implies that the smart system irrigation system has a high accuracy capable of predicting the water needs of plants up to 98%.The advantages of the SIS controller design used in this study when compared to other previous designs are evident owing to its cost-effectiveness and efficiency. It is, however, suggested that more advancement of this SIS controller design should be prospectively given appropriate attention subsequently.


## 5. Conclusion

Although the study’s goals and objectives were met to a satisfactory level, a working prototype was developed, as shown in Figure11. The system was tested on a small vegetable farm that requires water in the morning and evening when the soil water level is below 50%, and irrigation is turned off when the required threshold value is reached. The entire process can be monitored and controlled using a web browser on a mobile phone or personal computer. The design saves farmers time and money on irrigation, improves efficiency, and increases crop yield. In the future, the focus should be on incorporating and integrating more sensors to collect more data, as well as CCTV cameras to deter intruders. For harvesting, farmers should use SIS in all areas. It is therefore recommended that due to the epileptic power supply from Nigerian power providers, solar power and backup batteries should be used to supplement the main power supply.



---

*Source: 7678570-2022-06-23.xml*