// Define the buzzer pin
int buzzer = 3;
// Define the notes as frequency in Hertz
#define NOTE_C4 262
#define NOTE_D4 294
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_G4 392
#define NOTE_A4 440
#define NOTE_B4 494
#define NOTE_C5 523
// Duration of the notes (milliseconds)
int duration = 500;
void setup() {
// Nothing to setup
}
void loop() {
// Play a simple melody: C4, D4, E4, F4, G4, A4, B4, C5
tone(buzzer, NOTE_C4, duration);
delay(duration * 1.3); // Wait for the note to finish with a little break
tone(buzzer, NOTE_D4, duration);
delay(duration * 1.3);
tone(buzzer, NOTE_E4, duration);
delay(duration * 1.3);
tone(buzzer, NOTE_F4, duration);
delay(duration * 1.3);
tone(buzzer, NOTE_G4, duration);
delay(duration * 1.3);
tone(buzzer, NOTE_A4, duration);
delay(duration * 1.3);
tone(buzzer, NOTE_B4, duration);
delay(duration * 1.3);
tone(buzzer, NOTE_C5, duration);
delay(duration * 1.3);
// Add a longer delay at the end of the melody
delay(2000);
}