A Passive Infrared (PIR) sensor is an electronic device that measures infrared (IR) light radiating from objects within its field of view. They are most often used in PIR-based motion detectors for applications such as security alarms, automatic lighting control, and energy efficiency systems. PIR sensors detect the movement of heat-emitting bodies, such as humans or animals, by sensing changes in the infrared spectrum.
Pin Number | Name | Description |
---|---|---|
1 | VCC | Power supply input (5V-12V DC) |
2 | OUT | Digital output pin (High/Low) |
3 | GND | Ground connection |
// Define the PIR sensor pin
const int PIRPin = 2; // Connect PIR sensor's OUT pin to digital pin 2
void setup() {
pinMode(PIRPin, INPUT); // Initialize the PIR sensor pin as an input
Serial.begin(9600); // Start serial communication at 9600 baud rate
}
void loop() {
int motionStatus = digitalRead(PIRPin); // Read the PIR sensor's output
if (motionStatus == HIGH) {
// When motion is detected, the output pin goes HIGH
Serial.println("Motion detected!");
// Add code here to handle the motion detection event
} else {
// When no motion is detected, the output pin stays LOW
Serial.println("No motion detected.");
}
delay(100); // Wait for 100 milliseconds before reading again
}
Q: Can the PIR sensor work through glass? A: No, most PIR sensors cannot detect motion through glass as it blocks the infrared waves.
Q: How can I adjust the sensitivity and time delay? A: Many PIR sensors come with potentiometers that allow you to adjust sensitivity and time delay.
Q: Is it possible to power the PIR sensor with a battery? A: Yes, as long as the battery provides a voltage within the sensor's operating range (typically 5V-12V DC).
Q: How long does the PIR sensor need to warm up? A: PIR sensors typically require 20-60 seconds to stabilize after being powered on.
Remember, this documentation is a starting point for working with PIR sensors. Always consult the specific datasheet for your sensor model for the most accurate information.