## 4 The Software Implementation of the Dual-Axis-Based Solar Tracking System  
To deploy a modern, automated, IoT-based solar tracking device that optimizes the use of its hardware components and sensor modules while reducing overall power consumption, reliable software implementation is essential. The software code for the dual-axis solar tracker, written in C++, includes numerous variables and custom functions, necessitating the breakdown of the workflow diagram into several blocks for better comprehension of the automation process. As shown in Figure 4, the first block (a) features a custom homing function for calibrating the horizontal and vertical axes of the solar tracking system. The horizontal limit switch (HLS) and vertical limit switch (VLS) are continuously monitored in a while loop until both axes are positioned to face the sunrise each day. After the stepper motors complete their rotation and the homing function is achieved, the software proceeds to the second block (b) for the initial verification of the horizontal stepper (HS) and vertical stepper (VS). This function, assisted by rotary encoders, checks the functionality of both steppers. If the current clock impulse equals the previous one, indicating no rotation, the system sends an SMS alert to a repair service via the SIM800L GSM module. The application then pauses for 30 min, awaiting maintenance actions. Once the issue is resolved, the software checks the second motor similarly. If both motors are operational, the routine advances to the third block (c), which is for protection purposes and verifies wind speed (WS) using the custom-built anemometer. By collecting multiple voltage samples from the anemometer, an average value of 0.56 V was determined to correspond to a wind speed of 60 km per hour (kph). Moreover, the Arduino Mega 2560 board operates with analog-to-digital converters (ADCs) to convert incoming voltage values (0-5 V) into digital values (0-1023), with the help of the relation presented in Equation (2) [76]:  
\[\frac{R_{ADC}}{S_{V}}=\frac{ADCR}{AVM}, \tag{2}\]  
where \(R_{ADC}\) represents the resolution of the ADC, \(S_{V}\) designates the system voltage, \(ADCR\) is the ADC reading, and \(AVM\) represents the measured analog value. By substituting the known values, we obtain the digital equivalent of the analog voltage that we measured:  
\[\frac{1023}{5V}=\frac{ADCR}{AVM}\rightarrow\frac{1023}{5V}=\frac{ADCR}{0.56V} \to ADCR=\frac{1023\times 0.56V}{5V}=114 \tag{3}\]Thus, if two pairs of points exist in a Cartesian graph system \((x_{1},y_{1})\), respectively (\(x_{2}\), \(y_{2}\)), where \(x_{1}=0\), \(y_{1}=0\), \(x_{2}=114\), and \(y_{2}=60\), we can define the slope as in Equation (4):  
\[m=\frac{y_{2}-y_{1}}{x_{2}-x_{1}}=\frac{60-0}{114-0}=\frac{60}{114}=0.526\to y =m\times x\to y=0.526\times x, \tag{4}\]  
where \(m\) represents the conversion ratio between actual wind speed (\(y\)) and the measured analog value (\(x\)). Consequently, the software program will compare the registered analog readings to the value 114 (associated with 60 kph) and will then decide, based on the result, if the solar panel will be moved to the flat position, or otherwise, continue the solar tracking procedure. Similarly, in block (d), the solar radiation (SR) level is verified between two limits, \(\text{SR}_{\text{low}}=5000\,\text{lux}\) and \(\text{SR}_{\text{high}}=10,000\,\text{lux}\), which helps us establish if the weather conditions are proper for switching to solar tracking mode. Generally, if the SR value falls between the two limits, improper weather conditions appear, such as clouds or heavy fog, thus hindering the solar tracking system from harvesting the maximum capacity of solar energy.