Introduction
Sound output helps your Arduino projects talk to you or alert you. It makes your devices more interactive and fun.
Sound output helps your Arduino projects talk to you or alert you. It makes your devices more interactive and fun.
tone(pin, frequency, duration); noTone(pin);
tone() plays a sound on a speaker connected to a pin.
noTone() stops the sound on that pin.
tone(8, 1000, 500);
noTone(8);This program plays a short beep on pin 8 when the Arduino starts. It shows how sound output can give feedback.
#define SPEAKER_PIN 8 void setup() { // Play a beep sound to show the program started tone(SPEAKER_PIN, 1000, 300); delay(500); // Wait for beep to finish } void loop() { // Nothing here }
You need a small speaker or buzzer connected to the Arduino pin and ground.
Sound output is simple but powerful for making your projects interactive.
Sound output lets your Arduino communicate with you using beeps or tunes.
It is useful for alerts, feedback, and fun sounds.
Use tone() and noTone() to control sound on a pin.
tone().playSound(), soundOn(), and beep() are not valid Arduino functions.tone(8, 1000, 500); delay(1000); noTone(8);
tone(8, 1000, 500); plays a 1000 Hz sound on pin 8 for 500 milliseconds.delay(1000); waits 1 second, then noTone(8); stops the sound on pin 8.tone(9, 500); noTone();
noTone() requires the pin number to stop the sound on that pin.tone(9, 500); is valid; duration is optional and plays indefinitely until stopped.Pass the test and this pattern moves unknown