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
- Confirm the exact part number and breakout-board revision.
- Verify supply voltage, current demand, logic levels, and signal direction against the datasheet.
- Check controller pin assignments and bus address or interface mode against the example code.
- Power up with external loads disconnected, then test signals before full integration.
- 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 pin | Raspberry Pi pin | Note |
|---|---|---|
| I/O (signal) | GPIO18 (physical pin 12) | Hardware-PWM-capable pin, ideal for a clean tone |
| GND | GND | |
| VCC | Not connected (optional) |
Swipe sideways to see every column →
- 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
Active Buzzer
Self-oscillating buzzer that beeps with just a single HIGH signal — no PWM required.
KY 040
Clickable rotary encoder with integrated push-button — perfect for menu navigation and volume control.
Reed Switch
Simple, reliable open/close detection for DIY alarms.
TTP223
Touch-sensitive pad for replacing mechanical buttons — perfect for clean, sealed enclosures.
Related Guides & Projects
Raspberry Pi Pico W and Pico 2 W: Install MicroPython with Thonny or UF2
Hold BOOTSEL, drag the correct UF2 file, open the REPL and blink the onboard LED. Includes the Pico vs Pico W vs Pico 2 W firmware differences and what to do when the drive does not appear.
Raspberry Pi Pico W Web Server in MicroPython: Control an LED and Read a Sensor
Connect the Pico W to WiFi, serve a responsive control page, switch an LED and display the onboard temperature or an external sensor, with timeouts and reconnect handling.
Raspberry Pi Pico Oscilloscope with MicroPython
Convert a Raspberry Pi Pico into a basic 500 kSPS oscilloscope using its 12-bit ADC and MicroPython. Displays waveforms on an SSD1306 OLED or streams samples over USB serial to a Python plotter on your PC.
Self-Hosted Nextcloud NAS on Raspberry Pi 4
Build a private, durable Nextcloud NAS on a Raspberry Pi 4 -- SSD boot instead of a failure-prone SD card, Docker Compose with Redis caching, Tailscale for remote access with zero ports forwarded, and an automated backup strategy that actually runs.