Skip to content

Project 2.5.3: Iot Learning Kit

Intermediate Embedded Systems Project Using Raspberry Pi Pico 2 W and MicroPython


Overview

This project builds a small BLE learning station that combines an analog input, a PWM-controlled LED, and a threshold-based buzzer alert.

A potentiometer acts as the input, the LED brightness follows the input level, and the buzzer warns when the level crosses a threshold.

The final system should display the input level, adjust LED brightness, sound an alert above a chosen threshold, and let the threshold be tuned from a phone.

Required Components

10kΩ potentiometer
10kΩ potentiometer
Breadboard and jumper wires
Breadboard and jumper wires
Raspberry Pi Pico 2 W
Raspberry Pi Pico 2 W
LED
LED
220Ω resistor
220Ω resistor
Active buzzer
Active buzzer

Phone with BLUETOOTH app

Circuit Connections

Component terminal Connect to Pico physical pin Notes
Potentiometer left pin 3.3V Physical pin 36 Outer pin
Potentiometer middle pin GPIO 26 GPIO 26 / physical pin 31 ADC0 input
Potentiometer right pin GND Physical pin 38 Outer pin
LED anode (+) 220Ω resistor then GPIO 16 GPIO 16 / physical pin 21 PWM output
LED cathode (-) GND Physical pin 38 Common ground
Buzzer positive (+) GPIO 17 GPIO 17 / physical pin 22 Alert output
Buzzer negative (-) GND Physical pin 38 Common ground

Wiring Diagram

Circuit Diagram

Raspberry Pi Pico 2 W
┌─────────────────────┐
│                     │
│  3.3V ──────────────┤──── Potentiometer left pin
│  GPIO 26 ───────────┤──── Potentiometer middle pin (ADC0)
│  GND ───────────────┤──── Potentiometer right pin
│  GPIO 16 ───────────┤──── LED anode (+) via 220Ω resistor
│  GPIO 17 ───────────┤──── Buzzer +
│                     │
└─────────────────────┘

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 2: Place the Potentiometer

Insert the potentiometer onto the breadboard. Make sure each of the three potentiometer pins sits on a separate breadboard row.

Step 3: Connect One Outer Pin

Connect one outer potentiometer pin to 3.3V.

Step 4: Connect the Middle Pin

Connect the potentiometer middle pin to GPIO 26 (ADC0).

Step 5: Connect the Other Outer Pin

Connect the other outer potentiometer pin to GND.

Step 6: Place the LED

Place the LED on the breadboard. Identify the long leg as the anode (+) and the short leg as the cathode (-).

Step 7: Connect the LED Long Leg

Connect the LED long leg to one end of a 220Ω resistor.

Step 8: Connect the Resistor to GPIO 16

Connect the other end of the resistor to GPIO 16.

Step 9: Connect the LED Short Leg

Connect the LED short leg to GND.

Step 10: Place the Buzzer

Place the buzzer on the breadboard and identify its positive (+) and negative (-) pins.

Step 11: Connect the Buzzer Positive Pin

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

Step 12: Connect the Buzzer Negative Pin

Connect the buzzer negative (-) pin to GND.


Wiring Check

  • [x] Pico 2W is placed correctly across the breadboard center gap
  • [x] One potentiometer outer pin connects to 3.3V
  • [x] Potentiometer middle pin connects to GPIO 26
  • [x] Other potentiometer outer pin connects to GND
  • [x] LED long leg connects through a 220Ω resistor to GPIO 16
  • [x] LED short leg connects to GND
  • [x] Buzzer positive pin connects to GPIO 17
  • [x] Buzzer negative pin connects to GND
  • [x] No loose jumper wires

Intermediate Note

This project uses wireless UART on the Raspberry Pi Pico 2W. Use a terminal app such as nRF Connect, LightBlue, or another BLE UART terminal to connect to AIDER_LearnKit and send commands. The potentiometer value controls LED brightness, and the BLE threshold command changes when the buzzer alert happens.


Testing Individual Components

Before running the full project, test each part separately. This makes it easier to find wiring, library, or code problems.

Hardware setup

  • Build the potentiometer, LED, and buzzer circuit
  • Keep the potentiometer wiring short so the ADC reading stays stable

Test the input sensor

  • Run a short ADC script and rotate the potentiometer through the full range
  • Confirm the percentage changes smoothly from low to high

Test the output devices

  • Run a short PWM LED test to confirm brightness changes
  • Run a short buzzer test so you know the alert output works before combining everything

