// Melody: tone() plays a frequency in Hz on the buzzer on pin 8.
const int BUZZER = 8;
int notes[] = {262, 294, 330, 349, 392, 440, 494, 523};
void setup() {
}
void loop() {
for (int i = 0; i < 8; i++) {
tone(BUZZER, notes[i], 200);
delay(250);
}
noTone(BUZZER);
delay(1000);
}
Description
Play a short tune on a piezo buzzer. It compiles and runs on a virtual Uno in the browser. Turn the sound on, then change the notes in the list.
Cite this design
@design{breadboardhub/arduino-buzzer-melody,
title = {Arduino Uno: buzzer melody},
author = {breadboardhub},
url = {https://www.breadboardhub.com/breadboardhub/arduino-buzzer-melody},
version = {1.0.0}
}