Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Motion-Activated LED with PIR Sensor

View and Edit Project In Cirkit DesignerImage of Arduino UNO Motion-Activated LED with PIR Sensor

Circuit Documentation

Summary

This circuit is designed to detect motion using a PIR motion sensor and indicate the detection by lighting up an LED. The circuit uses an Arduino UNO microcontroller to read the sensor data and control the LED. When motion is detected by the PIR sensor, the Arduino turns on the LED and prints a message to the serial monitor.

Component List

  1. Arduino UNO

    • Description: A microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. LED: Two Pin (red)

    • Description: A red LED with two pins, anode and cathode.
    • Pins: cathode, anode
  3. PIR Motion Sensor (Wokwi Compatible)

    • Description: A passive infrared sensor used to detect motion.
    • Pins: VCC, OUT, GND

Wiring Details

Arduino UNO

LED: Two Pin (red)

PIR Motion Sensor (Wokwi Compatible)

Code Documentation

/*
   PIR sensor tester
*/

int ledPin = 13;                // choose the pin for the LED
int inputPin = 2;               // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status

void setup() {
  pinMode(12, OUTPUT);
  digitalWrite(12, LOW);
  
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare sensor as input

  Serial.begin(9600);
}

void loop() {
  val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin, HIGH);  // turn LED ON
    if (pirState == LOW) {
      // we have just turned on
      Serial.println("Motion detected!");
      // We only want to print on the output change, not state
      pirState = HIGH;
    }
  } else {
    digitalWrite(ledPin, LOW); // turn LED OFF
    if (pirState == HIGH) {
      // we have just turned off
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
      pirState = LOW;
    }
  }
}

This code initializes the PIR sensor and LED, and continuously checks the state of the PIR sensor. When motion is detected, the LED is turned on and a message is printed to the serial monitor. When motion ends, the LED is turned off and another message is printed.