Buzzer / Piezo
Controlling Passive Buzzer Buzzer / Piezo with STM32 Blue Pill
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 STM32 Blue Pill
Wiring
| Component pin | STM32 Blue Pill pin | Note |
|---|---|---|
| I/O (signal) | PA0 | |
| GND | GND | |
| VCC | Not connected (optional) |
Swipe sideways to see every column →
- Not every STM32duino core version ships a working tone()/noTone() — this bit-banged square-wave generator sidesteps that dependency and works regardless of core support.
- Same 2-5kHz sweet spot as the other boards.
- On 3-pin passive buzzer modules, VCC is often unconnected since the piezo has no internal circuitry to power — only the signal pin and GND actually matter.
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
STM32 Low-Power Modes: Sleep, Stop, and Standby Explained (With Working Code)
A practical guide to STM32's three-tier low-power system — Sleep, Stop, and Standby — with working STM32duino code, measured current draw on a Blue Pill, and a battery-powered project example.
STM32 Blue Pill Pinout: Every GPIO, ADC, and Alternate Function Explained
A complete STM32F103C8T6 Blue Pill pinout reference: every GPIO port, ADC channel, timer, and communication bus mapped, plus the 5V-tolerance and clone-board considerations that affect wiring decisions.
STM32 Black Pill Pinout: Every GPIO, ADC, and Peripheral Explained
Complete STM32 Black Pill (STM32F411CEU6) pinout reference: GPIO ports, 12-bit ADC, timers/PWM, USART, SPI, I2C, and the 3.3V-only pins to watch out for.
STM32 Nucleo Pinout: Arduino Headers, Morpho Connectors, and GPIO Explained
Complete STM32 Nucleo pinout reference: Arduino-compatible headers vs ST Morpho connectors, the built-in ST-LINK debugger, ADC voltage limits, and every peripheral pin mapped.