Built-in project · Arduino Uno R3

Passive buzzer on pin 8, on an Arduino Uno

A passive buzzer on pin 8 plays the eight notes of a C major scale with tone(), one every half second, and names each note as it plays. The whole build, an Arduino Uno and 1 more part, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Beginner Runs in your browser. Free, and no account needed.

Passive buzzer on pin 8 · Arduino Uno R3live0.000 s 0.00x
Click to open it in the editor
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · Arduino Uno R3
// Passive buzzer on pin 8: a C major scale, one note at a time.
//
//   pin 8   the buzzer's + leg
//   GND     the buzzer's other leg
//
// A passive buzzer has no oscillator inside, so a steady HIGH only clicks it
// once. tone(pin, frequency) makes the pin swing up and down that many times
// a second, and the buzzer turns the swinging into a note: 262 Hz is middle C,
// and each octave up doubles it.
//
// The scale climbs C D E F G A B C, then waits a second and starts again.
// Change the numbers in NOTES to play something else.

const int BUZZER = 8;
const int NOTES[] = {262, 294, 330, 349, 392, 440, 494, 523};
const char *NAMES[] = {"C5", "D5", "E5", "F5", "G5", "A5", "B5", "C6"};
const int COUNT = 8;
const int NOTE_MS = 500;

void setup() {
  Serial.begin(9600);
  Serial.println("Mokxi Uno: passive buzzer on pin 8");
}

void loop() {
  for (int i = 0; i < COUNT; i++) {
    Serial.print(NAMES[i]);
    Serial.print(" ");
    Serial.print(NOTES[i]);
    Serial.println(" Hz");
    tone(BUZZER, NOTES[i], NOTE_MS);
    delay(NOTE_MS + 50);
  }
  delay(1000);
}

Parts list

3 parts, plus the jumper wires. Every one is in the editor's parts bin.

How it is wired

2 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.

  • Ground: Arduino Uno R3 pin GND; Piezo speaker pin 2
  • Arduino Uno R3 pin 8; Piezo speaker pin 1

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.