Skip to Content
Circuitera

Measure short Arduino intervals across micros() rollover

Work through unsigned elapsed-time subtraction for a wraparound and understand the classic Uno R3 micros() resolution.

Subtract timestamps in the counter type

micros() returns an unsigned long. On the classic Uno R3 it advances in steps of 4 µs and the 32-bit counter rolls over after about 71.6 minutes. Subtract the previous timestamp from the new one while both remain unsigned. For a single short interval across rollover the result is the elapsed time.

Avoid comparing absolute deadlines

A test like now >= start + interval can fire early when the addition wraps. Use now - start >= interval instead. If you sleep or fail to poll for an entire counter cycle, modulo arithmetic cannot recover the missing cycle. Print results outside interrupt handlers and avoid claiming sub-step precision.

Open the exact Uno example

The controlled wraparound prints 12. These constants illustrate arithmetic without waiting for the physical clock to wrap.

void setup() {
  Serial.begin(9600);
  const unsigned long before = 0xFFFFFFF8UL;
  const unsigned long after = 0x00000004UL;
  Serial.println(after - before);
}
void loop() {}

Verified with [email protected] on Uno R3 (2026-12-05 UTC). This check did not use physical hardware.

Continue learning

Sources