From the arduino reference page for delay the parameter for delay is an unsigned long

Unsigned longs on the arduino can reach from 0 to 4,294,967,295.

It is likely that the number being passed to 'delay' is being interpreted as an int. This would mean the delay is limited to a max of 32,767.

You should explicitly declare your delay value as an unsigned long like the solution in this post.

unsigned long seconds = 1000L; //Notice the L 
unsigned long minutes = seconds * 60;

delay(minutes); //for 60,000 milliseconds
Answer from Wil on Stack Overflow
Top answer
1 of 4
8

From the arduino reference page for delay the parameter for delay is an unsigned long

Unsigned longs on the arduino can reach from 0 to 4,294,967,295.

It is likely that the number being passed to 'delay' is being interpreted as an int. This would mean the delay is limited to a max of 32,767.

You should explicitly declare your delay value as an unsigned long like the solution in this post.

unsigned long seconds = 1000L; //Notice the L 
unsigned long minutes = seconds * 60;

delay(minutes); //for 60,000 milliseconds
2 of 4
3

Yeesh... someone cited this thread elsewhere, here is the correct explanation:

delay() takes an unsigned long (32-bit number between 0 and 2^32-1, or about 4.2 billion). And delay(60000) works fine. There are two ways that one could get into trouble trying to pass numbers larger than those used in blink, but smaller than 4.2 billion to delay()

First, if you generate the number on the spot by multiplying numbers together, for example delay(60*1000);

Both of these numbers will default to int (16-bit signed integer from -32768 to 32767), so that multiplication will overflow that… leaving you with -5536 if my math serves me… Then, that gets converted to an unsigned long, leaving you with 2^32-5536, or, well, approximately 4.2 billion.

Solution is simple - explicitly tell the compiler that you intend for that literal to be an unsigned long, by putting UL after one of the numbers (the other will be automatically promoted to unsigned long to match):

delay(60UL*1000);

The other way an arduino user could get in trouble here (really, the same way, only through a different route) would be if they assigned the delay to a data type that couldn’t fit it, for example:

int time=60000; //this ends up as -5536 too...

delay(time); //same result!

Solution is also quite simple - just declare time as an unsigned long, instead of int.

Note that the first case (but not the second), where the constant expression generates an overflow, would actually generate a compiler warning…. Except, arduino turns off compiler warnings by default. You can turn them back on in File -> preferences. Sometimes it will warn about things that are fine, but when you see warnings, and it’s not doing what you want, the warnings are a good place to start looking.

Background on delayMicroseconds()

The issue with delayMicroseconds() having the maximum length of 16383 is unrelated - that limitation is because delayMicroseconds is, under the hood, implemented completely differently from delay(). delay() is based on micros() and the millis timer system (a hardware timer is configured prior to setup() being called, with the overflow interrupt incrementing a global count of milliseconds; millis() uses that count, and micros uses that plus the current count on the timer). delayMicroseconds, however, needs much higher accuracy than that method could achieve (micros takes something like 7-8us to return, and has resolution of 4us, since the timer in question runs off the 16MHz clock with /64 prescale); it's implemented by counting clock cycles. It takes an unsigned int (16-bit) instead of unsigned long, first off. It multiplies the requested delay by 4 (for 16MHz clock, at least), converting it into the number of iterations of a loop written in inline assembler that takes 4 clock cycles per iteration. So that's where the apparent 14-bit limit comes from: the number of 4-cycle loops has to fit in 16 bits, so the number of microseconds is 1/4th that (assuming 16 MHz system clock - so an 8 MHz pro mini, for example, you could specify twice as long of a delay to delayMicroseconds()!). On an (admittedly rare) 20 MHz one, the longest delay would be around 13000 ((2^16-1)/(20/4=5)) Long before that, though, you're better off just doing a while loop that checks micros()...

🌐
Arduino Forum
forum.arduino.cc › projects › programming
maximum delay in arduino an how to make it - Programming - Arduino Forum
May 20, 2013 - I want to make a 1 minute delay on my program? how do I make it? how the maximum delay on the Arduino? please help me
Discussions

