*4.3. Drip Irrigation Piping*

After the addition of soil, we drilled holes in two opposing walls and added the mainline, dripline, and drippers, as shown in Figure 11. We will connect the rest of the smart irrigation system to this basic drip irrigation setup later.

**Figure 11.** The addition of drip irrigation pipelines.

#### **5. Experiments and Discussion**

#### *5.1. Primary Tests in the Laboratory*

The initial tests were conducted in the lab to test the moisture sensor, temperature sensor, air humidity sensor, water flow sensor, solenoid valve, and firmware. The system was powered using a power supply. Using the relay, the ESP32 was able to control the solenoid valve. A loud click noise let us know when the valve was opened or closed. We calibrated the soil moisture sensor by first reading the value of the sensor in the air and then placing the probe in a glass of water and re-reading the value. After calibrating the moisture sensor, we proceeded to confirm that the ESP32, moisture sensor, and valve worked well together. To do so, we programmed the valve to open if the ESP32 was not in the cup of water. We then replaced the cup with a potted plant, re-calibrated the moisture sensor with the soil [36,37], and repeated the experiments.

We connected the DS18B20 temperature sensor to the ESP32 using the GPIO. As ESP32 does not have a dedicated 1-wire bus interface GPIO pin, we had to perform bit-banging on the GPIO to use the DS18B20. We followed the timing diagrams of the DS18B20 in order to write and read 1 s and 0 s. Lastly, we performed simple calibration by measuring the known temperatures [38]. We measured the temperatures of different objects with DS18B20 and compared them to the readings from a FLIR C3-X thermal camera. Figure 12a shows the temperature measured by the DS18B20 for a cup of hot water, and Figure 12b shows the thermal capture using the camera for the same cup. We repeated the temperature measurement with other test scenarios, and the results are shown in Table 2.

(**a**)

(**b**)

**Figure 12.** Measuring the temperature of a hot cup of water using the DS18B20 sensor and a thermal camera. (**a**) Temperature measured by the DS18B20 sensor. (**b**) Temperature measured by the thermal camera (FLIR C3-X, manufactured by Teledyne FLIR LLC, Wilsonville, OR, USA).


**Table 2.** Comparison of the DS18B20 temperature sensor with a thermal camera.

As the measured temperature difference was less than +/−1 °C, we then proceeded to connect the air humidity sensor and water flow sensor. We set up an interrupt on the ESP32 GPIO pin to read the pulses from the flow meter. To calibrate the sensor, we poured a known amount of water through the flow meter and checked if the sensor could calculate the amount of water that flowed through [39]. We observed that the error was less than one percent.

#### *5.2. Comparing the Sensor Readings to Weather Forecasts*

To test the accuracy of the sensor measurements in an outdoor environment, we took the readings from the DS18B20 soil temperature sensor and DHT22 air temperature and humidity sensor and compared them to the data gathered from timeanddate.com [40]. The test was conducted over a period of 4 h on 16 June 2023. Table 3 compares the temperature measured by the soil temperature sensor (DS18B20), air temperature sensor (DHT22), and the temperature data obtained from timeanddate.com (accessed on 16 June 2023).

**Table 3.** Comparison of temperatures.


As seen in the table, the air temperature measured by the DHT22 and the data obtained from timeanddate.com (accessed on 16 June 2023) match. The soil temperature measured by the DS18B20 was always slightly more than the air temperature. A comparison of the air humidity is shown in Table 4.

**Table 4.** Comparison of Temperature.


The measured and observed humidity slightly differ. The differences observed may be due to the differences in measurement locations. timeanddate.com (accessed on 16 June 2023) has a weather station set up at Doha International Airport; our tests were done in Abu Hamour on a windy day, with wind speeds reaching 37 km/h. Despite the slight differences, all the sensors performed well and are fit for the smart irrigation system.

#### *5.3. Testing the Solenoid Valve Outdoors*

We used a large 400 US gallon water tank for the irrigation system, as seen in Figure 13a. We also installed a pump motor to ensure the water flowed with enough pressure to open the solenoid valve. We placed the motor wiring in a container with a gasket lid to protect the connections from water and put an acrylic container sealed with silicone over the motor to provide some protection from the rain, as shown in Figure 13b. Lastly, we made holes in one of the walls of the container to provide air circulation for the motor.

Once the water tank was ready, we connected the solenoid valve to the pump motor. The electronic components were placed in a plastic container with a rubber gasket to protect them from water. The printed circuit boards (PCBs) were fastened into place using screws and a raiser. We designed a case for the barrel jack of the adapter and 3D-printed it. Next, we drilled holes into the walls of the container to allow wires to pass through and applied silicone to prevent moisture from entering the container. The field-ready kit can be seen in Figure 14a,b.

**Figure 13.** *Cont*.

(**a**)

(**b**) **Figure 13.** Water tank and pump motor for the irrigation system; (**a**) 400 US gallon water container; (**b**) water pump motor covered for water resistance.

(**b**)

**Figure 14.** Plastic container for the smart drip irrigation system. (**a**) Components of the irrigation system placed in the container. (**b**) Sealed container ready for outdoor use.

