The HC-SR501 PIR (Passive Infrared) motion sensor is a versatile and low-cost sensor that detects motion based on the infrared radiation emitted by objects in its field of view. It is widely used in various applications such as security systems, lighting control, and home automation projects. The sensor is designed to be easily integrated into circuits and can be used with microcontrollers like the Arduino UNO.
Pin Number | Name | Description |
---|---|---|
1 | VCC | Power supply input (4.5V to 20V) |
2 | OUT | Output signal (High/Low) |
3 | GND | Ground connection |
// HC-SR501 Motion Sensor Example Code
int ledPin = 13; // LED connected to digital pin 13
int sensorPin = 2; // HC-SR501 OUT pin connected to digital pin 2
int sensorState = LOW; // Variable for reading the sensor status
void setup() {
pinMode(ledPin, OUTPUT); // Initialize the LED pin as an output
pinMode(sensorPin, INPUT); // Initialize the sensor pin as an input
Serial.begin(9600); // Start serial communication at 9600 baud
}
void loop() {
sensorState = digitalRead(sensorPin); // Read the state of the sensor
if (sensorState == HIGH) { // Check if the sensor is triggered
digitalWrite(ledPin, HIGH); // Turn LED on
Serial.println("Motion detected!");
delay(1000); // Wait for 1 second
} else {
digitalWrite(ledPin, LOW); // Turn LED off
Serial.println("Motion ended.");
delay(1000); // Wait for 1 second
}
}
Q: Can the HC-SR501 sensor work with battery power? A: Yes, as long as the battery voltage is within the 4.5V to 20V range.
Q: How can I adjust the sensor's sensitivity? A: Turn the sensitivity adjustment potentiometer on the sensor module.
Q: Is it possible to use the HC-SR501 sensor outdoors? A: The sensor is not weatherproof, so it is not recommended for outdoor use without proper housing.
Q: How do I know if the sensor has stabilized after power-up? A: The sensor typically takes up to 60 seconds to stabilize. During this time, the output may trigger randomly. After this period, the sensor should operate normally.