PIR Sensor Based Smart Closet Light

Project Overview

This project creates a smart closet light that automatically turns on when you open the closet door. A PIR sensor detects motion inside the closet, and an LED strip illuminates the space. The light turns off after a set period of no motion.

Difficulty: Beginner
Estimated time: 1-2 hours
Estimated cost: $15-25

How It Works

A PIR sensor mounted inside the closet detects motion when you open the door. When motion is detected, an LED strip turns on. After a set period of no motion (e.g., 30 seconds), the lights turn off automatically. An optional door contact sensor can also trigger the light when the door opens.

Materials Needed

  • Arduino Nano or ESP32 (1)
  • AM312 PIR sensor (compact, 3.3V compatible) (1)
  • LED strip (5V, warm white, cut to closet length)
  • MOSFET or relay module (for switching LED strip)
  • Magnetic reed switch (optional, for door detection)
  • Jumper wires
  • Power supply (5V 2A)

Circuit Diagram

Connection Table

VCC

5V

GND

GND

OUT

Digital Pin 2

VCC

5V

GND

MOSFET Drain

Gate

Digital Pin 3

Source

GND

One side

Digital Pin 4

Other side

GND

Arduino Code

// Smart Closet Light with PIR Sensor
const int pirPin = 2;
const int ledPin = 3;
const int doorSensorPin = 4;  // optional

unsigned long lastMotionTime = 0;
const unsigned long lightTimeout = 30000;
bool lightsOn = false;

void setup() {
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(doorSensorPin, INPUT_PULLUP);
  
  digitalWrite(ledPin, LOW);
  
  delay(30000);
}

void turnLightsOn() {
  digitalWrite(ledPin, HIGH);
  lightsOn = true;
  lastMotionTime = millis();
}

void turnLightsOff() {
  digitalWrite(ledPin, LOW);
  lightsOn = false;
}

void loop() {
  bool motion = digitalRead(pirPin) == HIGH;
  bool doorOpen = digitalRead(doorSensorPin) == LOW;
  
  if (motion || doorOpen) {
    if (!lightsOn) {
      turnLightsOn();
    } else {
      lastMotionTime = millis();
    }
  }
  
  if (lightsOn && (millis() - lastMotionTime > lightTimeout)) {
    turnLightsOff();
  }
  
  delay(100);
}

Installation Steps

  1. Assemble the circuit and test on a breadboard.
  2. Mount the LED strip inside the closet along the door frame.
  3. Position the PIR sensor to face the interior of the closet.
  4. If using a reed switch, mount it on the door and frame.
  5. Enclose the Arduino and power supply in a small box inside the closet.
  6. Close the door and open it to test the light activation.

Project Extensions

  • Use an RGB LED strip for color-changing effects
  • Add a potentiometer to adjust light timeout
  • Add a DHT22 to monitor closet humidity (prevent mold)
  • Add Wi-Fi to report when the closet is opened

Conclusion

This smart closet light eliminates the need to fumble for a switch in the dark.

Leave a Reply

Your email address will not be published. Required fields are marked *

Component Pin Arduino Pin
AM312 PIR AM312 PIR AM312 PIR LED Strip (5V) LED Strip MOSFET MOSFET Reed Switch (optional) Reed Switch