#define BUZZER_PIN 8
// Nada dari lagu "Happy Birthday"
int melody[] = {
262, 262, 294, 262, 349, 330, // Happy Birthday to You
262, 262, 294, 262, 392, 349, // Happy Birthday to You
262, 262, 523, 440, 349, 330, 294, // Happy Birthday Dear [Name]
466, 466, 440, 349, 392, 349 // Happy Birthday to You
};
// Durasi dari setiap nada (dalam ms)
int noteDurations[] = {
500, 500, 1000, 1000, 1000, 2000,
500, 500, 1000, 1000, 1000, 2000,
500, 500, 1000, 1000, 1000, 1000, 2000,
500, 500, 1000, 1000, 1000, 2000
};
void setup() {
pinMode(BUZZER_PIN, OUTPUT);
}
void loop() {
for (int thisNote = 0; thisNote < sizeof(melody)/sizeof(melody[0]); thisNote++) {
int noteDuration = noteDurations[thisNote];
tone(BUZZER_PIN, melody[thisNote], noteDuration);
delay(noteDuration * 1.30);
noTone(BUZZER_PIN);
}
delay(10000);
}