HC SR501 Pir Motion Sensor Gerak
Table of Contents
Persiapan Part: #
– Raspberry Pi Pico / Pico W
– HC SR501 Pir Motion Sensor
– Breadboard
– 3x Kabel Jumper Male to Female
– Kabel Micro USD
– Aplikasi Thonny IDE
Wiring HC SR501 Ke Raspberry Pi Pico
– connect the VCC (power) pin of the sensor with a 5V pin (red wire)
– connect the OUTPUT pin of the sensor to GP22 (yellow wire)
– connect the GND of the sensor to a GND (ground) pin (black cable)
Sample Code #
from machine import Pin
import time
pir = Pin(22, Pin.IN, Pin.PULL_DOWN)
n = 0
print('Starting up the PIR Module')
time.sleep(1)
print('Ready')
while True:
if pir.value() == 1:
n = n+1
print('Motion Detected ',n)
time.sleep(1)