I've enhanced the code to ensure the flexibility of activating the relay at specified times. In the previous version, if there was a complete power outage in your home, the Arduino and Relay module would turn off due to lack of power. Additionally, the RTC module only adjusted the time when the power was restored, resulting in the relay not triggering to turn on or off.
Now, the modified code addresses this issue by allowing you to set specific times for triggering the relay. Even if there is a power outage during these times, both the Arduino and Relay module will remain off. The RTC module continues to update the time, but the relay will only be activated once power is restored. This updated code is essential for the Arduino to efficiently check and control the relay based on your desired schedule.
Ensure accurate configuration within the following if statement:
if ((currentHour == 17 && currentMinute >= 40) || (currentHour >= 18 && currentHour < 24) || (currentHour >= 0 && currentHour < 6))
In this statement, the first part (currentHour == 17 && currentMinute == 40) specifies the exact time to turn on the relay, while the second and third parts (currentHour >= 18 && currentHour < 24) || (currentHour >= 0 && currentHour < 6) cover the broader time range for turning on the relay if it happens to be off during that period. This code proves particularly valuable during power outages.