Part

Piezo speaker

Makes whatever tone you drive it with, and shows it.

See every part
  • 2 pins
  • In 51 projects
  • In 21 lessons
Drawn live by the editor's own code, at the size you see it.
At a glance

The Piezo speaker in brief

What it is, and where it sits on the bench.

A passive piezo element is a ceramic disc on a brass plate with two legs and no oscillator inside; that is what separates it from the near-identical active buzzer. A steady voltage does nothing; it sings whatever square wave it is given, so one leg goes to a digital pin and the other to ground, and tone() on an Uno or ESP32 picks the note, 440 Hz for an A. Mokxi’s part is a frequency counter on the voltage across its legs, counting a rise at 1.0 volt and a release at 0.4 volts so a slow or noisy edge cannot count twice, and it reports the note in hertz. Anything faster than 40 kHz is treated as noise, and 60 milliseconds without an edge reads as silence, so a very short blip never gets a frequency. The common mistake is wiring it like a buzzer, giving it plain DC and wondering why it is quiet. The disc’s roughly 10 nF of capacitance, its resonance near 4 kHz and its loudness are not modeled. You hear the note it plays through your computer’s speakers, as a soft square wave at that frequency.

Family
Outputs
Pins
2
Pins

2 pins

Named as the editor names them, so a wire lands where you expect it.

Pin
What it does
1
One leg.
2
The other leg.
How to use it

How to use a passive piezo with an Arduino

One leg goes to a digital pin and the other to GND, with no resistor. Then tone(pin, frequency) starts a square wave on the pin and returns at once, and noTone(pin) stops it, so the sketch decides how long each note lasts with its own delay(). Without tone(), a passive piezo on a pin held HIGH stays silent.

The circuit here plays the opening of Ode to Joy on pin 8, lights an LED on pin 13 for every note, and prints each pitch on the serial monitor. The 30 ms gap after every noTone() is what makes two notes of the same pitch sound like two notes rather than one long one, and the piezo’s readout shows the frequency it hears.

Part pin
Board pin
Leg 1
Pin 8
Leg 2
GND

tone() compiles for the ESP32 here too, and a 3.3 V square wave crosses the piezo’s 1 V threshold with room to spare.

Arduino Uno: piezo melodylive0.000 s 0.00x
Click to open it in the editor
This is the simulator itself, running here. Click anything to open it in the editor.
A tune with tone() and noTone()
const int PIEZO = 8;
const unsigned int NOTES[] = {330, 330, 349, 392, 392, 349, 330, 294};
void setup() {}
void loop() {
  for (int i = 0; i < 8; i++) {
    tone(PIEZO, NOTES[i]);
    delay(370);
    noTone(PIEZO);
    delay(30);   // the gap between notes
  }
  delay(2000);
}
How it is modeled

What is true about the Piezo speaker, here

In its help article’s own words: what the simulation gets right, and where it stops.

Modeled

The part watches the voltage across its two legs and times the transitions, with hysteresis so a slow edge or a noisy net cannot count twice; the gap between one rise and the next is the note's period, and the probe reports its frequency in hertz. Driven differentially, as an H-bridge would, it reads the same way, because what it is watching is the difference between the legs. Silence for long enough reads back as 0 Hz.

Not modeled

No capacitance (a real element is roughly 10 nF and loads the pin driving it; this one is high impedance on both legs) and no loudness. The probe is a frequency, not a volume. You hear the note it plays through your computer's speakers, as a square wave at that frequency and a fixed soft level (the speaker button on the canvas toolbar mutes it).

It is a frequency counter rather than an acoustic model. The hysteresis is 1.0 V to go one way and 0.4 V to come back, which are round numbers rather than a real element's thresholds, and they are absolute volts: a 3.3 V board's square wave crosses them and a 200 mV signal never does, however loud a real disc would be. Anything faster than 40 kHz is rejected as noise rather than reported, and 60 ms with no edge reads as silence, so a note shorter than that never gets a frequency at all. There is no resonance (a real disc is loudest near 4 kHz and nearly silent an octave away), no mechanical ring-down, no harmonics and no waveform: a sine and a square at the same rate read identically.

From Piezo element (passive), in full.

Projects

See the Piezo speaker in a project

51 built-in projects use it. Each opens in the editor, already wired.

Boards

The boards it is shown on

Each of these 3 boards has a built-in project with the Piezo speaker in it.

Boards

The Piezo speaker on each board

The pins, the voltage and the code change from board to board. Each page has that board’s wiring and a circuit you can run.

Wire up the Piezo speaker

Open the editor and push it into the breadboard. It is free, and it runs on your own machine.