Skip to content

Project 1.12.1

Bluetooth Buzzer Controller

Overview

Build a Bluetooth-controlled buzzer that responds to phone commands.

This project demonstrates using the same BLE communication idea from the LED project but with sound output.

The final result should let a phone turn the buzzer on, turn it off, or play short beep patterns.

Required Components

Raspberry Pi Pico 2 W
Raspberry Pi Pico 2 W
Active buzzer
Active buzzer
Breadboard
Breadboard
Jumper wires
Jumper wires
Phone with BLE app
Phone with BLE app

Circuit Connections

Component Pin Connects To Pico GPIO / Physical Pin Number Notes
Buzzer positive (+) GPIO 0 GPIO 0 / physical pin 1 -
Buzzer negative (-) GND Physical pin 38 -

Step-by-Step Assembly

Step 1: Place the Raspberry Pi Pico 2W

Place the Raspberry Pi Pico 2W 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 1

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 2

Step 3: Connect the Buzzer Positive Pin

Connect the buzzer positive (+) pin to GPIO 0.

Step 3

Step 4: Connect the Buzzer Negative Pin

Connect the buzzer negative (-) pin to 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 shared rooms.


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 Bluetooth 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.

BLE Advertising Test

Check that the Pico advertises as a BLE device your phone can see.

import bluetooth
import time
from ble_uart import BLEUART

ble = bluetooth.BLE()
ble.active(True)
uart = BLEUART(ble, name='Pico-Buzzer')

print('Scan for Pico-Buzzer in your BLE app')

while True:
    time.sleep(1)

Expected test result: Your phone BLE app should find a device named Pico-Buzzer.


Full Project Code

Upload and run this code after the individual tests work correctly.

from machine import Pin
import bluetooth
import time
from ble_uart import BLEUART

buzzer = Pin(0, Pin.OUT)
buzzer.off()

ble = bluetooth.BLE()
ble.active(True)
uart = BLEUART(ble, name='Pico-Buzzer')


def beep(count=1):
    for _ in range(count):
        buzzer.on()
        time.sleep(0.15)
        buzzer.off()
        time.sleep(0.15)


def on_rx(data):
    command = data.decode('utf-8').strip().lower()
    print('Received command:', command)

    if command in ('1', 'on'):
        buzzer.on()
        uart.write(b'Buzzer ON\n')
    elif command in ('0', 'off'):
        buzzer.off()
        uart.write(b'Buzzer OFF\n')
    elif command == 'beep':
        beep(1)
        uart.write(b'Beep played\n')
    elif command == 'double':
        beep(2)
        uart.write(b'Double beep played\n')
    elif command == 'help':
        uart.write(b'Commands: on, off, beep, double, help\n')
    else:
        uart.write(b'Unknown command. Send help.\n')


uart.on_rx(on_rx)

print('Bluetooth buzzer controller ready')
print('Connect with a BLE app and send commands: on, off, beep, double, help')

while True:
    time.sleep(0.1)

How the Code Works

Code Section What It Does Why It Matters
Buzzer setup Creates the active buzzer output on GPIO 0 The Bluetooth commands need a sound device to control
beep() function Creates one or more short buzzer sounds A function keeps repeated sound code easy to reuse
BLEUART service Creates the Bluetooth communication link to the phone This is how the phone sends control messages
on_rx() callback Processes incoming text commands This is where the buzzer actions are chosen

Expected Result

After running the code, your phone BLE app should find Pico-Buzzer. Sending on should make the buzzer stay on. Sending off should silence it. Sending beep or double should play the matching sound pattern.


Troubleshooting

Problem Possible Cause Solution
No sound Buzzer wiring or buzzer type is wrong Check polarity and confirm you are using an active buzzer
Phone cannot find Pico-Buzzer BLE libraries are missing or Bluetooth is not active Check the library files and rerun the advertising test
Commands do nothing The app is sending different text than expected Use simple commands like on, off, beep, or double