Arduino Example

Arduino Tone Melody Example

Play a simple melody with tone().

Wiring

Check pinout, power supply, common GND and voltage levels before connecting the module.

Full code

const int buzzerPin = 8;
int notes[] = {262, 294, 330, 349, 392, 440, 494, 523};

void setup() {}

void loop() {
  for (int i = 0; i < 8; i++) {
    tone(buzzerPin, notes[i], 200);
    delay(250);
  }
  noTone(buzzerPin);
  delay(1000);
}

How it works

This lesson matches the page title and gives a clean starting point for this exact example.

Common mistakes

Check board selection, wiring, libraries, power supply and serial monitor baud rate.

Frequently asked questions

Can I copy this code?

Yes. Adapt pins, credentials and libraries for your board.

Why does it not compile?

Install required libraries and select the correct board.