The HC-SR501 is a passive infrared (PIR) sensor module designed for motion detection in a range of applications such as security systems, automatic lighting, and home automation. It detects the infrared radiation emitted by objects in its field of view, especially warm moving objects like humans and animals.
Pin Number | Name | Description |
---|---|---|
1 | VCC | Power supply input (4.5V to 20V) |
2 | OUT | Output signal (High/Low) |
3 | GND | Ground connection |
// Define the motion sensor pin
const int motionSensorPin = 2; // Connect HC-SR501 OUT pin to Arduino pin 2
void setup() {
pinMode(motionSensorPin, INPUT); // Set the motion sensor pin as an input
Serial.begin(9600); // Start serial communication at 9600 baud rate
}
void loop() {
int motionStatus = digitalRead(motionSensorPin); // Read the sensor value
if (motionStatus == HIGH) {
// Motion detected
Serial.println("Motion detected!");
// Add your code here to handle motion detection event
} else {
// No motion detected
Serial.println("No motion.");
}
delay(1000); // Wait for 1 second before reading again
}
Q: Can the HC-SR501 sensor work outdoors? A: The HC-SR501 can work outdoors but it's not weatherproof. It should be placed in a protective enclosure to prevent damage from the elements.
Q: How can I extend the output signal duration? A: Turn the time delay potentiometer clockwise to increase the duration of the output signal.
Q: What is the range of detection of the HC-SR501? A: The detection range can be up to 7 meters, but it's adjustable via the sensitivity potentiometer.
Q: Is it possible to power the HC-SR501 with a 3.3V supply? A: No, the minimum supply voltage is 4.5V. Using a voltage lower than this may result in unreliable or no operation.