🟦 1. Introduction
A PIR (Passive Infrared) sensor is used to detect human motion. It senses infrared radiation emitted by the human body. This sensor is widely used in security systems, automatic lighting, and smart home applications.
🟦 2. Components
- Raspberry Pi
- PIR Motion Sensor (HC-SR501)
- LED
- 220Ω Resistor
- Breadboard
- Jumper Wires
🟦 3. Circuit and Connections
| Raspberry Pi Pinout Diagram |
| Pinout Diagram of PIR Motion Sensor |
🔌 Connections:
- VCC → 5V (Pin 2)
- GND → GND (Pin 6)
- OUT → GPIO17 (Pin 11)
- LED + → GPIO18 (Pin 12)
- LED – → GND (via 220Ω resistor)
🟦 4. Detailed Step By Step Circuit Working
- PIR sensor detects infrared radiation from human body
- When motion is detected → output becomes HIGH
- When no motion → output LOW
- Raspberry Pi reads signal via GPIO17
- If motion detected → LED turns ON
- If no motion → LED OFF
🟦 5. Libraries to be Included
import RPi.GPIO as GPIO
import time
🟦 6. Code
import RPi.GPIO as GPIO
import time
pir = 17
led = 18
GPIO.setmode(GPIO.BCM)
GPIO.setup(pir, GPIO.IN)
GPIO.setup(led, GPIO.OUT)
while True:
if GPIO.input(pir):
GPIO.output(led, True)
print("Motion Detected")
else:
GPIO.output(led, False)
time.sleep(0.1)
🟦 7. Detailed Step By Step Code Working
- Import GPIO and time libraries
- Assign PIR sensor to GPIO17
- Assign LED to GPIO18
- Set GPIO mode to BCM
- Set PIR as input
- Set LED as output
- Read PIR sensor value
- If HIGH → motion detected → LED ON
- Else → LED OFF
- Add delay for stability
🟦 8. Tips
- Wait 30–60 seconds for PIR sensor calibration
- Adjust sensitivity using onboard potentiometer
- Avoid placing near heat sources
- Use proper delay to avoid false triggering
🟦 9. Uses
- Motion detection alarms
- Automatic lights
- Smart home systems
- Security surveillance
🟦 10. Conclusion
PIR sensors are essential for motion detection applications. This simple project helps you build smart automation systems using Raspberry Pi.