Buzzer / Piezo
Controlling Passive Buzzer Buzzer / Piezo with Espressif ESP32
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 Espressif ESP32
Wiring
| Component pin | Espressif ESP32 pin | Note |
|---|---|---|
| I/O (signal) | GPIO25 | |
| GND | GND | |
| VCC | Not connected (optional) |
Swipe sideways to see every column →
- ESP32's Arduino core generates tones through the LEDC peripheral rather than the classic AVR tone() function — ledcWriteTone() is the equivalent used here.
- Same 2-5kHz sweet spot and "silent without an oscillating signal" caveat as the Arduino Uno.
- If your specific core version does support tone()/noTone() directly, that works too — LEDC is just the more universally-supported approach across core versions.
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
MicroPython vs Arduino on ESP32: Which Should You Learn First?
An honest comparison for beginners: where MicroPython is easier, where Arduino C++ is faster, how libraries and memory differ, and how to choose based on your project instead of hype.
MicroPython ESP32 Web Server: Control an LED or Relay from Your Browser
Create a working web server with the socket module, parse requests, serve a responsive control page for an LED or a relay, keep the displayed state truthful, choose a safe relay startup state and make the server survive bad or repeated requests.
MicroPython on ESP32 and Raspberry Pi Pico W: The Complete Guide
A structured MicroPython learning path for ESP32 and Pico W. Set up your tools, control GPIO, read sensors, connect to WiFi, build web servers, publish MQTT data and make projects reliable. Start here, then follow the links by level.
boot.py vs main.py in MicroPython: What Runs, When and Why
Understand the difference between boot.py and main.py in MicroPython, startup order, Wi-Fi setup, project structure, and recovery from boot errors.