**1. Introduction**

Agriculture, which involves the cultivation of crops and animals, is one of the most essential practices for maintaining and growing the human population. Not only does it provide nourishment to human beings, but it is also helpful in eliminating extreme poverty and boosting the economy of a country. Agriculture accounts for 4% of the global gross domestic product (GDP) and is projected to feed about 9.7 billion people by 2050 [1].

Agriculture has always depended on technology in one way or another. People used extremely simple tools for farming more than 12,000 years ago. The farm tools were often made of wood or animal bones [2]. As time went on, humans developed better tools for farming. By the second agricultural revolution in the U.S., tractors were a common sight in farmlands [3].

Water is essential for plant growth and the distribution of mineral nutrients. Irrigation involves the application of water to the soil through a system of pumps, tubes, and sprays. It is commonly used in areas where rainfall is low [4]. There are many different types of irrigation systems. For sustainable agriculture in desert countries, where efficient water use is necessary, drip irrigation systems are a great fit [5]. With drip irrigation, water is directly applied to the soil (close to the roots of the plants) in the form of droplets over time. The most significant advantage of drip irrigation systems compared to other systems is the amount of water saved [6,7].

We can use the Internet of Things (IoT) in any application that requires data collection, automation, or control. With the growing popularity of IoT, there has been an increase

**Citation:** Pereira, G.P.; Chaari, M.Z.; Daroge, F. IoT-Enabled Smart Drip Irrigation System Using ESP32. *IoT* **2023**, *4*, 221–243. https://doi.org/ 10.3390/iot4030012

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

Received: 15 May 2023 Revised: 14 June 2023 Accepted: 1 July 2023 Published: 7 July 2023

**Copyright:** © 2023 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/).

in the ideas surrounding smart agricultural technology [8,9]. In this paper, we designed a smart IoT-enabled drip irrigation system using an ESP32 microcontroller. The system comprises an ESP32, solenoid valve, soil moisture sensor, temperature sensor, air humidity sensor, and water flow sensor. We used the Blynk IoT mobile app and web dashboard to collect irrigation data, turn the automatic irrigation feature on or off, manually open the valve if needed, and plot temperature, soil moisture content, and air humidity graphs. Opening the valve allows water to reach the roots of the plants. The soil moisture sensor constantly checks if the soil is dry. If the soil is dry and the temperature is ideal, the ESP32 can automatically open the valve and irrigate the field. Based on the humidity sensor readings, the user can turn off the automatic irrigation feature or turn it back on.

We set out to grow green onions from onion bulbs. After a week of running the drip irrigation system, spring onions began to grow from a few onion bulbs. The irrigation for the week was conducted automatically by the system with no interference from the users. Each spring onion received 0.676 gallons of water over the week, which is a satisfactory outcome. We also plotted the weekly temperature, soil moisture, and air humidity graphs.

The remainder of the paper is organized as follows: Section 2 illustrates various relevant works and how we build upon them. Section 3 covers the overview of the entire system. Section 4 highlights the hardware used, with further details provided in Sections 4.1–4.3. Section 5 covers the results of the implementation and tests. Finally, Section 6 provides the conclusion and future scope of our project.

#### **2. Related Works**

There have been prior works on smart irrigation systems and smart drip irrigation systems [10,11]. Refs. [12,13] provide overviews of smart irrigation systems. They talk about wireless communications, irrigation methods, sensors applicable to smart irrigation systems, and types of monitoring in this field. Likewise, ref. [14] provides a detailed breakdown of irrigation monitoring, control, and the scheduling system, while [15] investigates the use cases, challenges, and issues of IoT in agriculture.

In ref. [16], a smart irrigation system was designed using a resistive soil moisture sensor, temperature sensor, water flow meter, and Arduino UNO single board computer (SBC). The system monitors temperature and soil moisture level, and if the soil becomes dry or the temperature exceeds 30 °C, the field is irrigated. Ref. [17] details a smart system that monitors and controls agricultural production using IoT. It monitors the data and provides it to the farmer, who can use the data to control the system remotely when needed, reducing the workload.

In ref. [18], a smart irrigation system was designed using a resistive soil moisture sensor, temperature sensor, air humidity sensor, and Arduino UNO SBC. The system monitors and displays the temperature and humidity readings. If the soil is too dry, the motor is powered on so that the soil receives water. Ref. [19] proposed an innovative design of a solar-powered smart drip irrigation system using a node microcontroller unit (MCU) that monitors temperature and humidity via a DHT11 sensor, and the soil moisture value determines when the pump turns on. Ref. [20] proposes a smart farm using a long-range wireless area network (LoRaWAN).

We built on the prior works in five crucial ways. Firstly, we used an ESP32 microcontroller. The ESP32 is cheap, has built-in Wi-Fi, and Blynk IoT officially supports the ESP32. Secondly, we offer improved automatic irrigation. The ESP32 takes into account the actual time of the day, soil moisture content, and soil temperature before opening the valve and watering the plants. The temperature readings are not available just for monitoring. We used the temperature readings to ensure that we watered the plants at the best temperature for maximum water absorption. Thirdly, we improved the monitoring and control features. Along with soil moisture and temperature, the ESP32 also monitors the humidity and notifies the user when the humidity is too low or too high. The user can then decide to switch off the automatic irrigation feature or manually open/close the valve based on the monitored values.

