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 commonly used in motion detection systems, such as alarm systems, automatic lighting controls, and occupancy sensors in smart buildings.
Pin Number | Name | Description |
---|---|---|
1 | VCC | Power supply (3.3V to 5V) |
2 | OUT | Digital output signal (High/Low) |
3 | GND | Ground connection |
// Define the PIR sensor pin
int pirPin = 2; // Digital pin connected to the PIR sensor's output
// Variable for the PIR sensor status
int pirState = LOW;
void setup() {
pinMode(pirPin, INPUT); // Initialize the PIR sensor pin as an input
Serial.begin(9600); // Start the serial communication
}
void loop() {
pirState = digitalRead(pirPin); // Read the state of the PIR sensor
if (pirState == HIGH) {
// Motion detected
Serial.println("Motion detected!");
// Add custom code here to handle motion detection
} else {
// No motion detected
Serial.println("No motion detected.");
}
delay(1000); // Wait for 1 second before reading again
}
Q: Can the PIR sensor work through glass? A: No, PIR sensors typically cannot detect motion through glass as it blocks the infrared radiation.
Q: How long does the PIR sensor output stay high after detecting motion? A: This can vary between models, but it is often adjustable with a potentiometer or set by the manufacturer.
Q: Is it possible to adjust the detection range and angle? A: The detection angle is fixed by the sensor's design, but some models allow for range adjustment via a potentiometer.
Q: Can the PIR sensor be used outdoors? A: While some PIR sensors are designed for outdoor use, they must be adequately protected from the elements and may require a different setup to avoid false triggers.