Motion detection with RPi, GPIO and PIR

My goal was very simple: detect motion in short range (some meters).

What is needed: RPi, breadboard (optional), jumper cables and a PIR sensor.
  • The PIR costs only a few euros (I got 5 for 8 EUR). searx it ;)
And on software side: python with RPi.GPIO module
  • If you don't have RPi.GPIO, you can install it from pip

The connections are simple, the PIR I have used has three legs (gnd,vcc,out). Basically you connect PIR's gnd to RPi's ground, VCC to 5V and out to a GPIO leg. The pictures will tell everything.


After you have connected everything, you can use python to get notices. Example code:

# Example code for PIR sensor
import RPi.GPIO as GPIO
import time

# Set GPIO
pir_in = 7  # -> your pin number
GPIO.setup(pir_in, GPIO.IN)

# Start detecting motion
    while True:
         if GPIO.input(pir_in):
             print (time.strftime("%H:%M:%S")) + ": Motion detected!"

except KeyboardInterrupt:

Finally you can adjust the sensitivity by turning the controls on the PIR (time/delay).

Note: a few PIR sernsors are available in H.A.C.K.
Contributors to this page: Avyd .
Page last modified on Sunday 04 of January, 2015 11:32:10 CET by Avyd.

Upcoming Events

1)  Wed 01 of Jan, 2020 18:00 CET
Kotes workshop