Fourthly, we set the duration of watering the plants through the drip irrigation system with the help of the flow sensor. Lastly, the ESP32 collected real-time data. We used these data to track the date and time of irrigation, and to help ensure that we did not accidentally water the plants multiple times in a single day, with assistance from the flow sensor.

#### **3. System Overview**

The overview of the IoT-enabled smart drip irrigation system is shown in Figure 1. The ESP32 is the brain of the system. We connected the ESP32 to different sensors and a relay. The temperature sensor probe and soil moisture sensor probe were inserted into the soil and monitored the soil temperature and moisture levels, respectively. The water flow sensor provides data on the water flow rate, and the humidity sensor measures the humidity of the air. The system opens the solenoid valve to water the plants using a relay. The ESP32 uses Wi-Fi to communicate with the mobile app or web dashboard via Blynk cloud. We used the Blynk app to collect irrigation data, manually control the valve, and plot the soil temperature fluctuation graph.

**Figure 1.** Overview of the IoT-enabled smart drip irrigation system [21].

It is best to water the plants in the morning or early in the evening. Watering the crops in the afternoon can lead to the water becoming hot and burning the plants. Watering the crops late in the evening may lead to water stagnation and encourage rot, fungal growth, and insects [22,23]. We used the hourly weather reports in Qatar [24,25] to set our morning irrigation window from 5 a.m. to 8 a.m. and evening irrigation window from 6 p.m. to 8 p.m. In these time windows, the weather is usually warm, and the temperature is between 24 °C and 30 °C, as shown in Figure 2. Using real-time data, the ESP32 will check the moisture and temperature of the soil within these time windows and water the plants if necessary.

We used an air humidity sensor to gather humidity data. If the temperature is very warm and the humidity is low, too much water will evaporate through transpiration. The water loss will lead to the plants attempting to absorb more water, and as they consume more water, they will consume more nutrients. Excess nutrients will cause the tips of the leaves to burn, and the leaves will wilt [26]. Hence, watering the soil when the humidity is too low may not be a good idea. The ESP32 will notify us if the humidity is too high or low. Based on the humidity readings, along with the other sensor data, we can turn the automatic irrigation feature on or off.

We can open the valve manually by using the app if there is a need to do so. The irrigation data are saved to the app as they help to recognize trends and eventually improve

the system. The irrigation data consist of the date and time of irrigation, the temperature of the soil at the time of irrigation, and the rate of the flow of water in the drip line.

**Figure 2.** The hourly reported temperature in Qatar for May 2023, color-coded into bands. The shaded overlays indicate night and civil twilight (source: www.weatherspark.com (accessed on 13 May 2023)) [27].

We interfaced the ESP32 with a moisture sensor, temperature sensor, air humidity sensor, water flow sensor, and solenoid valve. Using the data from these sensors, the ESP32 determines when to open the solenoid valve. The solenoid valve controls the flow of water into the pipes of the drip irrigation system. The flowchart highlighting the logic programmed into the ESP32 is shown in Figure 3.

**Figure 3.** Flow chart of the IoT-enabled smart drip irrigation system.

When we turn on the system, the ESP32 initializes its non-volatile storage (NVS) flash, Wi-Fi, real-time operating system (RTOS), soil moisture sensor, temperature sensor, air humidity sensor, and flow sensor. The ESP32 then connects to the Blynk servers and checks the moisture content of the soil, temperature, and humidity. If the irrigation system is currently set to automatic irrigation and if the soil is dry, it then obtains the current time of the day and compares it to the morning and evening irrigation time windows. If the time is within the irrigation time window, the ESP32 will check if the soil temperature is within the ideal range. If the temperature is within the ideal range for maximum water absorption, the ESP32 will open the valve for an hour and water the plants. The ESP32 will then wait ten minutes before checking the soil moisture level.

If the soil is dry but the current time is not within the irrigation time windows, the ESP32 will not open the valve. Similarly, if the temperature is not in the ideal range, the ESP32 will not open the valve. If the soil is humid during the moisture check, the ESP32 will keep the valve closed. An improved flowchart based on the results of our tests is presented in Section 5.

#### **4. Materials Used**

#### *4.1. Hardware*

The system's main hardware components are a microcontroller, moisture sensor, temperature sensor, air humidity sensor, water flow sensor, solenoid valve, relay, and a step-down transformer.

#### 4.1.1. Microcontroller—ESP32

The ESP32 is a low-cost, 32-bit microcontroller. It has built-in Bluetooth and Wi-Fi, making it useful for IoT applications. It can accommodate multiple sensors and devices with 48 general purpose input–output (GPIO) pins. We used the inbuilt Wi-Fi of the ESP32 to communicate with the Blynk mobile app or web dashboard. ESP32 sends irrigation information to Blynk cloud. We can control the valve or set the irrigation time using the mobile app.
