Bird
0
0
Arduinoprogramming~5 mins

noTone() to stop sound in Arduino

Choose your learning style9 modes available
Introduction

The noTone() function stops any sound that is playing on a pin. It helps you turn off a buzzer or speaker when you want silence.

When you want to stop a buzzer after a beep.
When you want to end a sound effect in a game.
When you want to stop a warning sound after a button press.
When you want to silence a speaker before playing a new sound.
Syntax
Arduino
noTone(pin);

pin is the number of the pin connected to the buzzer or speaker.

This function stops the sound immediately on that pin.

Examples
Stops any sound playing on pin 8.
Arduino
noTone(8);
Stops sound on pin 3, useful if you used tone(3, frequency) before.
Arduino
noTone(3);
Sample Program

This program plays a 1000 Hz sound on pin 9 for 1 second, then stops the sound using noTone().

Arduino
#define buzzerPin 9

void setup() {
  pinMode(buzzerPin, OUTPUT);
  tone(buzzerPin, 1000); // Play 1000 Hz tone
  delay(1000);           // Wait 1 second
  noTone(buzzerPin);     // Stop the tone
}

void loop() {
  // Nothing here
}
OutputSuccess
Important Notes

You must use the same pin number in noTone() that you used in tone().

If you don't call noTone(), the sound will keep playing forever.

noTone() only works on pins that support tone().

Summary

noTone() stops sound on a buzzer or speaker pin.

Use it to end sounds cleanly after playing tones.

Always match the pin number with the one used in tone().