PIR Sensor
A Passive Infrared (PIR) sensor is a type of electronic sensor that detects motion by measuring changes in infrared radiation levels. It is commonly used in security systems, automatic lighting systems, and other applications where motion detection is required. It's important to note that PIR sensors are sensitive to changes in infrared radiation, but they do not provide any information about the nature or shape of the detected object. They are mainly designed to detect motion and are less effective at detecting stationary objects.
PIR sensors are widely used due to their simplicity, low cost, and energy efficiency. They offer a reliable method for motion detection in various applications, making them popular in both residential and commercial settings.
The features and specifications of the PIR sensor include the following.
Connect the VCC pin of the PIR sensor to the 5V pin on the Arduino.
Connect the GND pin of the PIR sensor to the GND pin on the Arduino.
Connect the OUT pin of the PIR sensor to any digital input pin (pin 2) on the Arduino.
int pirPin = 2; // Pin connected to the OUT pin of the PIR sensor
void setup() {
Serial.begin(9600); // Initialize the serial communication for debugging
pinMode(pirPin, INPUT); // Set the pirPin as an input
}
void loop() {
int motionDetected = digitalRead(pirPin); // Read the state of the PIR sensor
if (motionDetected == HIGH) {
Serial.println("Motion detected!");
// Add your desired actions here when motion is detected
}
delay(100); // Delay between readings
}