// Define the notes
#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

// Define the duration of each note
#define QUARTER_NOTE 1000 // in milliseconds

void setup() {
  // Initialize the buzzer pin as an output
  pinMode(8, OUTPUT);
}

void loop() {
  // Play the melody
  playNote(NOTE_E4, QUARTER_NOTE);
  playNote(NOTE_D4, QUARTER_NOTE);
  playNote(NOTE_C4, QUARTER_NOTE);
  playNote(NOTE_D4, QUARTER_NOTE);
  playNote(NOTE_E4, QUARTER_NOTE);
  playNote(NOTE_E4, QUARTER_NOTE);
  playNote(NOTE_E4, QUARTER_NOTE);
  playNote(NOTE_D4, QUARTER_NOTE);
  playNote(NOTE_D4, QUARTER_NOTE);
  playNote(NOTE_D4, QUARTER_NOTE);
  playNote(NOTE_E4, QUARTER_NOTE);
  playNote(NOTE_E4, QUARTER_NOTE);
  playNote(NOTE_E4, QUARTER_NOTE);
  playNote(NOTE_E4, QUARTER_NOTE);
  playNote(NOTE_D4, QUARTER_NOTE);
  playNote(NOTE_C4, QUARTER_NOTE);
  playNote(NOTE_D4, QUARTER_NOTE);
  playNote(NOTE_E4, QUARTER_NOTE);
  playNote(NOTE_E4, QUARTER_NOTE);
  playNote(NOTE_E4, QUARTER_NOTE);
  playNote(NOTE_D4, QUARTER_NOTE);
  playNote(NOTE_D4, QUARTER_NOTE);
  playNote(NOTE_E4, QUARTER_NOTE);
  playNote(NOTE_D4, QUARTER_NOTE);
  playNote(NOTE_C4, QUARTER_NOTE);
  playNote(NOTE_C4, QUARTER_NOTE);
}

// Function to play a note
void playNote(int noteFrequency, int noteDuration) {
  // Play the note on the buzzer
  tone(8, noteFrequency, noteDuration);
  // Delay for the specified duration
  delay(noteDuration);
  // Stop playing the note
  noTone(8);
  // Delay for a short time between notes
  delay(50);
}