Skip to content

Arduino delay() Blocks All Other Operations

DodaTech Updated 2026-06-26 1 min read

In this tutorial, you'll learn about Arduino delay() Blocks All Other Operations. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

The Problem

delay() stops the entire program, preventing sensor reads, serial communication, and LED updates.

Quick Fix

Wrong

void loop() {
  digitalWrite(13, HIGH);
  delay(1000);  // Blocks everything for 1 second
  digitalWrite(13, LOW);
  delay(1000);
}
No serial, no sensors, no button reads during the 2-second loop.
unsigned long prev = 0;
const int interval = 1000;
bool ledState = false;

void loop() {
  unsigned long now = millis();
  if (now - prev >= interval) {
    prev = now;
    ledState = !ledState;
    digitalWrite(13, ledState);
  }
  // Other tasks run continuously
  checkSerial();
  readSensors();
}
LED blinks while serial and sensors run continuously.

Prevention

Replace delay() with millis() timing for all non-blocking applications. Use delay() only for short pauses (<10 ms) or in setup(). For delays in library code, document that it blocks. BlinkWithoutDelay is the canonical example pattern.

DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.

FAQ

### When is delay() acceptable?

In setup() for hardware initialization. For very short delays (<10 ms) where accuracy matters. In blocking test sketches.

Does delay() affect PWM output?

No. PWM runs in hardware and continues during delay(). But software PWM (bit-banging) will pause.

Can I stop a delay() early?

No. Once delay() starts, it cannot be interrupted. Use millis() timing to allow early exit on a condition.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro