Pico W active buzzer beeps through an S8050
MicroPython on a Pico W: GP15 switches an S8050 that sounds an active buzzer: four short beeps, a pause of a second, and again. The whole build, a Raspberry Pi Pico W and 3 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Beginner About 10 minutes to build and run. Runs in your browser. Free, and no account needed.
The parts retail for about $6.55. On Mokxi they're free.
What you'll learn
- Switching a load with an NPN transistor
- Why a base resistor protects the pin and transistor
- Active buzzers versus passive buzzers
- Turning a pin on and off in MicroPython
- Difficulty: Beginner
- Time: About 10 minutes
- Board: Raspberry Pi Pico W
- Parts: 5
How it works
An active buzzer makes its own tone as soon as current flows through it. The Pico W pin is too weak to drive it directly, so an S8050 transistor acts as a switch between the buzzer and ground.
The buzzer's other leg connects to 3.3 V. When GP15 goes high, current flows through the 1k resistor into the transistor's base. The transistor turns on and the buzzer sounds. When GP15 goes low, it stops.
The program beeps four times, 300 ms on and 300 ms off. It prints a line, waits one second, and starts over.
Parts list
5 parts, plus the jumper wires. They retail for about $6.55; on Mokxi they're free.
- 1 × Raspberry Pi Pico W
- 1 × BuzzerIn Starter Kit, Rocket Flight Computer Kit.
- 1 × Transistor (NPN or PNP)In LED Cube Kit.
- 1 × Resistor, 1k ΩIn Starter Kit, Claw Machine Kit, Halloween Prop Kit.
- 1 × Power, 3.3 V
Kits that can build it
These 2 starter kits have every part in the circuit. Each kit's page lists what else it can build.
Wiring table
Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.
| Part and pin | Connects to |
|---|---|
| Resistor, 1k Ω pin 1 | Raspberry Pi Pico W pin GP15 |
| Buzzer pin 1 | 3.3 V |
| Transistor (NPN or PNP) pin C | Buzzer pin 2 |
| Resistor, 1k Ω pin 2 | Transistor (NPN or PNP) pin B |
| Transistor (NPN or PNP) pin E | Ground |
The code
The MicroPython code exactly as the editor opens it. Change a line there and press Run: the board runs it on the official MicroPython firmware, with nothing to compile.
# Beep: an active buzzer sounds whenever its transistor is on, so GP15
# high is a beep. Four short ones, a pause, and again.
from machine import Pin
import time
buzzer = Pin(15, Pin.OUT)
while True:
for _ in range(4):
buzzer.value(1)
time.sleep_ms(300)
buzzer.value(0)
time.sleep_ms(300)
print("beep beep beep beep")
time.sleep(1)
Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- The buzzer never sounds. This project
Check the transistor's pins: collector to the buzzer, emitter to ground, base to the 1k resistor going to GP15. - The buzzer is stuck on. This project
Make sure the buzzer connects between 3.3 V and the collector, and the emitter reaches ground. - The buzzer makes a constant tone, or you cannot change its pitch. Buzzer
An active buzzer has its own oscillator, so it only beeps on and off. A passive buzzer needs tone() to set pitch. Check which type you have. - The buzzer is silent or very quiet. Buzzer
Check polarity: the plus mark goes to the pin or supply. For loud buzzers, drive them through a transistor instead of straight from a pin. - The load never turns on, or is always on, because the legs are in the wrong order. Transistor (NPN or PNP)
Check the pinout in the datasheet for your part. A 2N2222 or BC547 can have emitter, base, collector in a different order. Flat side orientation is easy to get wrong. - The base is wired straight to the pin with no resistor, or the motor has no flyback diode. Transistor (NPN or PNP)
Put about 1k between the pin and the base. For motors and relays, add a diode across the coil with the stripe toward the positive side. - The LED is dim, burns out, or the pin reads wrong because the resistor value is off. Resistor
Read the color bands again. A 220 ohm to 330 ohm resistor suits a typical LED on 5 V. 10k is a common pull-up or pull-down value. Check with a multimeter if unsure. - A pull-up or pull-down resistor is missing, so the input floats and reads random values. Resistor
Tie the input to 5 V or ground through about 10k. Or use INPUT_PULLUP and wire the switch to ground.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.