PIR Sensor Tutorial

Motion Detection with PIR Sensor

Introduction

Learn how to build a basic motion detector using a Passive Infrared (PIR) sensor. When motion is detected, the Arduino triggers an LED to light up as an alert.

Required Components

Wiring Diagram

PIR Sensor Wiring Diagram

Follow this wiring setup:

Arduino Code


#include 

const int pirPin = 2;    // PIR sensor output pin
const int ledPin = 13;   // LED pin

void setup() {
    pinMode(pirPin, INPUT);
    pinMode(ledPin, OUTPUT);
    Serial.begin(9600);
}

void loop() {
    int motion = digitalRead(pirPin);
    if (motion == HIGH) {
        digitalWrite(ledPin, HIGH);  // Turn on LED
        Serial.println("Motion detected!");
    } else {
        digitalWrite(ledPin, LOW);   // Turn off LED
    }
    delay(100);
}
            

Applications

Conclusion

By following this tutorial, you can use a PIR sensor to create motion detection systems for various projects. Try experimenting with adding sound or notifications!