⚡
usefultools.dev
⏱️

Arduino millis() Rollover Calculator

NOVO

Arduino millis() rollover calculator: see when millis() and micros() overflow for your uptime and test the rollover-safe interval check step by step.

Funciona 100% no seu navegador — o que você insere nunca é enviado nem armazenado nos nossos servidores.

Esta ferramenta ainda não está totalmente traduzida, por isso parte do texto continua em inglês. A ferramenta funciona da mesma forma em todos os idiomas.

millis() wraps every
49 d 17 h 2 min 47.296 s
micros() wraps every
1 h 11 min 34.967 s
Max value (unsigned long)
4294967295
1 · When will my board roll over?
millis()
Value now: 3888000000
Rollovers so far: 0
Next rollover in: 4 d 17 h 2 min 47.296 s
micros()
Value now: 1054597119
Rollovers so far: 905
Next rollover in: 54 min 0.37 s
2 · Simulate an interval check across the rollover
now = millis()now − prevsafeprev + intervalbroken
42949667960wait500fire ✗
4294967046250wait500fire ✗
0 ↺500wait500wait
250750wait500wait
5001000fire500fire
7501250fire500fire
10001500fire500fire
12501750fire500fire

↺ marks where millis() wrapped to 0. ✗ marks a wrong decision: the broken check fires before the interval has passed (or, if loop() misses the short window before the wrap, waits another 49.7 days). The safe check now - previous >= interval is correct on every row because unsigned subtraction is modulo 2³².

Rollover-safe Arduino code

const unsigned long INTERVAL = 1000UL;   // ms
unsigned long previousMillis = 0;          // must be unsigned long

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  unsigned long now = millis();

  // SAFE: unsigned subtraction wraps correctly across the 49.7-day rollover
  if (now - previousMillis >= INTERVAL) {
    previousMillis += INTERVAL;              // or = now; (+= keeps a fixed cadence)
    digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
  }

  // BROKEN: previousMillis + INTERVAL overflows near the rollover
  // if (now >= previousMillis + INTERVAL) { ... }
}
⚡

Exemplos rápidos

Entradas típicas e os resultados que esta ferramenta gera.

2³² ms
millis() period
49 d 17 h 2 min 47.296 s
2³² µs
micros() period
1 h 11 min 34.967 s
Uptime
Uptime 45 days: next wrap in
4 d 17 h 2 min 47.296 s
Overflow
4294966796 + 1000 (unsigned)
500 — broken check fires early
📖

Visão geral

millis() and micros() return an unsigned long, a 32-bit counter on every Arduino board. After 4,294,967,295 it wraps back to zero: millis() rolls over after about 49.7 days of uptime and micros() after about 71.6 minutes. Code that runs for weeks — data loggers, home automation, greenhouse controllers — must keep working through that moment.

This Arduino millis() rollover calculator tells you the current counter values, how many times each has already wrapped and how long until the next rollover for a given uptime, with optional calendar dates from a power-on time. A step-by-step simulation then runs the safe pattern now - previous >= interval next to the broken now >= previous + interval through a real wrap, highlighting every wrong decision. Copy the rollover-safe blink-without-delay sketch when you are done. Everything is calculated in your browser.

Por que usar esta ferramenta?

  • Exact rollover periods for millis() and micros()
  • Countdown and dates for your board’s next wrap
  • See why the subtraction pattern is safe
  • Spot the overflow bug before it ships
  • Free, private and instant
⭐

Recursos

⏳

Uptime countdown

Current millis()/micros() values, rollovers so far and time to the next wrap.

📅

Rollover dates

Enter when the board powered on to get the date of the next three millis() rollovers.

🧪

Rollover simulation

Evaluates the safe and broken interval checks in unsigned 32-bit math, row by row.

❌

Bug highlighting

Marks each row where the broken check fires too early or would wait for the next wrap.

🧩

Safe code snippet

Copy a blink-without-delay sketch that keeps working past 49.7 days.

🛠️

Como usar

1

Enter the uptime

Type how long the board has been running in days, hours, minutes and seconds.

2

Add a power-on time

Optionally set the date and time it started, or press Now.

3

Run the simulation

Set previousMillis, the interval and loop step to watch both checks across the wrap.

4

Copy the safe code

Paste the rollover-safe pattern into your sketch.

🤔

Perguntas frequentes