EMBEDDED TOOL
Arduino millis()/micros() Rollover Calculator
See exactly when millis() or micros() overflow, and check interval math.
Rolls over (overflows) after
—
Target value (current + interval, wrapped to 32-bit unsigned)
—
Does this interval cross a rollover?
—
About this tool
Both millis() and micros() return an unsigned long that overflows back to 0 after it fills up — this tool shows exactly when that happens, and lets you check whether a specific "current value + interval" calculation crosses that rollover point.
The good news: the standard non-blocking timing pattern — if (currentMillis - previousMillis >= interval) — keeps working correctly across a rollover, because unsigned integer subtraction wraps around too, giving the right answer automatically. You almost never need to handle rollover specially if you use subtraction (not > comparisons) against a target value.
Frequently asked questions
- Do I need to write special rollover-handling code?
- Usually not — as long as you compute elapsed time as
currentMillis - previousMillis(both unsigned) and compare that difference to your interval, unsigned wraparound arithmetic makes the subtraction correct even whenmillis()has rolled over in between. - Why does micros() roll over so much sooner than millis()?
- Both are 32-bit counters with the same maximum value (about 4.29 billion), but micros() counts 1,000× faster (microseconds vs milliseconds), so it fills up 1,000× sooner — about 71.6 minutes instead of about 49.7 days.
- Is this different on ESP32 or other non-AVR boards?
- The core Arduino API still returns a 32-bit
unsigned longfrommillis()/micros()on essentially all boards for API compatibility, so the same 32-bit rollover math shown here applies even on 32-bit or 64-bit-capable chips like ESP32.