Raspberry Pi Pico PIR Sensor Interfacing and Programming
Table of Contents
Raspberry Pi Pico PIR Sensor:
Raspberry Pi Pico PIR Sensor Interfacing and Programming- In this article, I will show you how to use a PIR sensor and a 5V buzzer with the Raspberry Pi Pico. We will be making a small security system.
Previous Articles:
Raspberry Pi Pico Pinout & Specs
Raspberry Pi Pico MicroPython and Thonny IDE Installation.
Raspberry Pi Pico Led examples.
Raspberry Pi Pico Digital Input.
Raspberry Pi Pico Oled Display Module SSD1306
Raspberry Pi Pico ADC Analog Sensor
Raspberry Pi Pico Temperature Sensor.
Raspberry Pi Pico Ultrasonic Sensor.
Raspberry Pi Pico LDR Sensor, Day & Night Detection.
Amazon Links:
Other Tools and Components:
Super Starter kit for Beginners
PCB small portable drill machines
*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!
The PIR Sensor triggers the Pico Board each time motion is detected and then the Raspberry Pi Pico board turns on the Buzzer. Let’s go ahead and take a look at the circuit diagram.
Raspberry Pi Pico PIR Sensor Circuit Diagram:
The PIR Motion Sensor Red and Black wires are connected with the Raspberry Pi Pico board 3.3V and GND pins. While the signal wire of the PIR sensor is connected with the GP14 of the Pico board. This is a 5V buzzer and it can’t be directly controlled using the Pico board; so, that’s why I am using this driver circuit to turn ON and OFF this buzzer. The base of the transistor is connected with GP28 pin of the Raspberry Pi Pico Board. So, that’s all about the connections.
Raspberry Pi Pico PIR Motion Sensor Programming:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
from machine import Pin import time buzzer = Pin(28, Pin.OUT) PirSensor = Pin(14, Pin.IN, Pin.PULL_DOWN) while True: if PirSensor.value(): buzzer.value(1) time.sleep(3) buzzer.value(0) time.sleep(5) else: buzzer.value(0) |
I defined buzzer as the output and PIR Sensor as the Input. Buzzer is connected to GP28 and PIR Sensor is connected to GP14. I am going to call these pins the buzzer and PirSensor.
Inside the while loop, we check if the PIR Motion sensor has detected any motion and then accordingly turn ON and turn OFF the buzzer. So, that’s all about the code.
I uploaded the code and it was working perfectly. For the practical demonstration watch video given below.
Next article, Raspberry Pi Pico Digital LDR Sensor for Day and Night detection.