2.14 Passive Infrared (PIR) Motion Sensor
The PIR motion sensor detects infrared radiation emitted by moving objects (like humans or animals) within its detection range. It outputs a digital signal (HIGH/LOW), where HIGH indicates motion detection and LOW indicates no motion.
Example Applications:
- Security alarm systems
- Automatic lighting control
- Occupancy detection in smart buildings
- Energy-saving automation
2.14.1 Example Code for Motion Detection System
The PIR sensor outputs a digital signal (HIGH when motion is detected, LOW when no motion). In this example, we trigger visual and auditory alerts when motion is detected (HIGH signal), and return to standby state when no motion is present.
- Hardware Setup:
- Connect the PIR sensor to digital pin
P0
(supports interrupt capability) - Ensure proper orientation (Fresnel lens facing detection area)
- Connect the PIR sensor to digital pin
- Programming Steps (Block-Based):
- Motion Detection: Continuously monitor sensor status (
read INFRARED PROXIMITY SENSOR on P0
) - Alert System:
- If motion detected (HIGH):
- Display "MOTION DETECTED" on screen
- Activate alarm (
TTS Module Play Ringtone alert
) - Turn all RGB LEDs RED (
lampNumber All (-1) displayColor RED
)
- Else (no motion):
- Display "SYSTEM READY" on screen
- Turn off all LEDs (
close All LED
)
- If motion detected (HIGH):
- Motion Detection: Continuously monitor sensor status (
- Key Notes:
- Typical detection range: 5-7 meters (adjustable via sensor potentiometer)
- Warm-up time required (30-60 seconds for stabilization)
- Visual (LED) and auditory (TTS) feedback for both states
- For reduced false triggers, add 2-3 second delay after detection

Figure 2.14.1a: PIR motion detection logic with alarm system