This part has a page of its own, with a note on using it and a circuit to try: the part page.
Where the active buzzer makes its one note off plain DC, a
passive piezo does nothing at all with a steady voltage. It needs a square wave, the
way tone() produces one, and a 440 Hz drive gives an A.
Pins
| Pin | What it does |
|---|---|
1 |
One leg. |
2 |
The other leg. |
Properties
None.
What the model gets right
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.
What it does not model
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.
Common mistakes
Wiring it expecting a buzzer's plain-DC behavior. A passive piezo stays silent on
a steady voltage no matter how it is polarized; it needs a driven square wave from
tone() or an oscillator.
See it in action
Metronome, Reaction timer and Morse sender all drive a passive piezo with
tone(). Open them at /templates.
The tutorial Arduino tone melody walks through Piezo melody: notes as frequencies, lengths as beats, and the gap between notes.
The piezo part page draws it live, with its pins and every project that uses one.