Arduino Buzzer Melody: Play Notes with tone()
A buzzer turns numbers into sound. Each number is a frequency in hertz. Play the musical scale.
Parts you need
- Arduino Uno
- Piezo buzzer
Wiring
- Pin 8 → buzzer + leg
- Buzzer − leg → GND rail
Arduino code
int buzzer = 8;
// Do Re Mi Fa So La Ti Do
int notes[] = {262, 294, 330, 349, 392, 440, 494, 523};
void setup() {
for (int i = 0; i < 8; i++) {
tone(buzzer, notes[i], 300);
delay(350);
}
}
void loop() {
}
Goal and tip
Goal: Play at least five different musical notes.
Tip: Try this: play the notes backwards by counting down from 7 to 0.