# delay function for few hours

Hello
Is the delay function accurate to provide a long periode time such as 2 hours, 10 hours 24 hours ?
Can I have a delay time as 2h30min30sec with a 9030000 value as delay function ?
I have to use the mini arduino, but I hesitate about the crystal frequency (8MHz or 16Mhz)

arduino timer back to zero after 50 days.

Yes you can have a delay up to 50 days. When putting a number over 32,000 into a delay call put a UL at the end of the number to give you an unsigned long type of constant.

ok, and what about the precision after few hours or few days ? can I have a precision of few seconds or fex milliseconds after 10 days ?

The precision is controlled by the accuracy of the crystal, it is about +/- 30 ppm, parts per million.

a drift at about 30ms every one million second ?

he_amine: a drift at about 30ms every one million second ?

That would be 30ppt (milli is a thousandth NOT a millionth) So it's within 30ms every THOUSAND seconds.

ie A bit better than 30ms per 1/4 of an hour.

Is the delay function accurate to provide a long periode time such as 2 hours, 10 hours 24 hours ? Can I have a delay time as 2h30min30sec with a 9030000 value as delay function ?

Doing it the hard way. Note the time with millis() that your event starts. Calculate the time you want the event to end, for example 2 hours: 2 hrs * 60 min/hr * 60 sec/min * 1000mS/sec = 7,200,000mS, add that to the current time. That's your stop time. Every pass thru loop, capture millis() again and compare it to the stop time. When it exceeds it, you're done. That's blink without delay in a nutshell.

he_amine: can I have a precision of few seconds or fex milliseconds after 10 days ?

I'm curious to know in what application that's likely to matter.

30 ppm is about 2.6 seconds a day. 78 seconds a month. (86,400 seconds per day = 0.0864 millions of seconds per day * 30 = 2.592)

For more accurate times over long intervals use a Real-Time Clock (RTC) add-on. They have a more accurate crystal.

You could probably also replace the resonator on an Arduino with a higher precision 16 MHz crystal.

he_amine: Is the delay function accurate to provide a long periode time such as 2 hours, 10 hours 24 hours ?

Will you ever want to change your mind during the 2 hours, 10 hours etc.

If you use the delay() function the only way to do so will be to reset the Arduino.

If you want the Arduino to be responsive during the waiting period use millis() to manage the timing as illustrated in several things at a time.

The same general approach can also be used with an RTC.

...R