Skip to content

Project 1.3.1: PIR Motion Activated LED Light


Overview

Build a motion-activated LED light using a PIR sensor.

This project demonstrates motion sensing and timed output control.

The final result is an LED that turns on when movement is detected.

Required Components

Raspberry Pi Pico 2 W
Raspberry Pi Pico 2 W
PIR motion sensor
PIR motion sensor
LED
LED
220Ω resistor
220Ω resistor
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 Start with 3.3V if your module supports it
PIR GND GND Physical pin 38
PIR OUT GPIO 1 GPIO 1 / physical pin 2 3.3V logic only
LED anode (+) 220Ω resistor then GPIO 0 GPIO 0 / physical pin 1
LED cathode (-) GND Physical pin 38

Step-by-Step Assembly

Step 1: Place the Raspberry Pi Pico 2W

Insert the Raspberry Pi Pico 2W onto the breadboard so that it sits across the center gap.

Make sure the USB port faces outward so you can easily connect it to your computer.

step1


Step 2: Position the PIR Sensor

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

Make sure you can clearly identify the three PIR pins:

  • VCC
  • OUT
  • GND

Some PIR modules have different pin orders, so always check the labels printed on your module before wiring.

step2


Step 3: Connect PIR VCC

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

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:

  • HIGH when motion is detected
  • LOW when no motion is detected

step5


Step 6: Place the LED

Insert the LED onto the breadboard.

  • Place the long leg (anode, +) in one row.
  • Place the short leg (cathode, -) in a different row.

Do not place both LED legs in the same breadboard row.

step6


Step 7: Connect the LED Long Leg to the Resistor

Insert one end of the 220Ω resistor into the same row as the LED’s long leg on the Breadboard.

step7


Step 8: Connect the Resistor to GPIO 0

Connect the other end of the 220Ω resistor from the Breadboard to GPIO 0 on the Raspberry Pi Pico 2W.

step8


Step 9: Connect the LED Short Leg to GND

Connect the LED’s short leg to a GND pin on the Raspberry Pi Pico 2W.

step9


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 3.3V only if the module supports 3.3V operation
  • PIR GND connects to GND
  • PIR OUT connects to GPIO 1
  • LED long leg connects to the 220Ω resistor
  • Resistor connects to GPIO 0
  • LED short leg connects to GND
  • No loose jumper wires

!!! note "Beginner Note"

Most PIR sensors need a short warm-up time after power is connected.

Wait about 10–60 seconds before testing motion detection.

Some PIR modules also have small adjustment knobs for sensitivity and delay time.

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 before adding the LED logic.

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: After warm-up, the Shell reports Motion when you move in front of the sensor.


LED Test

Check the LED wiring separately.

from machine import Pin
import time

led = Pin(0, Pin.OUT)

led.on()
time.sleep(1)
led.off()

Expected test result: The LED turns on, then off.


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

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

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

while True:
    if pir.value():
        led.on()
        print('Motion detected - LED ON')
        time.sleep(5)
        led.off()
        print('LED OFF')
    time.sleep(0.1)

How the Code Works

Code Section What It Does Why It Matters
Warm-up delay Waits for the PIR to stabilize PIR modules often give false readings right after power-up
PIR input Reads whether motion is detected This is the project trigger
LED control Turns the LED on and off Gives a visible response
5-second delay Keeps the light on briefly Makes the project act like a motion light

Expected Result

After the warm-up time, movement in front of the PIR sensor turns the LED on for about 5 seconds.


Troubleshooting

Problem Possible Cause Solution
LED always on PIR still warming up or output floating Wait longer and check the OUT wiring
No motion detected Sensor not powered correctly Check VCC, GND, and the module supply requirements
Random triggers Sensor too sensitive or facing heat sources Reposition the sensor and reduce nearby movement or heat