The Keyestudio Passive Infrared Sensor (PIR Sensor) is an electronic sensor that detects motion by measuring changes in the infrared light radiating from objects within its field of view. It is commonly used in security systems, lighting controls, and home automation systems to detect the presence of a human or animal.
Pin Number | Name | Description |
---|---|---|
1 | VCC | Connect to 5V power supply |
2 | OUT | Output signal (High/Low) |
3 | GND | Connect to ground |
// Define the PIR sensor pin
const int PIRPin = 2; // Connect PIR sensor output 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 motionState = digitalRead(PIRPin); // Read the state of the PIR sensor
// Check if the sensor detected motion
if (motionState == HIGH) {
// Motion detected
Serial.println("Motion detected!");
// Add your code here to handle motion detection event
} else {
// No motion detected
Serial.println("No motion detected.");
}
// Wait for a short period to avoid flooding the serial output
delay(100);
}
Q: Can the PIR sensor detect motion through glass or walls? A: No, the PIR sensor cannot detect motion through solid barriers like glass or walls.
Q: How can I extend the detection range of the PIR sensor? A: The detection range is fixed and cannot be extended beyond the sensor's specifications.
Q: Is the PIR sensor waterproof? A: No, the Keyestudio PIR sensor is not waterproof and should be used indoors or in a weather-protected area.
Q: How do I adjust the delay time for the sensor? A: Use the delay time adjustment knob on the sensor to set the duration for which the output remains high after detecting motion.
For further assistance, please refer to the Keyestudio PIR Sensor datasheet or contact technical support.