Skip to content
R

Buzzer / Piezo

Controlling Passive Buzzer Buzzer / Piezo with Raspberry Pi

What is the Passive Buzzer?

Passive Buzzer practical reference

A piezo buzzer that requires a driven PWM signal, allowing variable-pitch tones and simple melody playback rather than a fixed beep.

Key specifications

  • Operating voltage: 3V - 5V DC
  • Control: Requires a driven square wave (PWM or the Arduino tone() function) — pitch equals drive frequency
  • Usable frequency range: ~2kHz - 5kHz for clearly audible tones (piezo response falls off outside this band)
  • Silent when idle: No internal oscillator — a constant HIGH or LOW produces no sound, unlike an active buzzer

Pinout and connection notes

tone() on Arduino drives this directly from a digital pin with no extra hardware; on ESP32 use the ledc PWM API instead since tone() isn't implemented the same way there.

  • VCC / I/O: Signal input on breakout modules with 3 pins — a raw 2-lead piezo just has + and -
  • GND: Ground
  • I/O: On 3-pin modules: the driven PWM/tone signal; on bare 2-lead piezos, drive across the two leads directly

Integration checklist

  1. Confirm the exact part number and breakout-board revision.
  2. Verify supply voltage, current demand, logic levels, and signal direction against the datasheet.
  3. Check controller pin assignments and bus address or interface mode against the example code.
  4. Power up with external loads disconnected, then test signals before full integration.
  5. If readings or communication fail, check power and ground first, then pin mapping, interface settings, and library initialization.

Troubleshooting and reproducibility

Record the board used, wiring, library/version, supply arrangement, and measured behavior. Use the selected board-specific wiring example as the source of truth. Never assume visually similar modules share identical voltage tolerance or pin order.

Setting Up Passive Buzzer with Raspberry Pi

Library

gpiozero

Usually preinstalled on Raspberry Pi OS; otherwise: pip3 install gpiozero

Wiring

Component pinRaspberry Pi pinNote
I/O (signal)GPIO18 (physical pin 12)Hardware-PWM-capable pin, ideal for a clean tone
GNDGND
VCCNot connected (optional)

Swipe sideways to see every column →

Python
  • gpiozero's TonalBuzzer is built specifically for passive buzzers — its sibling class, Buzzer, is for active buzzers that only need on/off, so make sure you're using the right one.
  • Same 2-5kHz clearly-audible range as the other boards; TonalBuzzer will accept notes outside that but they'll sound faint on a typical piezo.
  • GPIO18 gets you real hardware PWM on the Pi, which produces a cleaner tone than a software-PWM pin would.

Related Components

Related Guides & Projects