Raspberry Pi with PIR Sensor

INTRODUCTION

In this lesson, we will learn on how to use a PIR sensor module with Raspberry Pi. It’s simple and easy project to detect a motion. 

HARDWARE PREPARATION

This tutorial use :

  1. Raspberry Pi
  2. Maker Hat
  3. USB Micro B Cable
  4. Low Cost PIR Sensor Module

You can make the hardware connection based on the diagram and table below.

Sample Code

This is the sample code used for this tutorial. Try it!

import RPi.GPIO as GPIO
import time
Buzzer = 26
PIR = 23
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(PIR, GPIO.IN)
GPIO.setup(Buzzer,GPIO.OUT)
try:
time.sleep(2)
while True:
if GPIO.input(PIR) == 1:
GPIO.output(Buzzer,GPIO.HIGH)
print("Motion detected")
else:
print("No motion detected")
GPIO.output(Buzzer,GPIO.LOW)
except KeyboardInterrupt:
GPIO.cleanup()
view raw RPi_PIR hosted with ❤ by GitHub

Thank you

Thank you for reading this tutorial and we hope it helps your project development. If you have any technical inquiry, please post at Cytron Technical Forum.

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorial

In-Home Security System using Maker Uno.
Learn to program Arduino using Tinkercad Circuit.
DIY Digital Alarm Clock Using REKA:BIT With Micro:bit
Display Internet Time (NTP) on micro:bit
DIY Interactive Robot Using REKA:BIT With Micro:bit
Tutorials of Cytron Technologies Scroll to Top