{"id":4139,"date":"2026-05-14T09:00:00","date_gmt":"2026-05-14T09:00:00","guid":{"rendered":"https:\/\/pirhome.com\/?p=3925"},"modified":"2026-05-14T09:00:00","modified_gmt":"2026-05-14T09:00:00","slug":"pir-shed-security-email","status":"publish","type":"post","link":"http:\/\/www.pirhome.com\/?p=4139","title":{"rendered":"PIR Sensor for Shed Security with Email Alerts"},"content":{"rendered":"<h2>Project Overview<\/h2>\n<p>This project creates a simple but effective security system for your shed, garage, or workshop. When motion is detected, the system sends an email alert to your phone or computer. It can also trigger a siren or flash lights as a deterrent.<\/p>\n<p><strong>Difficulty:<\/strong> Intermediate<br \/>\n<strong>Estimated time:<\/strong> 2 hours<br \/>\n<strong>Estimated cost:<\/strong> $25-35<\/p>\n<h2>How It Works<\/h2>\n<p>A PIR sensor monitors the shed interior. When motion is detected, the ESP32 sends an email via SMTP to your email address. An optional siren and strobe light can also be activated. The system includes a cooldown timer to prevent multiple emails for the same event.<\/p>\n<h2>Materials Needed<\/h2>\n<ul>\n<li>ESP32 (1)<\/li>\n<li>HC-SR501 PIR sensor (1)<\/li>\n<li>Buzzer or siren (optional)<\/li>\n<li>LED or strobe light (optional)<\/li>\n<li>Relay module (for siren\/light)<\/li>\n<li>Power supply (5V 2A) or battery with solar charger<\/li>\n<li>Weatherproof enclosure<\/li>\n<li>Jumper wires<\/li>\n<\/ul>\n<h2>Email Setup (Gmail)<\/h2>\n<ol>\n<li>Enable 2-factor authentication on your Google account<\/li>\n<li>Go to Security \u2192 App Passwords<\/li>\n<li>Select &#8220;Mail&#8221; and &#8220;Other&#8221; (name it &#8220;ESP32 Security&#8221;)<\/li>\n<li>Copy the 16-character password<\/li>\n<\/ol>\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>ESP32 Pin<\/th>\n<\/thead>\n<tbody>\n<th>PIR Sensor<\/th>\n<p> VCC<\/th>\n<p> 3.3V<\/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> GPIO 4<\/th>\n<th>Relay (Siren)<\/th>\n<p> IN<\/th>\n<p> GPIO 5<\/th>\n<th>Status LED<\/th>\n<p> Anode<\/th>\n<p> GPIO 2<\/th>\n<\/tbody>\n<p>\u8868<\/p>\n<h2>Arduino Code<\/h2>\n<pre><code>\/\/ Shed Security with Email Alerts\n#include &lt;WiFi.h&gt;\n#include &lt;ESP_Mail_Client.h&gt;\n\nconst char* ssid = \"YourWiFiSSID\";\nconst char* password = \"YourWiFiPassword\";\n\nconst char* smtp_server = \"smtp.gmail.com\";\nconst int smtp_port = 587;\nconst char* sender_email = \"your_email@gmail.com\";\nconst char* sender_password = \"your_app_password\";\nconst char* recipient_email = \"recipient@example.com\";\n\nconst int pirPin = 4;\nconst int sirenPin = 5;\nconst int ledPin = 2;\n\nunsigned long lastAlertTime = 0;\nconst unsigned long alertCooldown = 600000;\nbool alertActive = false;\n\nvoid setup() {\n  Serial.begin(115200);\n  \n  pinMode(pirPin, INPUT);\n  pinMode(sirenPin, OUTPUT);\n  pinMode(ledPin, OUTPUT);\n  digitalWrite(sirenPin, LOW);\n  digitalWrite(ledPin, LOW);\n  \n  WiFi.begin(ssid, password);\n  while (WiFi.status() != WL_CONNECTED) delay(500);\n  \n  delay(60000);\n}\n\nvoid sendEmailAlert() {\n  if (WiFi.status() != WL_CONNECTED) return;\n  \n  ESP_Mail_Session session;\n  session.server.host_name = smtp_server;\n  session.server.port = smtp_port;\n  session.login.email = sender_email;\n  session.login.password = sender_password;\n  \n  SMTP_Message message;\n  message.sender.name = \"Shed Security\";\n  message.sender.email = sender_email;\n  message.subject = \"SECURITY ALERT: Motion Detected in Shed\";\n  message.addRecipient(\"Recipient\", recipient_email);\n  \n  String textMsg = \"Motion was detected in your shed.\\nPlease check the property immediately.\";\n  message.text.content = textMsg.c_str();\n  \n  MailClient.sendMail(&session, &message);\n}\n\nvoid activateAlarm() {\n  alertActive = true;\n  digitalWrite(ledPin, HIGH);\n  digitalWrite(sirenPin, HIGH);\n  delay(5000);\n  digitalWrite(sirenPin, LOW);\n  digitalWrite(ledPin, LOW);\n  alertActive = false;\n}\n\nvoid loop() {\n  bool motion = digitalRead(pirPin) == HIGH;\n  \n  if (motion && (millis() - lastAlertTime > alertCooldown)) {\n    lastAlertTime = millis();\n    sendEmailAlert();\n    activateAlarm();\n    delay(5000);\n  }\n  \n  delay(100);\n}\n<\/code><\/pre>\n<h2>Battery-Powered Version with p<\/h2>\n<pre><code>#include &lt;esp_sleep.h&gt;\n\nRTC_DATA_ATTR unsigned long lastAlertTime = 0;\n\nvoid setup() {\n  esp_sleep_enable_ext0_wakeup((gpio_num_t)pirPin, 1);\n  \n  if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_EXT0) {\n    if (millis() - lastAlertTime > alertCooldown) {\n      lastAlertTime = millis();\n      WiFi.begin(ssid, password);\n      int attempts = 0;\n      while (WiFi.status() != WL_CONNECTED && attempts < 20) {\n        delay(500);\n        attempts++;\n      }\n      if (WiFi.status() == WL_CONNECTED) {\n        sendEmailAlert();\n        WiFi.disconnect();\n      }\n      for (int i = 0; i < 10; i++) {\n        digitalWrite(ledPin, HIGH);\n        delay(200);\n        digitalWrite(ledPin, LOW);\n        delay(200);\n      }\n    }\n  }\n  \n  esp_deep_sleep_start();\n}\n<\/code><\/pre>\n<h2>Installation Steps<\/h2>\n<ol>\n<li>Assemble circuit and test with USB power<\/li>\n<li>Configure Gmail App Password<\/li>\n<li>Update code with Wi-Fi credentials and email info<\/li>\n<li>Upload to ESP32 and test with hand motion<\/li>\n<li>Mount PIR sensor in shed corner at 2m height<\/li>\n<li>Enclose electronics in weatherproof box<\/li>\n<li>Enter shed to test email alert<\/li>\n<\/ol>\n<h2>Project Extensions<\/h2>\n<ul>\n<li>Add ESP32-CAM to capture and email images<\/li>\n<li>Add GSM module for cellular alerts<\/li>\n<li>Add door\/window contact sensors<\/li>\n<li>Create web dashboard to view alert history<\/li>\n<li>Integrate with Home Assistant via MQTT<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>This shed security system provides peace of mind by alerting you immediately when someone enters, allowing you to respond quickly even when away from home.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Project Overview This project creates a simple but effective security system for your shed, garage, or workshop. When motion is detected, the system sends an email alert to your phone or computer. It can also trigger a siren or flash lights as a deterrent. Difficulty: Intermediate Estimated time: 2 hours Estimated cost: $25-35 How It [&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-4139","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 Shed Security with Email Alerts - 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=4139\" \/>\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 Shed Security with Email Alerts - PIRHOME\" \/>\r\n<meta property=\"og:description\" content=\"Project Overview This project creates a simple but effective security system for your shed, garage, or workshop. When motion is detected, the system sends an email alert to your phone or computer. It can also trigger a siren or flash lights as a deterrent. Difficulty: Intermediate Estimated time: 2 hours Estimated cost: $25-35 How It [&hellip;]\" \/>\r\n<meta property=\"og:url\" content=\"http:\/\/www.pirhome.com\/?p=4139\" \/>\r\n<meta property=\"og:site_name\" content=\"PIRHOME\" \/>\r\n<meta property=\"article:published_time\" content=\"2026-05-14T09: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=\"3 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=4139#article\",\"isPartOf\":{\"@id\":\"http:\\\/\\\/www.pirhome.com\\\/?p=4139\"},\"author\":{\"name\":\"nic@nicsky.com\",\"@id\":\"http:\\\/\\\/www.pirhome.com\\\/#\\\/schema\\\/person\\\/41049b5236f9c77c9314997d070db3e3\"},\"headline\":\"PIR Sensor for Shed Security with Email Alerts\",\"datePublished\":\"2026-05-14T09:00:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\\\/\\\/www.pirhome.com\\\/?p=4139\"},\"wordCount\":312,\"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=4139#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"http:\\\/\\\/www.pirhome.com\\\/?p=4139\",\"url\":\"http:\\\/\\\/www.pirhome.com\\\/?p=4139\",\"name\":\"PIR Sensor for Shed Security with Email Alerts - PIRHOME\",\"isPartOf\":{\"@id\":\"http:\\\/\\\/www.pirhome.com\\\/#website\"},\"datePublished\":\"2026-05-14T09:00:00+00:00\",\"breadcrumb\":{\"@id\":\"http:\\\/\\\/www.pirhome.com\\\/?p=4139#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\\\/\\\/www.pirhome.com\\\/?p=4139\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\\\/\\\/www.pirhome.com\\\/?p=4139#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\\\/\\\/www.pirhome.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PIR Sensor for Shed Security with Email Alerts\"}]},{\"@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\":\"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\":\"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\":\"http:\\\/\\\/www.pirhome.com\\\/?author=1\"}]}<\/script>\r\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PIR Sensor for Shed Security with Email Alerts - 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=4139","og_locale":"en_US","og_type":"article","og_title":"PIR Sensor for Shed Security with Email Alerts - PIRHOME","og_description":"Project Overview This project creates a simple but effective security system for your shed, garage, or workshop. When motion is detected, the system sends an email alert to your phone or computer. It can also trigger a siren or flash lights as a deterrent. Difficulty: Intermediate Estimated time: 2 hours Estimated cost: $25-35 How It [&hellip;]","og_url":"http:\/\/www.pirhome.com\/?p=4139","og_site_name":"PIRHOME","article_published_time":"2026-05-14T09:00:00+00:00","author":"nic@nicsky.com","twitter_card":"summary_large_image","twitter_misc":{"Written by":"nic@nicsky.com","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/www.pirhome.com\/?p=4139#article","isPartOf":{"@id":"http:\/\/www.pirhome.com\/?p=4139"},"author":{"name":"nic@nicsky.com","@id":"http:\/\/www.pirhome.com\/#\/schema\/person\/41049b5236f9c77c9314997d070db3e3"},"headline":"PIR Sensor for Shed Security with Email Alerts","datePublished":"2026-05-14T09:00:00+00:00","mainEntityOfPage":{"@id":"http:\/\/www.pirhome.com\/?p=4139"},"wordCount":312,"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=4139#respond"]}]},{"@type":"WebPage","@id":"http:\/\/www.pirhome.com\/?p=4139","url":"http:\/\/www.pirhome.com\/?p=4139","name":"PIR Sensor for Shed Security with Email Alerts - PIRHOME","isPartOf":{"@id":"http:\/\/www.pirhome.com\/#website"},"datePublished":"2026-05-14T09:00:00+00:00","breadcrumb":{"@id":"http:\/\/www.pirhome.com\/?p=4139#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.pirhome.com\/?p=4139"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/www.pirhome.com\/?p=4139#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/www.pirhome.com\/"},{"@type":"ListItem","position":2,"name":"PIR Sensor for Shed Security with Email Alerts"}]},{"@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":"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":"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":"http:\/\/www.pirhome.com\/?author=1"}]}},"_links":{"self":[{"href":"http:\/\/www.pirhome.com\/index.php?rest_route=\/wp\/v2\/posts\/4139","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=4139"}],"version-history":[{"count":1,"href":"http:\/\/www.pirhome.com\/index.php?rest_route=\/wp\/v2\/posts\/4139\/revisions"}],"predecessor-version":[{"id":4664,"href":"http:\/\/www.pirhome.com\/index.php?rest_route=\/wp\/v2\/posts\/4139\/revisions\/4664"}],"wp:attachment":[{"href":"http:\/\/www.pirhome.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.pirhome.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4139"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.pirhome.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}