Programming Arduino Uno R3 to trigger a relay once every 24 hours I programmed Arduino UNO R3 to trigger a relay once every 24 hours from the moment it is powered on
I calculated milliseconds and used the function delay()
24 hours * 60 minutes each hour * 60 second every minute * 1000 milliseconds every second
so i used :
delay(86400000)

86 million and 400 thousands milliseconds
and currently i'm still testing it...
Will this work?
If not Is there a better built-in function/library or even external library to do it?
the relay trigger doesn't have to be very accurate at the very exact time each day
I don't need it to be very accurate, It can shift few minutes every few months or so, thats okay with me
But how about after few months or years of use ?
Will it shift the timing much ?
I read somewhere about using millis() function
and others use RTC (Real Time Clock) module
I don't want to use RTC module
Looking for a programmatical solution...
OR if my previous method using the delay() will work for such a very high number of millisecond ?
Thank you
Yes, the delay() will work, as will other methods based on the millis() counter. However, delay() will make it impossible to do something else in the meantime.
Look up Blink without delay for an example of how to accomplish such a delay while being able to do other things in your code while waiting.
Casting
When dealing with large numbers such as your 24-hour delay, make sure to explicitly cast those numbers as unsigned long, or expressing them with the &quot;UL&quot; extension (like for example 86400000UL). This explicitly tells C++ to expect an &quot;unsigned long&quot; (which in Arduino Uno terms is a 32-bit unsigned number).
In your case (with such an obviously large number), the compiler will automatically choose the right type. In other cases (for example, if you change the expression to 24*60*60*1000), the compiler will not automatically generate an unsigned long and you need to force it by changing the first part of the expression to an unsigned long: 24UL*60*60*1000 or, alternatively (unsigned long) 24*60*60*1000.
Accuracy
The accuracy of the timing will be dependent on the type of oscillator on your particular Arduino board. Many Arduinos or their clones use a Ceramic Oscillator that generally have an accuracy of about 0.1 to 0.5%, meaning a possible deviation of 43 seconds per day and as such maybe too inaccurate for your purposes. If your Arduino has a Crystal oscillator, it will be much more accurate (to something like 150ppm, meaning a maximum deviation of about 1 second per day under normal conditions).