# Is delay() good for making hour delay?

Hello! I'm wondering if `delay(1000*60*60*8 )` (8 hours) will fulfill its function. I want simple code that will give on one pin high state for example in 8 hours a day (delay(18hours); digitalWrite(); delay(8hours); digitalWrite(); in loop). Will it do what I want? I'm using Attiny85 1MHz with Arduino bootloader. What's possible tolerance of delay function?

Regards, Albert

delay takes an unsigned long in milliseconds. It's good for about 49 days of delay if you want to go that long.

But your code is dead in a delay, you can't read switches or react to anything else. So make sure you really have NOTHING else to do while you're in the delay. If you might have other things to do then look at the Blink Without Delay example to see how to keep the program running and figure out when it's time to do something.

If you work the math out like that instead of using just one number, then be sure you put a UL on the end of one of the numbers so the math doesn't get done with ints and overflow.

``````delay(1000UL * 60 * 60 *8);
``````

I'm wondering if delay(10006060*8 ) (8 hours) will fulfill its function.

No. 1000 is an int. 60 is an int. 8 is an int. So, integer math will be used, with intermediate values stored in int registers. That will result in overflow.

``````delay(1000UL * 60 * 60 * 8); // will uselessly stop the Arduino from doing anything else for 8 hours.
``````

If you flash a LED while in timing mode it would give you an indication if the controller is working.
To do this you cannot use delay().
Instead use millis() and the Blink Without Delay technique. (example is in the IDE samples).

Is the Tiny85 running on the internal clock or an external crystal?

The difference is accuracy of the clock, the internal clock needs to be calibrated and is affected by temperature.