I am designing a driver for a Bipolar stepper motor using Arduino Mega 2560 and DRV8825 Stepper driver.

In my application, a stepper motor (Nema 24) will run for 5 minutes and stop for 2 minutes. I have doubts about is what is the maximum time an Arduino Mega can delay the process, or how much a maximum time delay() function will last, or work in programming?


1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.