Arduino millis() Rollover Calculator
NOUVEAUArduino millis() rollover calculator: see when millis() and micros() overflow for your uptime and test the rollover-safe interval check step by step.
Fonctionne à 100 % dans votre navigateur — vos données ne sont jamais envoyées ni stockées sur nos serveurs.
Cet outil n'est pas encore entièrement traduit : une partie du texte est encore en anglais. L'outil lui-même fonctionne de la même façon dans toutes les langues.
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) { ... }
}Exemples rapides
Des entrées typiques et les résultats produits par cet outil.
Présentation
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.
Pourquoi utiliser cet outil ?
- 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
Fonctionnalités
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.
Mode d'emploi
Enter the uptime
Type how long the board has been running in days, hours, minutes and seconds.
Add a power-on time
Optionally set the date and time it started, or press Now.
Run the simulation
Set previousMillis, the interval and loop step to watch both checks across the wrap.
Copy the safe code
Paste the rollover-safe pattern into your sketch.