{"id":4712,"date":"2026-06-26T09:00:00","date_gmt":"2026-06-26T09:00:00","guid":{"rendered":"https:\/\/pirhome.com\/?p=4712"},"modified":"2026-06-26T09:00:00","modified_gmt":"2026-06-26T09:00:00","slug":"pir-smart-closet-light","status":"publish","type":"post","link":"http:\/\/www.pirhome.com\/?p=4712","title":{"rendered":"PIR Sensor Based Smart Closet Light"},"content":{"rendered":"<h2>Project Overview<\/h2>\n<p>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.<\/p>\n<p><strong>Difficulty:<\/strong> Beginner<br \/>\n<strong>Estimated time:<\/strong> 1-2 hours<br \/>\n<strong>Estimated cost:<\/strong> $15-25<\/p>\n<h2>How It Works<\/h2>\n<p>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.<\/p>\n<h2>Materials Needed<\/h2>\n<ul>\n<li>Arduino Nano or ESP32 (1)<\/li>\n<li>AM312 PIR sensor (compact, 3.3V compatible) (1)<\/li>\n<li>LED strip (5V, warm white, cut to closet length)<\/li>\n<li>MOSFET or relay module (for switching LED strip)<\/li>\n<li>Magnetic reed switch (optional, for door detection)<\/li>\n<li>Jumper wires<\/li>\n<li>Power supply (5V 2A)<\/li>\n<\/ul>\n<h2>Circuit Diagram<\/h2>\n<h3>Connection Table<\/h3>\n<table border=\"1\">\n<thead>\n<th>Component<\/th>\n<th>Pin<\/th>\n<th>Arduino Pin<\/th>\n<\/thead>\n<tbody>\n<th>AM312 PIR<\/th>\n<p> VCC<\/th>\n<p> 5V<\/th>\n<th>AM312 PIR<\/th>\n<p> GND<\/th>\n<p> GND<\/th>\n<th>AM312 PIR<\/th>\n<p> OUT<\/th>\n<p> Digital Pin 2<\/th>\n<th>LED Strip (5V)<\/th>\n<p> VCC<\/th>\n<p> 5V<\/th>\n<th>LED Strip<\/th>\n<p> GND<\/th>\n<p> MOSFET Drain<\/th>\n<th>MOSFET<\/th>\n<p> Gate<\/th>\n<p> Digital Pin 3<\/th>\n<th>MOSFET<\/th>\n<p> Source<\/th>\n<p> GND<\/th>\n<th>Reed Switch (optional)<\/th>\n<p> One side<\/th>\n<p> Digital Pin 4<\/th>\n<th>Reed Switch<\/th>\n<p> Other side<\/th>\n<p> GND<\/th>\n<\/tbody>\n<p>\u8868<\/p>\n<h2>Arduino Code<\/h2>\n<pre><code>\/\/ Smart Closet Light with PIR Sensor\nconst int pirPin = 2;\nconst int ledPin = 3;\nconst int doorSensorPin = 4;  \/\/ optional\n\nunsigned long lastMotionTime = 0;\nconst unsigned long lightTimeout = 30000;\nbool lightsOn = false;\n\nvoid setup() {\n  pinMode(pirPin, INPUT);\n  pinMode(ledPin, OUTPUT);\n  pinMode(doorSensorPin, INPUT_PULLUP);\n  \n  digitalWrite(ledPin, LOW);\n  \n  delay(30000);\n}\n\nvoid turnLightsOn() {\n  digitalWrite(ledPin, HIGH);\n  lightsOn = true;\n  lastMotionTime = millis();\n}\n\nvoid turnLightsOff() {\n  digitalWrite(ledPin, LOW);\n  lightsOn = false;\n}\n\nvoid loop() {\n  bool motion = digitalRead(pirPin) == HIGH;\n  bool doorOpen = digitalRead(doorSensorPin) == LOW;\n  \n  if (motion || doorOpen) {\n    if (!lightsOn) {\n      turnLightsOn();\n    } else {\n      lastMotionTime = millis();\n    }\n  }\n  \n  if (lightsOn && (millis() - lastMotionTime > lightTimeout)) {\n    turnLightsOff();\n  }\n  \n  delay(100);\n}\n<\/code><\/pre>\n<h2>Installation Steps<\/h2>\n<ol>\n<li>Assemble the circuit and test on a breadboard.<\/li>\n<li>Mount the LED strip inside the closet along the door frame.<\/li>\n<li>Position the PIR sensor to face the interior of the closet.<\/li>\n<li>If using a reed switch, mount it on the door and frame.<\/li>\n<li>Enclose the Arduino and power supply in a small box inside the closet.<\/li>\n<li>Close the door and open it to test the light activation.<\/li>\n<\/ol>\n<h2>Project Extensions<\/h2>\n<ul>\n<li>Use an RGB LED strip for color-changing effects<\/li>\n<li>Add a potentiometer to adjust light timeout<\/li>\n<li>Add a DHT22 to monitor closet humidity (prevent mold)<\/li>\n<li>Add Wi-Fi to report when the closet is opened<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>This smart closet light eliminates the need to fumble for a switch in the dark.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-4712","post","type-post","status-publish","format-standard","hentry","category-projects"],"blocksy_meta":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\r\n<title>PIR Sensor Based Smart Closet Light - PIRHOME<\/title>\r\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\r\n<link rel=\"canonical\" href=\"https:\/\/www.pirhome.com\/?p=4712\" \/>\r\n<meta property=\"og:locale\" content=\"en_US\" \/>\r\n<meta property=\"og:type\" content=\"article\" \/>\r\n<meta property=\"og:title\" content=\"PIR Sensor Based Smart Closet Light - PIRHOME\" \/>\r\n<meta property=\"og:description\" content=\"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 [&hellip;]\" \/>\r\n<meta property=\"og:url\" content=\"https:\/\/www.pirhome.com\/?p=4712\" \/>\r\n<meta property=\"og:site_name\" content=\"PIRHOME\" \/>\r\n<meta property=\"article:published_time\" content=\"2026-06-26T09:00:00+00:00\" \/>\r\n<meta name=\"author\" content=\"nic@nicsky.com\" \/>\r\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\r\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"nic@nicsky.com\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\r\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.pirhome.com\\\/?p=4712#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pirhome.com\\\/?p=4712\"},\"author\":{\"name\":\"nic@nicsky.com\",\"@id\":\"https:\\\/\\\/www.pirhome.com\\\/#\\\/schema\\\/person\\\/41049b5236f9c77c9314997d070db3e3\"},\"headline\":\"PIR Sensor Based Smart Closet Light\",\"datePublished\":\"2026-06-26T09:00:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pirhome.com\\\/?p=4712\"},\"wordCount\":328,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pirhome.com\\\/#organization\"},\"articleSection\":[\"Projects\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pirhome.com\\\/?p=4712#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pirhome.com\\\/?p=4712\",\"url\":\"https:\\\/\\\/www.pirhome.com\\\/?p=4712\",\"name\":\"PIR Sensor Based Smart Closet Light - PIRHOME\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pirhome.com\\\/#website\"},\"datePublished\":\"2026-06-26T09:00:00+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pirhome.com\\\/?p=4712#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pirhome.com\\\/?p=4712\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pirhome.com\\\/?p=4712#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pirhome.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PIR Sensor Based Smart Closet Light\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pirhome.com\\\/#website\",\"url\":\"https:\\\/\\\/www.pirhome.com\\\/\",\"name\":\"PIRHOME\",\"description\":\"PIR &amp; Motion Sensor\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.pirhome.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pirhome.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.pirhome.com\\\/#organization\",\"name\":\"PIRHOME\",\"url\":\"https:\\\/\\\/www.pirhome.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pirhome.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"http:\\\/\\\/www.pirhome.com\\\/wp-content\\\/uploads\\\/2026\\\/02\\\/cropped-\u5fae\u4fe1\u56fe\u7247_2026-02-19_222409_472.jpg\",\"contentUrl\":\"http:\\\/\\\/www.pirhome.com\\\/wp-content\\\/uploads\\\/2026\\\/02\\\/cropped-\u5fae\u4fe1\u56fe\u7247_2026-02-19_222409_472.jpg\",\"width\":512,\"height\":512,\"caption\":\"PIRHOME\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pirhome.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.pirhome.com\\\/#\\\/schema\\\/person\\\/41049b5236f9c77c9314997d070db3e3\",\"name\":\"nic@nicsky.com\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/271d4eaab48e299e4fce771a8c43c537be3ac77a3115cc7de802a6c8b692d971?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/271d4eaab48e299e4fce771a8c43c537be3ac77a3115cc7de802a6c8b692d971?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/271d4eaab48e299e4fce771a8c43c537be3ac77a3115cc7de802a6c8b692d971?s=96&d=mm&r=g\",\"caption\":\"nic@nicsky.com\"},\"sameAs\":[\"http:\\\/\\\/www.pirhome.com\"],\"url\":\"http:\\\/\\\/www.pirhome.com\\\/?author=1\"}]}<\/script>\r\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PIR Sensor Based Smart Closet Light - PIRHOME","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pirhome.com\/?p=4712","og_locale":"en_US","og_type":"article","og_title":"PIR Sensor Based Smart Closet Light - PIRHOME","og_description":"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 [&hellip;]","og_url":"https:\/\/www.pirhome.com\/?p=4712","og_site_name":"PIRHOME","article_published_time":"2026-06-26T09:00:00+00:00","author":"nic@nicsky.com","twitter_card":"summary_large_image","twitter_misc":{"Written by":"nic@nicsky.com","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pirhome.com\/?p=4712#article","isPartOf":{"@id":"https:\/\/www.pirhome.com\/?p=4712"},"author":{"name":"nic@nicsky.com","@id":"https:\/\/www.pirhome.com\/#\/schema\/person\/41049b5236f9c77c9314997d070db3e3"},"headline":"PIR Sensor Based Smart Closet Light","datePublished":"2026-06-26T09:00:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pirhome.com\/?p=4712"},"wordCount":328,"commentCount":0,"publisher":{"@id":"https:\/\/www.pirhome.com\/#organization"},"articleSection":["Projects"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pirhome.com\/?p=4712#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pirhome.com\/?p=4712","url":"https:\/\/www.pirhome.com\/?p=4712","name":"PIR Sensor Based Smart Closet Light - PIRHOME","isPartOf":{"@id":"https:\/\/www.pirhome.com\/#website"},"datePublished":"2026-06-26T09:00:00+00:00","breadcrumb":{"@id":"https:\/\/www.pirhome.com\/?p=4712#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pirhome.com\/?p=4712"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.pirhome.com\/?p=4712#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pirhome.com\/"},{"@type":"ListItem","position":2,"name":"PIR Sensor Based Smart Closet Light"}]},{"@type":"WebSite","@id":"https:\/\/www.pirhome.com\/#website","url":"https:\/\/www.pirhome.com\/","name":"PIRHOME","description":"PIR &amp; Motion Sensor","publisher":{"@id":"https:\/\/www.pirhome.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pirhome.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pirhome.com\/#organization","name":"PIRHOME","url":"https:\/\/www.pirhome.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pirhome.com\/#\/schema\/logo\/image\/","url":"http:\/\/www.pirhome.com\/wp-content\/uploads\/2026\/02\/cropped-\u5fae\u4fe1\u56fe\u7247_2026-02-19_222409_472.jpg","contentUrl":"http:\/\/www.pirhome.com\/wp-content\/uploads\/2026\/02\/cropped-\u5fae\u4fe1\u56fe\u7247_2026-02-19_222409_472.jpg","width":512,"height":512,"caption":"PIRHOME"},"image":{"@id":"https:\/\/www.pirhome.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.pirhome.com\/#\/schema\/person\/41049b5236f9c77c9314997d070db3e3","name":"nic@nicsky.com","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/271d4eaab48e299e4fce771a8c43c537be3ac77a3115cc7de802a6c8b692d971?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/271d4eaab48e299e4fce771a8c43c537be3ac77a3115cc7de802a6c8b692d971?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/271d4eaab48e299e4fce771a8c43c537be3ac77a3115cc7de802a6c8b692d971?s=96&d=mm&r=g","caption":"nic@nicsky.com"},"sameAs":["http:\/\/www.pirhome.com"],"url":"http:\/\/www.pirhome.com\/?author=1"}]}},"_links":{"self":[{"href":"http:\/\/www.pirhome.com\/index.php?rest_route=\/wp\/v2\/posts\/4712","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.pirhome.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.pirhome.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.pirhome.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.pirhome.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4712"}],"version-history":[{"count":1,"href":"http:\/\/www.pirhome.com\/index.php?rest_route=\/wp\/v2\/posts\/4712\/revisions"}],"predecessor-version":[{"id":4783,"href":"http:\/\/www.pirhome.com\/index.php?rest_route=\/wp\/v2\/posts\/4712\/revisions\/4783"}],"wp:attachment":[{"href":"http:\/\/www.pirhome.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4712"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.pirhome.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4712"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.pirhome.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4712"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}