Ard Tone Blocking
DodaTech
1 min read
In this tutorial, you'll learn about Arduino tone() Blocks Program Execution. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.
The Problem
The program freezes while tone() is playing.
Quick Fix
Wrong
tone(9, 440, 1000);
delay(1000); // Wastes CPU time
No other code can run during the 1-second delay.
Right
unsigned long toneEnd = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
if (millis() >= toneEnd) {
noTone(9);
} else {
tone(9, 440);
}
Serial.println("Running..."); // Continuous
delay(100);
}
void startTone() {
tone(9, 440);
toneEnd = millis() + 500;
}
"Running..." prints continuously while tone plays in background.
Prevention
tone() with duration parameter runs in the background (hardware timer). Do not use delay() while a tone is playing — the tone continues in hardware, but your program pauses. Use millis() timing to check when the tone should stop.
DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro