PIR Motion Sensor

PIR Motion Sensor for Security System

Introduction

This experiment demonstrates how to use a PIR motion sensor with an Arduino to create a simple security system that detects motion.

PIR Motion Sensor

Components Needed

Circuit Setup

  1. Connect the PIR sensor's output to a digital input pin (e.g., D2) on the Arduino.
  2. Connect the LED to a digital output pin using a 220-ohm resistor in series.

The LED will light up when motion is detected.

PIR Motion Sensor Circuit Setup

Code for PIR Motion Sensor

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 sensorValue = digitalRead(pirPin);
  if (sensorValue == HIGH) {
    digitalWrite(ledPin, HIGH);  // Turn on LED when motion is detected
    Serial.println("Motion Detected!");
  } else {
    digitalWrite(ledPin, LOW);   // Turn off LED when no motion
    Serial.println("No Motion");
  }
  delay(500);
}
            

Explanation

The PIR motion sensor detects motion and sends a HIGH signal to the Arduino. This triggers the LED to light up, and a message is printed on the Serial Monitor.

Troubleshooting