{"id":3922,"date":"2026-03-31T01:57:24","date_gmt":"2026-03-31T05:57:24","guid":{"rendered":"https:\/\/pirhome.com\/?p=3919"},"modified":"2026-03-31T01:57:24","modified_gmt":"2026-03-31T05:57:24","slug":"pir-automatic-fan-control","status":"publish","type":"post","link":"http:\/\/www.pirhome.com\/?p=3922","title":{"rendered":"PIR Sensor for Automatic Fan Control"},"content":{"rendered":"<h2>Project Overview<\/h2>\n<p>This project creates an automatic fan control system that turns on a ceiling or desk fan when someone enters a room and turns it off after they leave. It&#8217;s perfect for bathrooms, workshops, or any room where you want ventilation only when occupied.<\/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 detects when someone enters the room. When motion is detected, the system activates a relay that turns on the fan. After a set period of no motion (e.g., 5 minutes), the fan turns off automatically. An optional temperature sensor can also trigger the fan if the room gets too hot.<\/p>\n<h2>Materials Needed<\/h2>\n<ul>\n<li><strong>Arduino Uno<\/strong> or <strong>ESP32<\/strong> (1)<\/li>\n<li><strong>HC-SR501 PIR sensor<\/strong> (1)<\/li>\n<li><strong>Relay module<\/strong> (5V, single channel, rated for fan load)<\/li>\n<li><strong>LED<\/strong> (for status indication)<\/li>\n<li><strong>Resistor<\/strong> (220\u03a9 for LED)<\/li>\n<li><strong>Jumper wires<\/strong><\/li>\n<li><strong>Power supply<\/strong> (5V 1A)<\/li>\n<li><strong>Project enclosure<\/strong><\/li>\n<li><strong>Optional: DHT22 temperature sensor<\/strong><\/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<td>VCC<\/th>\n<td>5V<\/th>\n<th>PIR Sensor<\/th>\n<td>GND<\/th>\n<td>GND<\/th>\n<th>PIR Sensor<\/th>\n<td>OUT<\/th>\n<td>Digital Pin 2<\/th>\n<th>Relay Module<\/th>\n<td>VCC<\/th>\n<td>5V<\/th>\n<th>Relay Module<\/th>\n<td>GND<\/th>\n<td>GND<\/th>\n<th>Relay Module<\/th>\n<td>IN<\/th>\n<td>Digital Pin 3<\/th>\n<th>Status LED<\/th>\n<td>Anode<\/th>\n<td>Digital Pin 13 (through 220\u03a9)<\/th>\n<th>Status LED<\/th>\n<td>Cathode<\/th>\n<td>GND<\/th>\n<th>DHT22 (optional)<\/th>\n<td>DATA<\/th>\n<td>Digital Pin 4<\/th>\n<\/tbody>\n<table>\n<h2>Arduino Code<\/h2>\n<pre><code>\/\/ Automatic Fan Control with PIR\n#include &lt;DHT.h&gt;  \/\/ Include if using temperature sensor\n\nconst int pirPin = 2;\nconst int relayPin = 3;\nconst int ledPin = 13;\n\nunsigned long lastMotionTime = 0;\nconst unsigned long fanOffDelay = 300000; \/\/ 5 minutes\n\nbool fanOn = false;\n\n#ifdef USE_TEMP_SENSOR\n#define DHTTYPE DHT22\nconst int dhtPin = 4;\nDHT dht(dhtPin, DHTTYPE);\nconst float tempThreshold = 28.0; \/\/ Turn on if above 28\u00b0C\n#endif\n\nvoid setup() {\n  Serial.begin(9600);\n  \n  pinMode(pirPin, INPUT);\n  pinMode(relayPin, OUTPUT);\n  pinMode(ledPin, OUTPUT);\n  \n  digitalWrite(relayPin, LOW);\n  digitalWrite(ledPin, LOW);\n  \n  #ifdef USE_TEMP_SENSOR\n  dht.begin();\n  #endif\n  \n  Serial.println(\"Auto Fan Control Ready\");\n  delay(60000); \/\/ PIR warm-up\n}\n\nvoid turnFanOn() {\n  digitalWrite(relayPin, HIGH);\n  digitalWrite(ledPin, HIGH);\n  fanOn = true;\n  lastMotionTime = millis();\n  Serial.println(\"Fan ON\");\n}\n\nvoid turnFanOff() {\n  digitalWrite(relayPin, LOW);\n  digitalWrite(ledPin, LOW);\n  fanOn = false;\n  Serial.println(\"Fan OFF\");\n}\n\nvoid loop() {\n  bool motion = digitalRead(pirPin) == HIGH;\n  \n  #ifdef USE_TEMP_SENSOR\n  float temp = dht.readTemperature();\n  if (!isnan(temp) && temp > tempThreshold) {\n    if (!fanOn) {\n      turnFanOn();\n    }\n  }\n  #endif\n  \n  if (motion) {\n    lastMotionTime = millis();\n    if (!fanOn) {\n      turnFanOn();\n    }\n  }\n  \n  if (fanOn && (millis() - lastMotionTime > fanOffDelay)) {\n    #ifdef USE_TEMP_SENSOR\n    \/\/ Only turn off if temperature is below threshold\n    if (temp &lt;= tempThreshold || isnan(temp)) {\n      turnFanOff();\n    } else {\n      lastMotionTime = millis(); \/\/ Reset timer if still hot\n    }\n    #else\n    turnFanOff();\n    #endif\n  }\n  \n  delay(100);\n}\n<\/code><\/pre>\n<h2>Ceiling Fan Wiring Safety<\/h2>\n<p><strong>Important:<\/strong> Ceiling fans typically operate on 120V\/240V AC. Use a relay rated for the fan&#8217;s current (typically 0.5-1.5A). If you are not experienced with AC wiring, consult an electrician.<\/p>\n<p>For DC fans (e.g., computer fans), the 5V relay can directly control them.<\/p>\n<h2>Installation Steps<\/h2>\n<ol>\n<li><strong>Assemble circuit:<\/strong> Build on breadboard and test.<\/li>\n<li><strong>Connect fan:<\/strong> Wire the fan to the relay (AC wiring requires caution).<\/li>\n<li><strong>Mount PIR sensor:<\/strong> Place sensor at 2m height covering the room.<\/li>\n<li><strong>Enclose electronics:<\/strong> Place Arduino and relay in a safe enclosure.<\/li>\n<li><strong>Power up:<\/strong> Connect power supply.<\/li>\n<li><strong>Test:<\/strong> Walk into room, verify fan turns on. Leave room, wait 5 minutes, verify fan turns off.<\/li>\n<\/ol>\n<h2>Project Extensions<\/h2>\n<ul>\n<li><strong>Speed control:<\/strong> Add PWM control for variable fan speed (requires triac circuit for AC fans).<\/li>\n<li><strong>Window sensor:<\/strong> Add magnetic reed switch to disable fan when window is open.<\/li>\n<li><strong>Humidity sensor:<\/strong> Use DHT22 to turn on fan in bathrooms when humidity rises.<\/li>\n<li><strong>Smart home integration:<\/strong> Add ESP32 to report fan status and allow remote control.<\/li>\n<li><strong>Manual override:<\/strong> Add push button for manual control.<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>This automatic fan control system ensures ventilation only when needed, saving energy and reducing noise when rooms are empty. It&#8217;s perfect for bathrooms, workshops, and home offices.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Project Overview This project creates an automatic fan control system that turns on a ceiling or desk fan when someone enters a room and turns it off after they leave. It&#8217;s perfect for bathrooms, workshops, or any room where you want ventilation only when occupied. 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-3922","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 Fan Control - 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=3922\" \/>\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 Fan Control - PIRHOME\" \/>\r\n<meta property=\"og:description\" content=\"Project Overview This project creates an automatic fan control system that turns on a ceiling or desk fan when someone enters a room and turns it off after they leave. It&#8217;s perfect for bathrooms, workshops, or any room where you want ventilation only when occupied. Difficulty: Beginner Estimated time: 1-2 hours Estimated cost: $15-25 How [&hellip;]\" \/>\r\n<meta property=\"og:url\" content=\"http:\/\/www.pirhome.com\/?p=3922\" \/>\r\n<meta property=\"og:site_name\" content=\"PIRHOME\" \/>\r\n<meta property=\"article:published_time\" content=\"2026-03-31T05:57:24+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=3922#article\",\"isPartOf\":{\"@id\":\"http:\\\/\\\/www.pirhome.com\\\/?p=3922\"},\"author\":{\"name\":\"nic@nicsky.com\",\"@id\":\"http:\\\/\\\/www.pirhome.com\\\/#\\\/schema\\\/person\\\/41049b5236f9c77c9314997d070db3e3\"},\"headline\":\"PIR Sensor for Automatic Fan Control\",\"datePublished\":\"2026-03-31T05:57:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\\\/\\\/www.pirhome.com\\\/?p=3922\"},\"wordCount\":408,\"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=3922#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"http:\\\/\\\/www.pirhome.com\\\/?p=3922\",\"url\":\"http:\\\/\\\/www.pirhome.com\\\/?p=3922\",\"name\":\"PIR Sensor for Automatic Fan Control - PIRHOME\",\"isPartOf\":{\"@id\":\"http:\\\/\\\/www.pirhome.com\\\/#website\"},\"datePublished\":\"2026-03-31T05:57:24+00:00\",\"breadcrumb\":{\"@id\":\"http:\\\/\\\/www.pirhome.com\\\/?p=3922#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\\\/\\\/www.pirhome.com\\\/?p=3922\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\\\/\\\/www.pirhome.com\\\/?p=3922#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\\\/\\\/www.pirhome.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PIR Sensor for Automatic Fan Control\"}]},{\"@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 Automatic Fan Control - 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=3922","og_locale":"en_US","og_type":"article","og_title":"PIR Sensor for Automatic Fan Control - PIRHOME","og_description":"Project Overview This project creates an automatic fan control system that turns on a ceiling or desk fan when someone enters a room and turns it off after they leave. It&#8217;s perfect for bathrooms, workshops, or any room where you want ventilation only when occupied. Difficulty: Beginner Estimated time: 1-2 hours Estimated cost: $15-25 How [&hellip;]","og_url":"http:\/\/www.pirhome.com\/?p=3922","og_site_name":"PIRHOME","article_published_time":"2026-03-31T05:57:24+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=3922#article","isPartOf":{"@id":"http:\/\/www.pirhome.com\/?p=3922"},"author":{"name":"nic@nicsky.com","@id":"http:\/\/www.pirhome.com\/#\/schema\/person\/41049b5236f9c77c9314997d070db3e3"},"headline":"PIR Sensor for Automatic Fan Control","datePublished":"2026-03-31T05:57:24+00:00","mainEntityOfPage":{"@id":"http:\/\/www.pirhome.com\/?p=3922"},"wordCount":408,"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=3922#respond"]}]},{"@type":"WebPage","@id":"http:\/\/www.pirhome.com\/?p=3922","url":"http:\/\/www.pirhome.com\/?p=3922","name":"PIR Sensor for Automatic Fan Control - PIRHOME","isPartOf":{"@id":"http:\/\/www.pirhome.com\/#website"},"datePublished":"2026-03-31T05:57:24+00:00","breadcrumb":{"@id":"http:\/\/www.pirhome.com\/?p=3922#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.pirhome.com\/?p=3922"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/www.pirhome.com\/?p=3922#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/www.pirhome.com\/"},{"@type":"ListItem","position":2,"name":"PIR Sensor for Automatic Fan Control"}]},{"@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\/3922","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=3922"}],"version-history":[{"count":1,"href":"http:\/\/www.pirhome.com\/index.php?rest_route=\/wp\/v2\/posts\/3922\/revisions"}],"predecessor-version":[{"id":4034,"href":"http:\/\/www.pirhome.com\/index.php?rest_route=\/wp\/v2\/posts\/3922\/revisions\/4034"}],"wp:attachment":[{"href":"http:\/\/www.pirhome.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3922"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.pirhome.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3922"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.pirhome.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3922"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}