Learn

Sounding an Active Buzzer on a Raspberry Pi 4B

Wire an active buzzer to a Raspberry Pi 4B GPIO pin and switch it on and off in Python — the simplest possible sound output, no PWM required.

Try this directly in the free Raspberry Pi 4B simulator — no hardware or signup required. New to the GPIO header? Start with the interactive pinout guide.

What you’ll need

  • Raspberry Pi 4B
  • Active Buzzer

Step by step

  1. Drag Raspberry Pi 4B onto the Canvas.
  2. Drag the Active Buzzer onto the Canvas — it connects via drawn wires, not breadboard legs.
  3. Hover over its 2 pins to confirm the labels: Positive (+) and Negative (−).
  4. Wire it up: Positive → a GPIO pin (e.g. pin 37). Negative → a Pi GND pin.
  5. Go to the Code tab and write:
import RPi.GPIO as GPIO
import asyncio
 
buzzerPin = 37
 
GPIO.setmode(GPIO.BOARD)
GPIO.setup(buzzerPin, GPIO.OUT)
 
GPIO.output(buzzerPin, GPIO.HIGH)
await asyncio.sleep(1)
 
GPIO.output(buzzerPin, GPIO.LOW)
GPIO.cleanup()
  1. Click Start — this app plays a real, brief tone through your computer's speakers whenever the buzzer is powered, so make sure your volume isn't muted.

What “working correctly” looks like

  • The buzzer's own small musical-note indicator animates for exactly the 1 second the pin is driven HIGH, and you should hear a short, steady electronic tone through your speakers for that same second.
  • Driving the pin LOW again silences it instantly — an active buzzer has its own tiny built-in oscillator, so all your code has to do is turn it on and off, the same as an LED.

If something’s wrong

  • Note indicator animates but you hear nothing → check your computer/browser volume isn't muted; the tone is deliberately quiet by design, but it should still be audible at a normal volume.
  • Nothing happens at all, indicator included → confirm Negative is wired to a real Pi GND pin — an active buzzer, like an LED, needs a complete circuit to sound.
  • Want a changing pitch instead of one fixed tone? That needs the Passive Buzzer component instead — an Active Buzzer only ever makes ONE tone, since it has its own built-in oscillator.