Max Delay - Direct Answer requested
I happened to see someone ask about the maximum delay time possible in an Arduino sketch. Simple question. But I didn't see that anyone actually answered the question. There were about 19 "why do you want to do it that way"'s, and about 27 "you should use millis()"'s, and several "let's take ... More on forum.arduino.cc
🌐 forum.arduino.cc
19
1
August 7, 2015
delay doesn't accept variable for long times?
You are using a signed int. More on reddit.com
🌐 r/arduino
9
2
July 24, 2022
Time limit on delay()?
I am new to arduino and also pressed for time on a project. I am building an automatic plant watering thingy that uses a 12vdc valve, a motor controller and an attiny85. Basically I want the arduino to wait for 7 days (604,800,000 milliseconds) and then open the valve for a few seconds and ... More on forum.arduino.cc
🌐 forum.arduino.cc
0
0
July 23, 2012
maximum delay() is 32767ms ?
From playing with it, it looks like the argument to the delay() function is treated as a signed int, making the maximum delay something like 32767 milliseconds. Is that correct? If so, it would be helpful to update the reference page for delay() to make this clear. More on forum.arduino.cc
🌐 forum.arduino.cc
0
0
January 19, 2008
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Max Delay - Direct Answer requested - Programming - Arduino Forum
August 7, 2015 - I happened to see someone ask about the maximum delay time possible in an Arduino sketch. Simple question. But I didn't see that anyone actually answered the question. There were about 19 "why do you want to do it that way"'s, and about 27 "you should use millis()"'s, and several "let's take ...
🌐
Arduino
docs.arduino.cc › language-reference › en › functions › time › delay
delay() | Arduino Documentation
delay() for timing events longer than 10s of milliseconds, unless the Arduino sketch is straightforward.
🌐
Arduino
docs.arduino.cc › language-reference › en › functions › time › delayMicroseconds
delayMicroseconds() | Arduino Documentation
June 5, 2025 - The largest value that will produce an accurate delay is 16383; larger values can produce an extremely short delay.
🌐
Reddit
reddit.com › r/arduino › delay doesn't accept variable for long times?
r/arduino on Reddit: delay doesn't accept variable for long times?
July 24, 2022 -

I am having some trouble with my Leonardo. It seems to be getting stuck in things that should not be infinite loops. What's shown below is what I originally wrote, but my Void loop function does not loop. It only runs once. The intent is to refresh the page every approximately 2 minutes, then click on three buttons that are 25 units apart. (I also made the mouse move in the x direction just because after a refresh, the mouse icon was hidden so I wasn't sure whether to trust that it would click the right spot until I made it visible again).

#include <Keyboard.h>

#include <Mouse.h>

const char refreshKey = KEY_F5;

const int ySpacing = 25;

const int xSpacing = 500;

const int refreshDelay = 10000;

const int eventDelay = 50;

const int pauseDelay = 150;

const int interluDelay = 100000;

void setup() {

Keyboard.begin();

delay(refreshDelay / 5);

Mouse.begin();

delay(refreshDelay / 5);

}

void loop() {

// refresh page

Keyboard.press``(refreshKey);

delay(eventDelay);

Keyboard.releaseAll();

delay(refreshDelay);

// click first

Mouse.move(xSpacing, 0, 0);

delay(pauseDelay);

Mouse.press``();

delay(eventDelay);

Mouse.release();

delay(pauseDelay);

// click up one

Mouse.move(0 - xSpacing, 0 - ySpacing, 0);

delay(pauseDelay);

Mouse.press``();

delay(eventDelay);

Mouse.release();

delay(pauseDelay);

// click up two

Mouse.move(0, 0 - ySpacing, 0);

delay(pauseDelay);

Mouse.press``();

delay(eventDelay);

Mouse.release();

delay(pauseDelay);

// return mouse and wait

Mouse.move(0, 2 * ySpacing, 0);

delay(interluDelay);

}

Like I said, it runs once, it works perfectly, but then it stops for some reason. One thing I did to check to see if it was truly looping or not was to include a piezo buzzer that beeps for about a half-second at the beginning of Void loop. It still wasn't repeating, so I took out everything except the beep and the long, 100 second delay. That code looks like this:

void loop() {

for (int j = 0; j < 50; j++) {

digitalWrite(buzzerPin, HIGH);

delay(3);

digitalWrite(buzzerPin, LOW);

delay(3);

}

delay(interluDelay);

}

Anyway, I tried a lot of things from deleting all references to the libraries, shortening variable names, getting rid of all constants that were no longer being used due to commenting out 3/4 of my code. Finally, I just got rid of the variable interluDelay alltogether and wrote 100,000 in the delay function manually, and it worked. Arduino's max int value is 2 billion, and the maximum delay time is twice that. Why can I type the number in but can't use a variable (and why were all my other variable delays like the 10 second refreshDelay were working just fine?)

