Note: there's an existing question here this should be closed as a duplicate of, but that is proving hard to find. So until someone does find it...
The arduino delay()
function creates a blocking delay of the provided number of milliseconds. The argument is an unsigned long
which on a 16-bit Arduino is a 32-bit unsigned integer type, having a maximum value of 4,294,967,295. Since these are milliseconds, the maximum delay()
would be 4,294,967.295 seconds, or about 49 days.
However, you can easily achieve longer delays by using counting variables to count up instances of shorter delays. At an extreme, by using up available memory for keeping track of such counting, you can readily achieve theoretical delays exceeding the age of the universe.
Note that the Arduino delay()
function is blocking, which is to say that nothing else (except interrupts and on-chip hardware peripherals) runs during it. This is often undesirable. A more useful solution might be to make a loop taking say 20 milliseconds to run, as the result of a delay()
and a few housekeeping operations, and then run this over and over again while counting. Or you could make a 1 second loop, or whatever you choose.