STEMAIDE AFRICA
Project 1.8.2: Wi-Fi Buzzer Web Controller
Beginner Embedded Systems Project Using Raspberry Pi Pico 2 W and MicroPython
Overview
Build a web-controlled buzzer using Wi-Fi and a browser.
This project demonstrates sending a browser action to create a sound on the Pico side.
The final result should open a web page where a button makes the buzzer sound.
Required Components
![]() Raspberry Pi Pico 2 W |
![]() Active Buzzer |
![]() Breadboard |
![]() Jumper Wires |
| 2.4 GHz Wi-Fi Network | Phone or Computer Browser |
Circuit Connections
| Component Pin | Connects To | Pico GPIO / Physical Pin Number | Notes |
|---|---|---|---|
| Buzzer Positive (+) | GPIO 0 | GPIO 0 / Physical Pin 1 | Output signal |
| Buzzer Negative (-) | GND | Physical Pin 38 | Common ground |
Step-by-Step Assembly
Step 1: Place the Raspberry Pi Pico 2 W
Place the Raspberry Pi Pico 2 W on the breadboard so it sits across the center gap.
Keep the USB port facing outward so you can easily connect it to your computer.

Step 2: Place the Active Buzzer
Place the active buzzer on the breadboard.
Identify the positive (+) and negative (-) pins before wiring.
Use a small 3.3V-safe buzzer, or use a driver if your buzzer needs more current.

Step 3: Connect the Buzzer Positive Pin
Connect:
- Buzzer positive (+) → GPIO 0

Step 4: Connect the Buzzer Negative Pin
Connect:
- Buzzer negative (-) → GND

Wiring Check
- Pico 2W is placed correctly across the breadboard center gap
- Buzzer positive pin connects to GPIO 0
- Buzzer negative pin connects to GND
- No loose jumper wires
Beginner Note
An active buzzer makes sound when it receives power from the GPIO pin. Keep test sounds short in a classroom.
Testing Individual Components
Before running the full project, test each part separately. This makes it easier to find wiring or code problems.
Buzzer Test
Check that the buzzer sounds before adding Wi-Fi code.
from machine import Pin
import time
buzzer = Pin(0, Pin.OUT)
buzzer.on()
time.sleep(0.3)
buzzer.off()
Expected Test Result
The buzzer should sound briefly.
Wi-Fi Connection Test
Check that the Pico 2 W connects to Wi-Fi and prints its IP address.
import network
import time
SSID = 'YOUR_WIFI_NAME'
PASSWORD = 'YOUR_WIFI_PASSWORD'
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(SSID, PASSWORD)
for _ in range(15):
if wlan.isconnected():
break
print('Connecting...')
time.sleep(1)
print('Connected:', wlan.isconnected())
if wlan.isconnected():
print('IP address:', wlan.ifconfig()[0])
Expected Test Result
The Shell should show Connected: True and print an IP address.
Full Project Code
import network
import socket
import time
from machine import Pin
SSID = 'YOUR_WIFI_NAME'
PASSWORD = 'YOUR_WIFI_PASSWORD'
buzzer = Pin(0, Pin.OUT)
def buzz_once():
buzzer.on()
time.sleep(0.3)
buzzer.off()
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(SSID, PASSWORD)
print('Connecting to Wi-Fi...')
for _ in range(15):
if wlan.isconnected():
break
time.sleep(1)
if not wlan.isconnected():
raise RuntimeError('Wi-Fi connection failed')
ip_address = wlan.ifconfig()[0]
print('Connected. Open http://{} in your browser'.format(ip_address))
html = """<!DOCTYPE html>
<html>
<head>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<title>Wi-Fi Buzzer</title>
</head>
<body style='font-family:Arial;text-align:center;padding:40px'>
<h1>Wi-Fi Buzzer Control</h1>
<p>Press the button to sound the buzzer.</p>
<a href='/beep'>
<button style='padding:16px 28px;font-size:20px'>BEEP</button>
</a>
</body>
</html>"""
address = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
server = socket.socket()
server.bind(address)
server.listen(1)
while True:
client, client_address = server.accept()
print('Client connected from', client_address)
request = client.recv(1024).decode()
if 'GET /beep' in request:
buzz_once()
print('Buzzer sounded')
client.send(
'HTTP/1.1 200 OK\r\n'
'Content-Type: text/html\r\n'
'Connection: close\r\n\r\n'
)
client.sendall(html)
client.close()
How the Code Works
| Code Section | What It Does | Why It Matters |
|---|---|---|
buzz_once() |
Turns the buzzer on for a short time and then off | Keeps the sound easy to control |
| Wi-Fi setup | Connects the Pico 2 W to the network | The web server needs Wi-Fi before the page can be opened |
| HTML page | Creates a simple page with one BEEP button | The browser needs this page to send the command |
| Request check | Looks for /beep in the browser request |
Tells the Pico when to sound the buzzer |
Expected Result
After entering your Wi-Fi details and running the code, the Shell should print an IP address.
Opening that address in a browser should show a BEEP button.
Pressing the button should sound the buzzer briefly.
Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| No sound | Buzzer wiring is wrong or buzzer type is unsuitable | Check polarity and confirm you are using an active buzzer |
| Wi-Fi never connects | Wrong network details or unsupported network | Recheck the SSID and password and make sure the network is 2.4 GHz |
| Web page opens but button does nothing | Browser request is not reaching the Pico or buzzer test failed | Run the buzzer test first and then recheck the request code |