🌐
Arduino Forum
forum.arduino.cc › projects › general guidance
Time limit on delay()? - General Guidance - Arduino Forum
July 23, 2012 - I am building an automatic plant watering thingy that uses a 12vdc valve, a motor controller and an attiny85. Basically I want the arduino to wait for 7 days (604,800,000 milliseconds) and then open the valve for a few seconds and ...
Find elsewhere
🌐
Arduino Forum
forum.arduino.cc › forum 2005-2010 (read only) › software › bugs & suggestions
maximum delay() is 32767ms ? - Bugs & Suggestions - Arduino Forum
January 19, 2008 - From playing with it, it looks like the argument to the delay() function is treated as a signed int, making the maximum delay something like 32767 milliseconds. Is that correct? If so, it would be helpful to update the r…
🌐
Tech Explorations
techexplorations.com › home › tech explorations guides › /arduino/ › programming › 11. the problem with delay()
11. The problem with delay() - Tech Explorations
March 5, 2024 - It might also need to record sensor data to an Internet of Things service and turn on a relay. With the 1000ms delay that we have imposed with the delay() function, the Arduino is actually forced to do nothing (other than counting milliseconds) ...
🌐
Quora
quora.com › What-is-the-longest-time-delay-you-can-make-using-an-Arduino
What is the longest time delay you can make using an Arduino? - Quora
Answer (1 of 3): in practice, longer than the age of the earth, 4.5 Billion years. For really long delays, you probably want to check the date instead, and be aware that maintaining power for that long is going to require some serious work. Your computer will fail first.
🌐
Arduino Forum
forum.arduino.cc › projects › programming
maximum delay in arduino an how to make it - #14 by UKHeliBob - Programming - Arduino Forum
August 13, 2019 - I can't make any sense of what you want to do, but if you are trying to time something without affecting other functions then consider using the millis() function for timing. See Using millis() for timing. A beginners guide, Several things at the same time and look at the BlinkWithoutDelay example in the IDE.
🌐
DigiKey
digikey.com › en › maker › tutorials › 2022 › how-to-avoid-using-the-delay-function-in-arduino-sketches
How to Avoid Using the Delay() Function in Arduino Sketches
February 23, 2022 - The counter will typically exceed the maximum value with the same frequency because the board’s clock speed remains constant. However, note that this method is only viable if you don’t want to use your Arduino code on other boards, as those might use different clock speeds, which will lead to the interval getting shorter or longer depending on the clock frequency.
🌐
Delft Stack
delftstack.com › home › howto › arduino › arduino delay microseconds
How to Add Delay in Microseconds in Arduino | Delft Stack
March 4, 2025 - The maximum delay you can set with delayMicroseconds is 16383 microseconds. Can I use delayMicroseconds in the loop function? Yes, you can use delayMicroseconds in the loop function, but be aware that it will block other code from executing ...
🌐
Random Nerd Tutorials
randomnerdtutorials.com › home › arduino › theory and blog › why you shouldn’t always use the arduino delay function
Why You Shouldn’t Always Use the Arduino Delay Function | Random Nerd Tutorials
April 2, 2019 - Though I have to send one time ... the Arduino must send again the same signal for 50 msec to switch of ch 1 (relay 1) wait (100 msec) and switch on ch 2 (50 msec) with an other data code....
🌐
Reddit
reddit.com › r/arduino › repeating delaymicroseconds(max_value) to get a longer delay?
r/arduino on Reddit: Repeating delayMicroseconds(max_value) to get a longer delay?
March 7, 2017 -

Hello!

Noob to Arduino and C here.

I'm working with a stepper motor to control the Right Ascension axis on my telescope.

I've found that between two steps, I need a delay of 25.882 milliseconds. Now, delay() only takes integers, but I need a higher resolution. Looking at delayMicroseconds(), it states that for this delay, a maximum of 16383 microseconds is possible for accurate timing. Obviously, I need 25882 microseconds, which is above that limit.

What I'm wondering, is: Can I do two consecutive delayMicroseconds() with half my target delay? This means that I'll do

delayMicroseconds(target_half) // target_half = 12941 < 16383
delayMicroseconds(target_half)

Here's a code exerpt:

float millisbetweenSteps = 25.882; // milliseconds - calculated - lower is faster
int microsbetweenSteps = millisbetweenSteps * 1000; // microseconds

...

void runStepper(boolean run) {
  if (run == true) {
    digitalWrite(enablePin, HIGH);
    digitalWrite(directionPin, LOW);

    digitalWrite(stepPin, HIGH);
    delayMicroseconds(pulseWidthMicros); // needed?
    digitalWrite(stepPin, LOW);

    delayMicroseconds(microsbetweenSteps/2); //Because delayMicroseconds max value is 16383micros
    digitalWrite(ledPin, !digitalRead(ledPin));
    delayMicroseconds(microsbetweenSteps/2); 
  }
}  


void loop() {
  runStepper(true);  
}

Looking at the stepper, it looks as if I'm getting the desired result, but I'm not sure.

Cheers!

🌐
Arduino Forum
forum.arduino.cc › projects › programming
Need 40 ns delay max with Arduino IDE - Page 2 - Programming - Arduino Forum
July 28, 2024 - This is correct. There's nothing about these SSD130x devices that requires a strict 40ns timing in any way. They don't have any particular signal conditioning requirements that result in a need to jump through hoops.
🌐
Arduino Forum
forum.arduino.cc › forum 2005-2010 (read only) › hardware › troubleshooting
Is there a maximum delay with arduino? - Troubleshooting - Arduino Forum
August 31, 2007 - hopefully i'm just missing something! I need a delay of ten minutes which I programmed 600,000 milliseconds, but it seems to time out at a maximum of 10 seconds. Should this be happening? How do I use longer time delays…
🌐
Arduino Forum
forum.arduino.cc › projects › programming
limits on delay() ? - Programming - Arduino Forum
January 28, 2012 - I'll be doing it twice a day. So basically I'm turning on a pin for about 2.5 minutes, then I want it off for 12 hours, on 2.5 min, off 12 hours... the 12 hour delay looks massive: delay(43200000) ...