Skip to content

Project 1.3.2: PIR Motion Buzzer Alarm


Overview

Build a motion-triggered buzzer alarm.

This project demonstrates how one sensor can trigger an audible alert.

The final result is a buzzer that sounds when motion is detected.

Required Components

Raspberry Pi Pico 2 W
Raspberry Pi Pico 2 W
PIR motion sensor
PIR motion sensor
Active buzzer
Active buzzer
Breadboard
Breadboard
Jumper wires
Jumper wires

Circuit Connections

Component Pin Connects To Pico GPIO / Physical Pin Number Notes
PIR VCC 3.3V or module-safe supply Physical pin 36 Check your PIR module label
PIR GND GND Physical pin 38
PIR OUT GPIO 1 GPIO 1 / physical pin 2 3.3V logic only
Buzzer positive (+) GPIO 0 GPIO 0 / physical pin 1 Use a small active buzzer
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.

step1


Step 2: Position the PIR Sensor

Place the PIR sensor so the white dome faces the area where you want to detect motion.

Check the labels on the PIR sensor pins before wiring. Most PIR sensors have:

  • VCC
  • OUT
  • GND

Some modules may have the pins in a different order, so confirm the labels on your own module.

step2


Step 3: Connect PIR VCC

Connect the PIR VCC pin to 3.3V on the Raspberry Pi Pico 2W if your PIR module supports 3.3V operation.

If your PIR sensor requires 5V, power it from 5V, but make sure the OUT signal is safe for the Pico’s 3.3V GPIO pin.

step3


Step 4: Connect PIR GND

Connect the PIR GND pin to a GND pin on the Raspberry Pi Pico 2W.

step4


Step 5: Connect PIR OUT to GPIO 1

Connect the PIR OUT pin to GPIO 1 on the Raspberry Pi Pico 2W.

The PIR OUT pin sends a digital signal to the Pico when motion is detected.

step5


Step 6: Place the Active Buzzer

Insert the active buzzer onto the breadboard.

Make sure the two buzzer pins are placed in different breadboard rows.

step6


Step 7: Connect the Buzzer Positive Pin to GPIO 0

Connect the buzzer’s positive pin (+) to GPIO 0 on the Raspberry Pi Pico 2W.

step7


Step 8: Connect the Buzzer Negative Pin to GND

Connect the buzzer’s negative pin (-) to a GND pin on the Raspberry Pi Pico 2W.

step8


Wiring Check

Before running the code, confirm:

  • Pico 2W is placed correctly across the breadboard center gap
  • PIR sensor faces the motion test area
  • PIR VCC connects to the correct power pin for your module
  • PIR GND connects to GND
  • PIR OUT connects to GPIO 1
  • Active buzzer positive pin connects to GPIO 0
  • Active buzzer negative pin connects to GND
  • No loose jumper wires

!!! note "Beginner Note"

Most PIR sensors need 10–60 seconds to stabilize after power is connected.

During this warm-up time, the sensor may give false motion readings.

Wait before testing the alarm.

Testing Individual Components

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

PIR Sensor Test

Check motion detection first.

from machine import Pin
import time

pir = Pin(1, Pin.IN)

print('Wait 10 seconds for PIR warm-up')
time.sleep(10)

while True:
    print('Motion' if pir.value() else 'No motion')
    time.sleep(0.5)

Expected test result: The Shell reports Motion when movement is detected.


Buzzer Test

Check the buzzer before combining everything.

from machine import Pin
import time

buzzer = Pin(0, Pin.OUT)

for _ in range(2):
    buzzer.on()
    time.sleep(0.2)
    buzzer.off()
    time.sleep(0.2)

Expected test result: The buzzer beeps twice.


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 Pin
import time

buzzer = Pin(0, Pin.OUT)
pir = Pin(1, Pin.IN)

def alarm_pattern():
    for _ in range(3):
        buzzer.on()
        time.sleep(0.2)
        buzzer.off()
        time.sleep(0.2)

print('Motion alarm ready')
print('Wait 10 seconds for PIR warm-up')
time.sleep(10)

while True:
    if pir.value():
        print('ALARM! Motion detected')
        alarm_pattern()
        time.sleep(1)
    time.sleep(0.1)

How the Code Works

Code Section What It Does Why It Matters
alarm_pattern() Creates three short buzzer beeps Makes the alarm easier to recognize
Warm-up delay Lets the PIR stabilize Reduces false triggers
PIR check Looks for motion Starts the alarm only when needed
Cooldown delay Waits briefly after the alarm Helps avoid immediate repeats

Expected Result

After PIR warm-up, movement in front of the sensor makes the buzzer play a three-beep alarm pattern.


Troubleshooting

Problem Possible Cause Solution
Alarm never sounds PIR still warming up or incorrect wiring Wait longer and recheck VCC, GND, and OUT
Alarm repeats too often Sensor retriggers quickly Aim the sensor carefully and add more delay if needed
Weak buzzer sound Buzzer current too high for GPIO Use a transistor driver for the buzzer