Test communication

  • Connect to AIDER_LearnKit from the BLE app
  • Send status, threshold 70, alerts off, and alerts on to verify the command interface

Run the full system

  • Rotate the potentiometer and observe the LED brightness
  • Turn the knob above the threshold and confirm the buzzer and BLE alert activate
  • Lower the input again and confirm the alert condition clears

Save the project

  • Save the working code
  • Record which threshold value felt most useful for the classroom demonstration

Full Project Code

After completing and checking the circuit connections, open Thonny IDE. Copy and paste the code below into a new file, or upload the project file to the Raspberry Pi Pico 2 W, then run it from Thonny.

from machine import ADC, PWM, Pin
import bluetooth
import time
from ble_uart import BLEUART

DEVICE_NAME = "AIDER_LearnKit"
ALERT_COOLDOWN_MS = 1500
sensor = ADC(26)
led = PWM(Pin(16))
led.freq(1000)
buzzer = Pin(17, Pin.OUT)
ble = bluetooth.BLE()
ble.active(True)
uart = BLEUART(ble, name=DEVICE_NAME)

threshold_percent = 80
alerts_enabled = True
last_alert_ms = time.ticks_add(time.ticks_ms(), -ALERT_COOLDOWN_MS)
command_queue = []


def send_line(message):
    print(message)
    uart.write((message + "\n").encode())


def on_rx(data):
    command = data.decode("utf-8").strip().lower()
    if command:
        command_queue.append(command)


def current_percent():
    raw_value = sensor.read_u16()
    return int((raw_value * 100) / 65535)


def set_brightness(percent):
    duty = int((percent * 65535) / 100)
    led.duty_u16(duty)


def beep_alert():
    buzzer.on()
    time.sleep_ms(120)
    buzzer.off()


uart.on_rx(on_rx)
send_line("Bluetooth IoT learning kit ready")

while True:
    now = time.ticks_ms()
    percent = current_percent()
    set_brightness(percent)

    if alerts_enabled and percent >= threshold_percent and time.ticks_diff(now, last_alert_ms) >= ALERT_COOLDOWN_MS:
        beep_alert()
        send_line("ALERT: Input level {}% reached the threshold".format(percent))
        last_alert_ms = now

    if command_queue:
        command = command_queue.pop(0)
        if command == "status":
            send_line("Level:{}% Threshold:{}% Alerts:{}".format(percent, threshold_percent, alerts_enabled))
        elif command.startswith("threshold "):
            threshold_percent = int(command.split()[1])
            send_line("Threshold set to {}%".format(threshold_percent))
        elif command == "alerts on":
            alerts_enabled = True
            send_line("Alerts enabled")
        elif command in ("alerts off", "mute"):
            alerts_enabled = False
            buzzer.off()
            send_line("Alerts disabled")
        elif command == "help":
            send_line("Commands: status, threshold <value>, alerts on, alerts off, mute, help")
        else:
            send_line("Unknown command. Send help.")

    time.sleep_ms(100)

How the Code Works

Code Section What It Does Why It Matters
current_percent() Reads the analog level and scales it to 0 to 100% One normalised value can drive several outputs
PWM LED control Maps the percentage directly to LED brightness Creates clear visual feedback
Threshold comparison Checks whether the input level is above the alert limit Adds rule-based decision logic to the kit
BLE threshold commands Allow the student to tune the alert limit remotely Encourage calibration and experimentation

Expected Result

As the potentiometer is turned, the LED gets brighter or dimmer. When the level rises above the chosen threshold, the buzzer sounds briefly and the BLE app receives an alert message.


Troubleshooting

Problem Possible cause Solution
LED brightness does not change The LED is not on the PWM pin path or the potentiometer is wired incorrectly Check GPIO 16, the resistor, and the potentiometer middle-pin connection on GPIO 26.
Alert never triggers The threshold is too high or alerts are disabled Lower the threshold temporarily and confirm alerts are enabled.
Buzzer stays silent The buzzer wiring is wrong or the buzzer needs a driver Verify GPIO 17 wiring and use a driver if the buzzer needs more current.
Phone cannot find the BLE device The Pico is not advertising or the BLE helper files are missing Confirm ble_uart.py and ble_advertising.py are saved on the Pico, restart the board, and scan again from nRF Connect or LightBlue.
Commands do not change the system state The phone is connected to the wrong service or the command text is different from the expected command Reconnect to the BLE UART service and send the exact command shown in the test section.