Arduino tone() Keeps Playing After Expected Stop
DodaTech
Updated 2026-06-26
1 min read
In this tutorial, you'll learn about Arduino tone() Keeps Playing After Expected Stop. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.
The Problem
tone() continues playing even after the expected duration or noTone() call.
Quick Fix
Wrong
tone(9, 440); // No stop mechanism
Buzzer plays indefinitely.
Right
unsigned long toneStart = 0;
void playTone(int pin, int freq, unsigned long dur) {
tone(pin, freq);
toneStart = millis();
while (millis() - toneStart < dur) {
// Let tone play
}
noTone(pin);
}
void setup() {
playTone(9, 880, 300);
}
Buzzer plays 880 Hz for 300 ms then stops.
Prevention
Always pair tone() with either a duration parameter or a noTone() call. The duration parameter is the simplest approach. Use millis() timing instead of delay() for non-blocking tone control. noTone() immediately stops the waveform.
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