int buzzerPin = 7;
// Define a melody using frequencies (Hz) and durations (ms)
int melody[] = {262, 294, 330, 349, 392, 440, 494, 523}; // Notes (C4 to C5)
int noteDurations[] = {500, 500, 500, 500, 500, 500, 500, 1000}; // Durations
void setup() {
pinMode(buzzerPin, OUTPUT);
}
void loop() {
for (int i = 0; i < 8; i++) {
tone(buzzerPin, melody[i], noteDurations[i]); // Play the note
delay(noteDurations[i] + 100); // Wait a bit longer between notes
}
delay(2000); // Pause before repeating the melody
}