{"id":4129,"date":"2026-05-04T09:00:00","date_gmt":"2026-05-04T09:00:00","guid":{"rendered":"https:\/\/pirhome.com\/?p=3915"},"modified":"2026-05-04T09:00:00","modified_gmt":"2026-05-04T09:00:00","slug":"pir-automatic-trash-can-lid-2","status":"publish","type":"post","link":"https:\/\/www.pirhome.com\/?p=4129","title":{"rendered":"PIR Sensor for Automatic Trash Can Lid"},"content":{"rendered":"<h2>Project Overview<\/h2>\n<p>This project creates a touchless automatic trash can lid that opens when you wave your hand or approach with trash. A PIR sensor detects motion, and a servo motor lifts the lid. After a few seconds, the lid closes automatically.<\/p>\n<p><strong>Difficulty:<\/strong> Beginner<br \/>\n<strong>Estimated time:<\/strong> 2-3 hours<br \/>\n<strong>Estimated cost:<\/strong> $20-30<\/p>\n<h2>How It Works<\/h2>\n<p>A PIR sensor mounted on the trash can lid or front detects motion. When motion is detected, a servo motor rotates to lift the lid. After a set delay, the servo returns to its closed position. An optional button can be added for manual control.<\/p>\n<h2>Materials Needed<\/h2>\n<ul>\n<li>Arduino Nano or Arduino Uno (1)<\/li>\n<li>HC-SR501 PIR sensor (1)<\/li>\n<li>Servo motor (MG995 or SG90)<\/li>\n<li>Trash can with hinged lid<\/li>\n<li>Mounting hardware (brackets, screws)<\/li>\n<li>Jumper wires<\/li>\n<li>Power supply (5V 2A or battery pack)<\/li>\n<li>Project enclosure<\/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>PIR Sensor<\/th>\n<p> VCC<\/th>\n<p> 5V<\/th>\n<th>PIR Sensor<\/th>\n<p> GND<\/th>\n<p> GND<\/th>\n<th>PIR Sensor<\/th>\n<p> OUT<\/th>\n<p> Digital Pin 2<\/th>\n<th>Servo Motor<\/th>\n<p> Red (VCC)<\/th>\n<p> 5V<\/th>\n<th>Servo Motor<\/th>\n<p> Brown (GND)<\/th>\n<p> GND<\/th>\n<th>Servo Motor<\/th>\n<p> Orange (Signal)<\/th>\n<p> Digital Pin 9<\/th>\n<th>Push Button<\/th>\n<p> One side<\/th>\n<p> Digital Pin 3<\/th>\n<th>Push Button<\/th>\n<p> Other side<\/th>\n<p> GND<\/th>\n<\/tbody>\n<p>\u8868<\/p>\n<h2>Arduino Code<\/h2>\n<pre><code>\/\/ Automatic Trash Can Lid Opener\n#include &lt;Servo.h&gt;\n\nServo lidServo;\n\nconst int pirPin = 2;\nconst int servoPin = 9;\nconst int buttonPin = 3;\nconst int ledPin = 13;\n\nconst int closedPos = 0;\nconst int openPos = 90;\n\nunsigned long lastTriggerTime = 0;\nconst unsigned long openDuration = 3000;\n\nbool lidOpen = false;\nbool motionDetected = false;\nbool buttonHeld = false;\n\nvoid setup() {\n  Serial.begin(9600);\n  \n  pinMode(pirPin, INPUT);\n  pinMode(buttonPin, INPUT_PULLUP);\n  pinMode(ledPin, OUTPUT);\n  \n  lidServo.attach(servoPin);\n  lidServo.write(closedPos);\n  digitalWrite(ledPin, LOW);\n  \n  delay(60000);\n}\n\nvoid openLid() {\n  lidServo.write(openPos);\n  lidOpen = true;\n  lastTriggerTime = millis();\n  digitalWrite(ledPin, HIGH);\n}\n\nvoid closeLid() {\n  lidServo.write(closedPos);\n  lidOpen = false;\n  digitalWrite(ledPin, LOW);\n}\n\nvoid loop() {\n  bool motion = digitalRead(pirPin) == HIGH;\n  bool button = digitalRead(buttonPin) == LOW;\n  \n  if (button && !buttonHeld) {\n    buttonHeld = true;\n    if (lidOpen) closeLid();\n    else openLid();\n  }\n  if (!button) buttonHeld = false;\n  \n  if (motion && !motionDetected && !lidOpen) {\n    motionDetected = true;\n    openLid();\n  }\n  \n  if (!motion && motionDetected) motionDetected = false;\n  \n  if (lidOpen && !buttonHeld && (millis() - lastTriggerTime > openDuration)) {\n    closeLid();\n  }\n  \n  delay(100);\n}\n<\/code><\/pre>\n<h2>Installation Steps<\/h2>\n<ol>\n<li>Mount servo on trash can using brackets or epoxy<\/li>\n<li>Attach servo horn to lid with a rigid arm<\/li>\n<li>Position PIR sensor on front of trash can at waist height<\/li>\n<li>Place Arduino in small enclosure attached to the back of the trash can<\/li>\n<li>Power with USB adapter or battery pack<\/li>\n<li>Wave hand in front of sensor to test<\/li>\n<li>Adjust servo positions in code if needed<\/li>\n<\/ol>\n<h2>Project Extensions<\/h2>\n<ul>\n<li>Add battery level indicator<\/li>\n<li>Add voice recognition module for voice activation<\/li>\n<li>Add small fan to spray air freshener when lid opens<\/li>\n<li>Add LED strip inside lid to illuminate when open<\/li>\n<li>Add ultrasonic sensor to detect when trash can is full<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>This automatic trash can lid opener makes kitchen cleanup more hygienic and convenient. With simple materials and basic coding, you can upgrade any standard trash can to a touchless model.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Project Overview This project creates a touchless automatic trash can lid that opens when you wave your hand or approach with trash. A PIR sensor detects motion, and a servo motor lifts the lid. After a few seconds, the lid closes automatically. Difficulty: Beginner Estimated time: 2-3 hours Estimated cost: $20-30 How It Works A [&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-4129","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 for Automatic Trash Can Lid - 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=\"http:\/\/www.pirhome.com\/?p=4129\" \/>\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 for Automatic Trash Can Lid - PIRHOME\" \/>\r\n<meta property=\"og:description\" content=\"Project Overview This project creates a touchless automatic trash can lid that opens when you wave your hand or approach with trash. A PIR sensor detects motion, and a servo motor lifts the lid. After a few seconds, the lid closes automatically. Difficulty: Beginner Estimated time: 2-3 hours Estimated cost: $20-30 How It Works A [&hellip;]\" \/>\r\n<meta property=\"og:url\" content=\"http:\/\/www.pirhome.com\/?p=4129\" \/>\r\n<meta property=\"og:site_name\" content=\"PIRHOME\" \/>\r\n<meta property=\"article:published_time\" content=\"2026-05-04T09: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\":\"http:\\\/\\\/www.pirhome.com\\\/?p=4129#article\",\"isPartOf\":{\"@id\":\"http:\\\/\\\/www.pirhome.com\\\/?p=4129\"},\"author\":{\"name\":\"nic@nicsky.com\",\"@id\":\"http:\\\/\\\/www.pirhome.com\\\/#\\\/schema\\\/person\\\/41049b5236f9c77c9314997d070db3e3\"},\"headline\":\"PIR Sensor for Automatic Trash Can Lid\",\"datePublished\":\"2026-05-04T09:00:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\\\/\\\/www.pirhome.com\\\/?p=4129\"},\"wordCount\":330,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\\\/\\\/www.pirhome.com\\\/#organization\"},\"articleSection\":[\"Projects\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"http:\\\/\\\/www.pirhome.com\\\/?p=4129#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"http:\\\/\\\/www.pirhome.com\\\/?p=4129\",\"url\":\"http:\\\/\\\/www.pirhome.com\\\/?p=4129\",\"name\":\"PIR Sensor for Automatic Trash Can Lid - PIRHOME\",\"isPartOf\":{\"@id\":\"http:\\\/\\\/www.pirhome.com\\\/#website\"},\"datePublished\":\"2026-05-04T09:00:00+00:00\",\"breadcrumb\":{\"@id\":\"http:\\\/\\\/www.pirhome.com\\\/?p=4129#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\\\/\\\/www.pirhome.com\\\/?p=4129\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\\\/\\\/www.pirhome.com\\\/?p=4129#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\\\/\\\/www.pirhome.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PIR Sensor for Automatic Trash Can Lid\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\\\/\\\/www.pirhome.com\\\/#website\",\"url\":\"http:\\\/\\\/www.pirhome.com\\\/\",\"name\":\"PIRHOME\",\"description\":\"PIR &amp; Motion Sensor\",\"publisher\":{\"@id\":\"http:\\\/\\\/www.pirhome.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\\\/\\\/www.pirhome.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\\\/\\\/www.pirhome.com\\\/#organization\",\"name\":\"PIRHOME\",\"url\":\"http:\\\/\\\/www.pirhome.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\\\/\\\/www.pirhome.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.pirhome.com\\\/wp-content\\\/uploads\\\/2026\\\/02\\\/cropped-\u5fae\u4fe1\u56fe\u7247_2026-02-19_222409_472.jpg\",\"contentUrl\":\"https:\\\/\\\/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\":\"http:\\\/\\\/www.pirhome.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"http:\\\/\\\/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\":\"https:\\\/\\\/www.pirhome.com\\\/?author=1\"}]}<\/script>\r\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PIR Sensor for Automatic Trash Can Lid - 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":"http:\/\/www.pirhome.com\/?p=4129","og_locale":"en_US","og_type":"article","og_title":"PIR Sensor for Automatic Trash Can Lid - PIRHOME","og_description":"Project Overview This project creates a touchless automatic trash can lid that opens when you wave your hand or approach with trash. A PIR sensor detects motion, and a servo motor lifts the lid. After a few seconds, the lid closes automatically. Difficulty: Beginner Estimated time: 2-3 hours Estimated cost: $20-30 How It Works A [&hellip;]","og_url":"http:\/\/www.pirhome.com\/?p=4129","og_site_name":"PIRHOME","article_published_time":"2026-05-04T09: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":"http:\/\/www.pirhome.com\/?p=4129#article","isPartOf":{"@id":"http:\/\/www.pirhome.com\/?p=4129"},"author":{"name":"nic@nicsky.com","@id":"http:\/\/www.pirhome.com\/#\/schema\/person\/41049b5236f9c77c9314997d070db3e3"},"headline":"PIR Sensor for Automatic Trash Can Lid","datePublished":"2026-05-04T09:00:00+00:00","mainEntityOfPage":{"@id":"http:\/\/www.pirhome.com\/?p=4129"},"wordCount":330,"commentCount":0,"publisher":{"@id":"http:\/\/www.pirhome.com\/#organization"},"articleSection":["Projects"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["http:\/\/www.pirhome.com\/?p=4129#respond"]}]},{"@type":"WebPage","@id":"http:\/\/www.pirhome.com\/?p=4129","url":"http:\/\/www.pirhome.com\/?p=4129","name":"PIR Sensor for Automatic Trash Can Lid - PIRHOME","isPartOf":{"@id":"http:\/\/www.pirhome.com\/#website"},"datePublished":"2026-05-04T09:00:00+00:00","breadcrumb":{"@id":"http:\/\/www.pirhome.com\/?p=4129#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.pirhome.com\/?p=4129"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/www.pirhome.com\/?p=4129#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/www.pirhome.com\/"},{"@type":"ListItem","position":2,"name":"PIR Sensor for Automatic Trash Can Lid"}]},{"@type":"WebSite","@id":"http:\/\/www.pirhome.com\/#website","url":"http:\/\/www.pirhome.com\/","name":"PIRHOME","description":"PIR &amp; Motion Sensor","publisher":{"@id":"http:\/\/www.pirhome.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.pirhome.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/www.pirhome.com\/#organization","name":"PIRHOME","url":"http:\/\/www.pirhome.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.pirhome.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.pirhome.com\/wp-content\/uploads\/2026\/02\/cropped-\u5fae\u4fe1\u56fe\u7247_2026-02-19_222409_472.jpg","contentUrl":"https:\/\/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":"http:\/\/www.pirhome.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"http:\/\/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":"https:\/\/www.pirhome.com\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/www.pirhome.com\/index.php?rest_route=\/wp\/v2\/posts\/4129","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pirhome.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pirhome.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pirhome.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pirhome.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4129"}],"version-history":[{"count":1,"href":"https:\/\/www.pirhome.com\/index.php?rest_route=\/wp\/v2\/posts\/4129\/revisions"}],"predecessor-version":[{"id":4649,"href":"https:\/\/www.pirhome.com\/index.php?rest_route=\/wp\/v2\/posts\/4129\/revisions\/4649"}],"wp:attachment":[{"href":"https:\/\/www.pirhome.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pirhome.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pirhome.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}