We tested the system and found that the solenoid valve worked well and would let water flow through as directed by the ESP32. We connected the solenoid valve outlet to the inlet of the water flow sensor. We made more acrylic containers sealed with silicone to improve the irrigation system's overall dust and water resistance. We placed one container over the extension board and the other electronics. We put the other container over the solenoid valve and flow sensor. The containers are shown in Figure 15a,b. To keep the wiring between the PCB and solenoid valves free of water, we 3D-printed a simple case and sealed it using glue and silicone. This case is shown in Figure 15c. We also placed the DHT22 humidity sensor in a plastic enclosure and sealed it with silicone, as shown in Figure 15d.

We found the irrigation system capable of withstanding dust and light rain due to all the containers and silicone.

(**b**)

(**c**)

**Figure 15.** Making the irrigation system water- and dust-resistant. (**a**) Protecting the electronics with an acrylic container. (**b**) Protecting the solenoid valve and water flow sensor with an acrylic container. (**c**) Protecting the solenoid wires with a 3D-printed case. (**d**) Protecting the DHT22 with a plastic case.

#### *5.4. Testing the Entire Smart Drip Irrigation System in the Field*

After confirming that the irrigation system was satisfactorily water- and dust-resistant, we connected the outlet of the water flow sensor to the drip irrigation system's mainline. We placed the drippers at different locations and positioned the moisture sensor and temperature sensor in the soil near one of the drippers. We placed the DHT22 on top of the acrylic case covering the valve. The entire smart drip irrigation system is shown in Figure 16.

We tested the system without any plants for the first few days and opened the valve for just ten minutes at a time. The water flow rate through the mainline was 10 L per hour, as per the flow meter sensor. We collected the water from the drippers using a bottle for ten minutes and measured it in a graduated cylinder. We repeated the tests multiple times and present our findings in Table 5. The average flow rate of 0.64 L per hour falls within the range specified by the manufacturer of the dripper [41].

**Test Number Mainline Flow Rate (lph) Flow Rate of Each Dripper (lph) Total Flow Rate of Eight Drippers (lph)** 1 16 0.71 5.68 2 10 0.59 4.72 3 12 0.66 5.28 4 10 0.60 4.8 5 12 0.66 5.28

**Table 5.** Measured flow rate of the mainline and drippers.

**Figure 16.** Smart drip irrigation system working in the field.

We programmed the ideal temperature range to be between 27–32 °C or 80.6–89.6 °F. While maximum water is used at a soil temperature of 59 °F [42], it is not a temperature that is easy to reach in the summer months. Hence, we continued our tests with an attainable temperature range. We also programmed the acceptable relative humidity range to be between 25% and 90%; 25% was set as the lower limit as most plants grow best with a relative humidity of over 50%. Although many plants will tolerate lower levels, only those native to arid regions will tolerate humidity below 25% [43]. If the humidity reading crossed the lower or upper limit, we received a notification on the Blynk app. For the most part, the system worked as we expected. The ESP32 opens the valve if the soil is dry and the current time and temperature are within the programmed ideal range. If the soil is moist, the ESP32 will not open the valve. However, we discovered some issues during our tests.

At times, even though the ESP32 had opened the valve once, the soil around the sensor was not moist. This delay led to the ESP32 opening the valve a second time and over-watering the soil. To combat this, we modified the firmware to block the valve from being opened twice on the same day if the water flow sensor was already triggered earlier the same day. Hence, the flow sensor confirms that the plants received water. It was possible to manually open the valve via the app if we needed to do so.

Additionally, if the tank was empty during the irrigation window, the ESP32 still opened the valve and considered that it had done its job, but the soil was dry. If there is a water shortage, the ESP32 might miss the irrigation window and not water the plants. We handled this issue by modifying the firmware and setting up a notification. We received an app notification if the irrigation window had passed, the flowmeter was never triggered, and the soil was dry even though the ESP32 opened the valve. The Blynk app notification allowed us to inspect the tank and soil and decide between manually opening the valve or waiting for the next irrigation time window. The modified flow chart accommodating the above changes is shown in Figure 17.

**Figure 17.** Final flow chart of the smart drip irrigation system firmware.

The most significant differences in the final flowchart occurred after confirming that the soil was dry. If the ESP32 conducts the moisture check within one of the irrigation time windows, it then checks if the valve was opened earlier today. If the system had opened the valve before, it would not open the valve again to prevent over-watering the plants. If the ESP32 has yet to open the valve and the temperature is in the ideal range, it will open the valve and water the plants.

Due to the extreme weather changes in Qatar this year, there were days when we were not even close to the ideal soil temperature for irrigation. We added a safety feature to ensure that the plants did not remain thirsty just because the soil was not at the ideal temperature. If the soil is dry, the ESP32 has not opened the valve as yet, and the evening time window is about to end, the ESP32 will open the valve to water the plants regardless and note down the temperature at the time of irrigation.

If the valve is opened once, the morning and evening irrigation time windows have passed, and the soil is still dry, the admin user will receive a notification about the dry soil. We can then decide if the valve needs to be opened manually through the app.

After we updated the ESP32 firmware according to the latest flowchart, we planted onion bulbs into the soil to grow spring onions. We placed the bulbs near the drippers. Later, we positioned the moisture sensor in the soil near one of the bulbs and drippers. We then opened the solenoid valve for sixty minutes compared to the ten minutes during the early testing phase. We then watered the onion bulbs.
