The PIR HC-SR501 is a Passive Infrared (PIR) sensor module designed to detect motion through changes in infrared levels emitted by objects in its field of view. It is widely used in security systems, lighting controls, and home automation projects due to its low cost, ease of use, and reliability.
Pin Name | Description |
---|---|
VCC | Power supply (5V – 20V) |
OUT | Digital output signal (High/Low) |
GND | Ground |
// Define the PIR motion sensor pin
const int PIRPin = 2; // Connect PIR sensor's OUT pin to Arduino's pin 2
void setup() {
pinMode(PIRPin, INPUT); // Set the PIR pin as an input
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int motionStatus = digitalRead(PIRPin); // Read the PIR sensor's output
if (motionStatus == HIGH) {
// When motion is detected, print a message
Serial.println("Motion detected!");
// Add your code here to handle the motion detection event
} else {
// When no motion is detected, print a message
Serial.println("No motion detected.");
}
delay(1000); // Wait for 1 second before reading again
}
Q: Can the sensor detect motion through walls? A: No, the PIR sensor cannot detect motion through walls as it relies on detecting infrared radiation from objects.
Q: How can I adjust the range and sensitivity of the sensor? A: The HC-SR501 module typically has two potentiometers to adjust the delay time and sensitivity. Rotate these knobs to increase or decrease the respective settings.
Q: Is it possible to power the sensor with a 3.3V supply? A: The sensor is designed to operate with a supply voltage of 5V to 20V. Using a voltage lower than 5V may result in unreliable or non-functional operation.