## 6 SWORD Algorithm  
The _SWORD_ algorithm (Figure 5) is designed and implemented in the microcontroller Atmega 328p of the sensor node to reduce power consumption. The _SWORD_ algorithm proceeds as follows:  
1. The microcontroller Atmega 328p initially wakes up from sleep mode. 2. All the components of the sensor node (i.e., sensors, microcontroller, and XBee S2C) are supplied with energy from a solar cell (12 V/5 W) at daytime to charge their batteries. The batteries are used to supply power to the sensor node at nighttime. 3. The microcontroller measures the climate conditions (i.e., air temperature, air humidity, and soil moisture). 4. The microcontroller measures the difference between the previous and subsequent soil moisture values (soil moisture difference = | previous value \(-\) subsequent value| ) to check whether redundant data exist. 5. When the difference between the two values is zero or less than or equal to 5% (threshold level), the sensors and the XBee S2C module enter sleep mode. Furthermore, the microcontroller goes to power-saving mode to save the energy of the sensor node. In such case, the soil is wet and no data are transmitted from the sensor node to the router node. In addition, irrigating the soil is unnecessary, thereby leading to water saving. The components of the sensor node remain in sleep mode until the threshold level is exceeded. A slight difference in value of 5% is selected to obtain a precise decision. In agriculture, irrigation systems depend on soil moisture measurements, wherein soil is considered a crucial part of planning tools for conducting irrigation [49; 50]. When soil is dry, the irrigation system is operating; otherwise, the irrigation system is off (i.e., wet soil). Therefore, the _SWORD_ algorithm is determined on the basis of soil moisture measurement in the current study. By using soil moisture, irrigation is scheduled to sustain soil moisture conditions equivalent or close to the field capacity to satisfy the required crop water requirements. In addition, several sensors are being considered for future work to capture relevant parameters related to agriculture, such as soil temperature, soil conductivity, salinity, leaf wetness, and rainfall sensors. 6. By contrast, all the components of the sensor node remain awake when the difference between the two values is greater than 5%. Therefore, the measured data in Step 3 are transmitted from the sensor node to the coordinator node via the router nodes. After the transmission process is completed, the sensors and XBee S2C module enter sleep mode. Furthermore, the microcontroller goes to power-saving mode to save the energy of the sensor node. The sensor node transmits the measured data about climate conditions every 15 min (900 s) for 2 s (i.e., extremely low DC 2/900 = 2.222 \(\times\) 10\({}^{-3}\)). The sensors require 1 s to measure the data on climate conditions. In addition, another second is required to transmit the data to the related router node, includingthe active transmission time of XBee S2C (i.e., 11.32 ms, as shown in the previous section) and the microcontroller. This situation indicates that 2 s are consumed by each sensor node to measure and transmit climate conditions to the related router node, as shown in the timing diagram in Figure 6. Consequently, each sensor node wakes up for 2 s and sleeps for 898 s.
7. The four sensor nodes communicate using one router node (Figure 1). Therefore, the allocated time for each router node is 16 s. From the 16 s, 8 s is for the four sensor nodes, whereas 8 s is for the guard time (2 s after data transmission of each sensor node to avoid data collision), as shown in Figure 6. The router nodes, such as RN1, RN2, RN3, and RN4, collect and transmit the data of the four sensor nodes to the main router node within 16 s and then enter sleep mode. Consequently, each router node wakes up for 16 s and sleeps for 884 s (i.e., extremely low DC 1.778 \(\times\) 10\({}^{-2}\)), as shown in Figure 6.
8.