Introduction
This experiment demonstrates how to use a Passive Infrared (PIR) motion sensor to detect human movement and trigger an action.
Components Needed
- PIR Motion Sensor
- Arduino
- LED (optional for visualization)
- Jumper Wires
Circuit Setup
- Connect the PIR sensor’s VCC and GND pins to the 5V and GND on the Arduino.
- Connect the output pin of the PIR sensor to a digital input pin (e.g., D2) on the Arduino.
The PIR sensor detects motion in its field of view and sends a signal to the Arduino when movement is detected.
Code for PIR Motion Detection
Upload the following code to your Arduino to detect motion:
const int pirPin = 2;
const int ledPin = 13;
void setup() {
pinMode(pirPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int motionDetected = digitalRead(pirPin);
if (motionDetected == HIGH) {
digitalWrite(ledPin, HIGH); // Turn on LED if motion is detected
Serial.println("Motion Detected!");
} else {
digitalWrite(ledPin, LOW); // Turn off LED if no motion
Serial.println("No Motion");
}
delay(500);
}
Explanation
The PIR sensor detects infrared radiation from moving objects, triggering a response (e.g., turning on an LED) when motion is detected.
Troubleshooting
- Ensure the PIR sensor is placed in an area where it can detect motion.
- If the sensor isn't detecting motion, check for power issues or wiring problems.