An active buzzer module is the easiest alarm sound for a Pico W project: switch GP18 HIGH and it beeps. No PWM, no library.
The script plays a short beep, a three-beep alarm pattern and a long beep in a loop — copy the beep() function into your own project for gas, water-level or door alarms.
Wiring
| Raspberry Pi Pico W | Active buzzer module (high-level trigger) | Wire | Notes |
|---|---|---|---|
| 3V3 | VCC | red | 3V3 is pin 36. VBUS (pin 40) works too and is louder — I/O still only sees the transistor base. |
| GND | GND | black | GND pin 23 is right next to GP18. |
| GP18 | I/O | orange | GP18 is physical pin 24. |
3.3–5 V part, 3.3 V board. The I/O pin only drives the module's transistor, so a 3.3 V GPIO is enough even when the buzzer runs from 5 V. Check the label: "high-level trigger" beeps when I/O is HIGH; "low-level trigger" modules (with a PNP transistor) beep when I/O is LOW.
Board quirks
- An active buzzer has its own oscillator: a steady HIGH makes a fixed tone. If yours only clicks, it is a passive buzzer — see the passive buzzer guide.
- Check the module label. “Low-level trigger” modules use a PNP transistor and beep on LOW: set
ACTIVE_LOW = True. - The pin is set to the silent level when it is created, so the buzzer does not chirp at boot.
Code
# Active buzzer module on a Raspberry Pi Pico W (MicroPython).
# Wiring: VCC -> 3V3 (pin 36) or VBUS (pin 40) for a louder beep, GND -> GND, I/O -> GP18 (pin 24).
# I/O only drives the module's transistor, so a 3.3 V GPIO is fine either way.
# "High-level trigger" modules beep on HIGH; set ACTIVE_LOW = True for "low-level trigger" ones.
from machine import Pin
import time
ACTIVE_LOW = False
buzzer = Pin(18, Pin.OUT, value=1 if ACTIVE_LOW else 0) # start silent
def buzz(on):
buzzer.value((not on) if ACTIVE_LOW else on)
def beep(ms=100, times=1, gap=100):
for _ in range(times):
buzz(True)
time.sleep_ms(ms)
buzz(False)
time.sleep_ms(gap)
print("Active buzzer on GP18")
while True:
print("1 short beep")
beep(100)
time.sleep(1)
print("3 quick beeps (alarm pattern)")
beep(80, 3, 80)
time.sleep(1)
print("1 long beep")
beep(600)
time.sleep(2)# Active buzzer module on a Raspberry Pi Pico W (MicroPython).
# Wiring: VCC -> 3V3 (pin 36) or VBUS (pin 40) for a louder beep, GND -> GND, I/O -> GP18 (pin 24).
# I/O only drives the module's transistor, so a 3.3 V GPIO is fine either way.
# "High-level trigger" modules beep on HIGH; set ACTIVE_LOW = True for "low-level trigger" ones.
from machine import Pin
import time
ACTIVE_LOW = False
buzzer = Pin(18, Pin.OUT, value=1 if ACTIVE_LOW else 0) # start silent
def buzz(on):
buzzer.value((not on) if ACTIVE_LOW else on)
def beep(ms=100, times=1, gap=100):
for _ in range(times):
buzz(True)
time.sleep_ms(ms)
buzz(False)
time.sleep_ms(gap)
print("Active buzzer on GP18")
while True:
print("1 short beep")
beep(100)
time.sleep(1)
print("3 quick beeps (alarm pattern)")
beep(80, 3, 80)
time.sleep(1)
print("1 long beep")
beep(600)
time.sleep(2)Expected serial output
Active buzzer on GP18
1 short beep
3 quick beeps (alarm pattern)
1 long beepActive buzzer on GP18 1 short beep 3 quick beeps (alarm pattern) 1 long beep
Common errors
Buzzer is on all the time and stops when the code “beeps”
It is a low-level trigger module. Set ACTIVE_LOW = True.
Only a faint click
Passive buzzer, or VCC is not connected. Passive buzzers need a PWM tone.