Preview build — page text is a draft awaiting human review. Code badges come from real compiles. The flasher is real but not yet hardware-tested; the Playground is still a preview.

Active buzzer module with Raspberry Pi Pico W — MicroPython beeps

Beep an active buzzer module from a Pico W on GP18 in MicroPython: short, long and alarm patterns, with high- and low-level trigger modules covered.

MicroPythonVerified — micropython (mpy-cross v1.29.0), 3 Nov 2026Compile-only

Community draft — report a mistake

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 WOnly the pins used are shown · 3.3 V logicActive buzzer module (high-level trigger)GND3V3GP18I/OVCCGND
Every connection
Raspberry Pi Pico WActive buzzer module (high-level trigger)WireNotes
3V3VCCred3V3 is pin 36. VBUS (pin 40) works too and is louder — I/O still only sees the transistor base.
GNDGNDblackGND pin 23 is right next to GP18.
GP18I/OorangeGP18 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

main.pyMicroPython
# 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

REPL / Thonny shellOutput
Active 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.

↑↓ to move · Enter to open