Authorized Online Retailers:

Buy from USA Buy from UK Buy from DE Buy from IT Buy from FR Buy from ES ここでご購入を!

In this project, we will use a PIR motion sensor to detect human movement. Once an intruder’s motion is detected, Pico will trigger a buzzer alarm. This is a typical application used in many home security systems.

  1. Raspberry Pi Pico board and microUSB cable
  2. A computer to run Thonny Python IDE
  3. A breadboard
  4. PIR motion sensor x 1 pc
  5. Active Buzzer (low voltage trig) x 1 pc
  6. Some jumper wires

In above circuit graph, you can see that:
PIR sensor VCC pin connected to VBUS(5V)
PIR sensor GND pin connected to GND
PIR sensor OUT pin connected to GP16
buzzer I/O pin   connected to GP15

You can download the lesson6 python code from
Here is the full code with comments:

from machine import Pin #import Pin library
from time import sleep # import sleep function

buzzer = Pin(15, Pin.OUT,Pin.PULL_UP) #set GP15 as digital output pin for buzzer
pir = Pin(16, Pin.IN,Pin.PULL_DOWN)  # set GP16 as digital input pin for PIR motion sensor

while True:
    if pir.value(): #when PIR detects motion 
        print("Intruder is detected!")  
        buzzer.low() # make buzzer alarm
        buzzer.high() #close buzzer alarm
        print("No Intruder!")

Step 1: Connect the Pico board to one of the USB ports on your PC.
Step 2: If you haven’t installed Thonny Software or don’t know how to use Thonny IDE, please read Lesson 1.

Step 3: Now open the Thonny Python IDE and click Run to select MicroPython for Raspberry Pi Pico as the interpreter.

Also, please select the COM port to which your Pico board is connected.

After that, click OK to save the setting.

Step 4: Copy the Python code to the Thonny window as follows:

Step 5: Click the little ► button. The save page will pop up as shown in the following photo; select Raspberry Pi Pico as the destination.

Step 6: Name the file, then click OK.

Step 7: Click the little ► button again to run the Python code.

Now put your hand close to the PIR motion sensor, and the buzzer will sound, and the shell will show “Intruder is detected.” Now remove your hand from the PIR motion sensor, and the buzzer will stop sounding, and the shell will show “No Intruder.”

After the operation is complete, press Ctrl+C to end the command.

Learn More about parts SKU:2021005900

No. Picture Product Name Link
1 Raspberry Pi Pico Board
2 Servo motor
3 Infrared Sensor Module
4 RFID Module and card
5 Push Buttons and Hats
6 LED(6 x White, 6 x Red, 6 x Yellow, 6x Green)
7 Servo motor
8 Piezo Buzzer Module
9 I2C LCD Display(16×2)
10 Philips Screwdriver
11 Solderless Prototype Breadboard
12 Potentionmeter (10K adjustable resistor)
13 40Pin M to M Jumper Wires
14 20Pin M to F Jumper wires 15cm