Skip to content

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.
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

### Does noTone() stop tone() immediately?

Yes. noTone() stops the PWM output on the pin immediately. The waveform generator is disabled.

Can I use tone() in an ISR?

No. tone() uses millis() internally and cannot be called from an ISR on AVR. Set a flag and call tone() from loop().

Does tone() interfere with PWM?

Yes. tone() uses Timer2, which controls PWM on pins 3 and 11. analogWrite() on those pins will stop working while tone() is active.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro