{"id":52313,"date":"2026-11-01T10:50:56","date_gmt":"2026-11-01T10:50:56","guid":{"rendered":"http:\/\/siratek.net\/index.php\/tutorials\/pir-motion-sensor\/"},"modified":"2026-11-01T10:50:56","modified_gmt":"2026-11-01T10:50:56","slug":"pir-motion-sensor","status":"publish","type":"siratek_tutorial","link":"https:\/\/siratek.net\/index.php\/tutorials\/pir-motion-sensor\/","title":{"rendered":"Detecting People with a PIR Sensor"},"content":{"rendered":"<body><p><\/p>\n<h2>What it does<\/h2>\n<p>A passive infrared sensor watches for <strong>changes<\/strong> in the infrared light falling on it. Everything warm glows in the infrared, and when a person moves across the sensor\u2019s view the pattern shifts, which the module reports as a single digital HIGH on one pin.<\/p>\n<p>\u201cPassive\u201d is the important word. It emits nothing and measures nothing; it only notices change. That one fact explains almost all of its behaviour, including the part people find most frustrating: <strong>a person who stands perfectly still disappears.<\/strong> The sensor is not broken. There is no change for it to see.<\/p>\n<p>It is also the easiest sensor in this library to read, because the module does all the work and hands you a HIGH or a LOW.<\/p>\n<h2>Before you begin<\/h2>\n<h3>Required parts and tools<\/h3>\n<ul>\n<li>An Arduino Uno or compatible board.<\/li>\n<li>One PIR motion module. This is Siratek product 2855, the common HC-SR501 type.<\/li>\n<li>Three female-to-male jumper wires.<\/li>\n<\/ul>\n<h3>What is on the board<\/h3>\n<p>Under the white plastic dome is a sensor the size of a shirt button. The dome itself is a <strong>Fresnel lens<\/strong>, moulded into many small facets that divide the view into a fan of separate zones. Movement across the boundary between zones is what the sensor actually detects, which is why walking <strong>across<\/strong> the field triggers it far more reliably than walking straight at it.<\/p>\n<p>On the back of the board:<\/p>\n<ul>\n<li>A <strong>three-pin header<\/strong>.<\/li>\n<li><strong>Two orange-topped trimmers<\/strong>: sensitivity, meaning range, and time delay.<\/li>\n<li>A <strong>yellow jumper<\/strong> with two positions, which sets the retriggering mode.<\/li>\n<li>A voltage regulator, which is why the module takes 5 V but its output is a lower voltage.<\/li>\n<\/ul>\n<h3>Read your own pin order<\/h3>\n<p>The three pins are <code>VCC<\/code>, <code>OUT<\/code> and <code>GND<\/code>, and <strong>the order differs between batches of this module<\/strong>. Some put <code>VCC<\/code> on the left, some on the right.<\/p>\n<p>The silkscreen is usually printed on the board underneath the white dome. The dome lifts off: it is a push fit, not glued. Take it off, read the three labels, put it back.<\/p>\n<p>Guessing here reverses power across the module, so it is worth the thirty seconds.<\/p>\n<h3>The output is about 3.3 V<\/h3>\n<p>The module has its own regulator, and its HIGH is roughly 3.3 V rather than 5 V.<\/p>\n<p>An Uno reads anything above about 3 V as HIGH, so this works. But the margin is small, and it is the reason this sensor is more sensitive than most to a long wire or a poor connection. If a reading seems erratic, measure the <code>OUT<\/code> pin with a meter while you wave at it, rather than assuming the sensor is faulty.<\/p>\n<h3>The two trimmers<\/h3>\n<p>Both turn with a small screwdriver, and both are worth setting deliberately rather than leaving at whatever the factory chose.<\/p>\n<p><strong>Sensitivity<\/strong> sets the range, roughly three to seven metres. Start it at minimum. A sensor at maximum range in a small room triggers on everything, including warm air moving, and feels hopelessly unreliable.<\/p>\n<p><strong>Time delay<\/strong> sets how long <code>OUT<\/code> stays HIGH after a trigger, from a few seconds to several minutes. Start it at minimum too, so you can see each detection separately while testing. Turn it up only when you know what you want.<\/p>\n<p>Which trimmer is which varies by board. Turn one a little, test, and label it with a marker.<\/p>\n<h3>The jumper, which decides what happens during a long event<\/h3>\n<ul>\n<li><strong>Repeat, sometimes marked <code>H<\/code>:<\/strong> while movement continues, the timer keeps restarting, so <code>OUT<\/code> stays HIGH the whole time and goes LOW once the movement stops and the delay runs out.<\/li>\n<li><strong>Single, sometimes marked <code>L<\/code>:<\/strong> <code>OUT<\/code> goes HIGH, stays HIGH for the delay, then goes LOW regardless of whether the movement is still happening, and only then can it trigger again.<\/li>\n<\/ul>\n<p><strong>Repeat is what you want almost always.<\/strong> A light that should stay on while someone is in the room needs it. Single mode is for counting discrete events.<\/p>\n<h3>Give it a minute to settle<\/h3>\n<p>When first powered, the module needs <strong>thirty seconds to a minute<\/strong> to establish what the room normally looks like. During that time it reports nonsense, often a long HIGH.<\/p>\n<p>This is normal and it catches everyone, because the natural thing to do is upload the sketch and stare at the output immediately. Power it, wait a minute, then start testing.<\/p>\n<h2>Pin reference<\/h2>\n<table>\n<thead>\n<tr>\n<th>Pin or label<\/th>\n<th>Connect to<\/th>\n<th>Purpose<\/th>\n<th>Notes<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>VCC<\/code><\/td>\n<td>Uno <code>5V<\/code><\/td>\n<td>Power<\/td>\n<td>4.5 to 20 V; the regulator handles it<\/td>\n<\/tr>\n<tr>\n<td><code>OUT<\/code><\/td>\n<td>Uno <code>D2<\/code><\/td>\n<td>Motion signal<\/td>\n<td>HIGH on detection, around 3.3 V<\/td>\n<\/tr>\n<tr>\n<td><code>GND<\/code><\/td>\n<td>Uno <code>GND<\/code><\/td>\n<td>Ground<\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<figure class=\"siratek-tutorial-figure\"><img decoding=\"async\" src=\"http:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/pir-motion-sensor-wiring.svg\" alt=\"A PIR module with VCC to 5V, GND to ground and OUT to pin 2, showing the two trimmers and the retrigger jumper on the back of the board\" loading=\"lazy\"><figcaption>Three wires, and three settings on the board that matter more than the code.<\/figcaption><\/figure>\n<h2>Wiring steps<\/h2>\n<ol>\n<li>Unplug the USB cable.<\/li>\n<li>Lift the white dome off and read the three pin labels. Put the dome back.<\/li>\n<li><code>GND<\/code> to <code>GND<\/code>.<\/li>\n<li><code>VCC<\/code> to <code>5V<\/code>.<\/li>\n<li><code>OUT<\/code> to <code>D2<\/code>.<\/li>\n<li>Set both trimmers to minimum and the jumper to repeat.<\/li>\n<li>Plug the USB cable back in, then leave it alone for a minute before judging anything.<\/li>\n<\/ol>\n<h2>Software and libraries<\/h2>\n<p>No library is required. The module gives you a plain digital signal, so this is <code>digitalRead()<\/code> and nothing more.<\/p>\n<p>Use plain <code>INPUT<\/code>, not <code>INPUT_PULLUP<\/code>. The module drives the pin both ways, so an internal pull-up would be fighting it.<\/p>\n<h2>Minimal working example<\/h2>\n<pre><code>\/\/ Siratek: reporting motion, printing only when the state changes.\n\nconst int pirPin = 2;\nconst int ledPin = 13;\n\nint lastState = LOW;\n\nvoid setup() {\n  pinMode(pirPin, INPUT);\n  pinMode(ledPin, OUTPUT);\n\n  Serial.begin(9600);\n  Serial.println(\"Siratek: warming up, about a minute.\");\n  delay(60000);\n  Serial.println(\"ready.\");\n}\n\nvoid loop() {\n  int state = digitalRead(pirPin);\n\n  if (state != lastState) {\n    lastState = state;\n    digitalWrite(ledPin, state);\n    Serial.println(state == HIGH ? \"motion\" : \"clear\");\n  }\n}<\/code><\/pre>\n<p>Printing only on a change, rather than every pass, is what makes this readable. A loop that prints the state every time floods the serial monitor with thousands of identical lines and hides the moment you care about.<\/p>\n<p>The onboard LED on pin 13 gives you a response you can see without looking at the laptop, which matters when you are across the room waving at the sensor.<\/p>\n<h3>A light that stays on while someone is there<\/h3>\n<p>The module\u2019s own time delay could do this, but doing it in software gives you a number you can change without a screwdriver.<\/p>\n<pre><code>\/\/ Siratek: hold an output on for a while after the last movement.\n\nconst int pirPin = 2;\nconst int lampPin = 8;\n\nconst unsigned long holdFor = 15000;  \/\/ milliseconds after the last motion\n\nunsigned long lastMotion = 0;\nbool lampOn = false;\n\nvoid setup() {\n  pinMode(pirPin, INPUT);\n  pinMode(lampPin, OUTPUT);\n  Serial.begin(9600);\n  delay(60000);\n  Serial.println(\"Siratek: ready.\");\n}\n\nvoid loop() {\n  if (digitalRead(pirPin) == HIGH) {\n    lastMotion = millis();\n    if (!lampOn) {\n      lampOn = true;\n      digitalWrite(lampPin, HIGH);\n      Serial.println(\"on\");\n    }\n  }\n\n  if (lampOn &amp;&amp; millis() - lastMotion &gt;= holdFor) {\n    lampOn = false;\n    digitalWrite(lampPin, LOW);\n    Serial.println(\"off\");\n  }\n}<\/code><\/pre>\n<p>Set the module\u2019s own delay to minimum when using this, so the two timers do not fight. The hardware reports events; the software decides how long they last.<\/p>\n<h2>Expected result<\/h2>\n<p>After the warm-up, <code>OUT<\/code> goes HIGH when you move in front of the sensor and returns LOW a few seconds after you stop. With the trimmers at minimum you should need to be within a couple of metres.<\/p>\n<p>Wave your hand <strong>across<\/strong> the sensor\u2019s view rather than towards it, and you will see it trigger far more readily. That is the Fresnel lens doing its job.<\/p>\n<h2>Troubleshooting<\/h2>\n<table>\n<thead>\n<tr>\n<th>Symptom<\/th>\n<th>Likely cause<\/th>\n<th>Check or fix<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Triggers constantly at first<\/td>\n<td>Still warming up<\/td>\n<td>Wait a minute after power-up<\/td>\n<\/tr>\n<tr>\n<td>Triggers at random afterwards<\/td>\n<td>Sensitivity too high, or a draught<\/td>\n<td>Lower sensitivity; keep it away from vents and sunlight<\/td>\n<\/tr>\n<tr>\n<td>Never triggers<\/td>\n<td>Power reversed, pin order assumed<\/td>\n<td>Lift the dome and read the labels<\/td>\n<\/tr>\n<tr>\n<td>Stays HIGH for ages<\/td>\n<td>Time delay trimmer<\/td>\n<td>Turn it down<\/td>\n<\/tr>\n<tr>\n<td>One long HIGH instead of separate events<\/td>\n<td>Jumper in repeat, which is usually right<\/td>\n<td>Use single mode only if counting events<\/td>\n<\/tr>\n<tr>\n<td>Misses a person standing still<\/td>\n<td>Working as designed<\/td>\n<td>PIR sees change, not presence<\/td>\n<\/tr>\n<tr>\n<td>Misses someone walking towards it<\/td>\n<td>Fewer zone crossings<\/td>\n<td>Mount it across the path, not along it<\/td>\n<\/tr>\n<tr>\n<td>Erratic over a long wire<\/td>\n<td>Output is only about 3.3 V<\/td>\n<td>Shorten the wire; measure <code>OUT<\/code> with a meter<\/td>\n<\/tr>\n<tr>\n<td>Triggers when a lamp switches on<\/td>\n<td>Infrared from a hot filament<\/td>\n<td>Reposition, or lower sensitivity<\/td>\n<\/tr>\n<tr>\n<td>Works indoors, useless outdoors<\/td>\n<td>Sunlight and moving warm air<\/td>\n<td>PIR is an indoor sensor<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Next steps<\/h2>\n<ul>\n<li><strong>Easier first:<\/strong> <em>Read a Push Button<\/em>, which is the same <code>digitalRead()<\/code> with no settings.<\/li>\n<li><strong>Related products:<\/strong> an active buzzer for an alert, or a relay to switch a real lamp.<\/li>\n<li><strong>Next project:<\/strong> combine it with the relay tutorial for a light that comes on when someone enters, using a low-voltage lamp.<\/li>\n<\/ul>\n<h2>Sources and attribution<\/h2>\n<p>All text, wiring guidance and code in this tutorial are original Siratek work.<\/p>\n<ul>\n<li>HC-SR501 module documentation for the warm-up period, the adjustable range and delay, and the retriggering jumper.<\/li>\n<li>The two trimmers, the jumper and the onboard regulator described here were read from the Siratek product photographs for item 2855.<\/li>\n<\/ul>\n<p>Pin order varies between batches of this module, so this tutorial tells the reader to lift the dome and read their own silkscreen rather than giving a fixed order. Range and delay figures are typical values that depend on the trimmer settings. No third-party tutorial text, diagrams, photographs or code has been reproduced here.<\/p>\n<p><\/p>\n<\/body>","protected":false},"excerpt":{"rendered":"<p>A passive infrared sensor watches for changes in the infrared light falling on it. Everything warm glows in the infrared, and when a person moves across the sensor&#039;s view the pattern shifts, which the module reports as a single digital&#8230;<\/p>\n","protected":false},"featured_media":0,"template":"","siratek_tutorial_level":[],"class_list":["post-52313","siratek_tutorial","type-siratek_tutorial","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Detecting People with a PIR Sensor - siratek<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/siratek.net\/index.php\/tutorials\/pir-motion-sensor\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Detecting People with a PIR Sensor - siratek\" \/>\n<meta property=\"og:description\" content=\"A passive infrared sensor watches for changes in the infrared light falling on it. Everything warm glows in the infrared, and when a person moves across the sensor&#039;s view the pattern shifts, which the module reports as a single digital...\" \/>\n<meta property=\"og:url\" content=\"http:\/\/siratek.net\/index.php\/tutorials\/pir-motion-sensor\/\" \/>\n<meta property=\"og:site_name\" content=\"siratek\" \/>\n<meta property=\"og:image\" content=\"http:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/pir-motion-sensor-wiring.svg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/pir-motion-sensor\\\/\",\"url\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/pir-motion-sensor\\\/\",\"name\":\"Detecting People with a PIR Sensor - siratek\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/siratek.net\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/pir-motion-sensor\\\/#primaryimage\"},\"image\":{\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/pir-motion-sensor\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/siratek.net\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/pir-motion-sensor-wiring.svg\",\"datePublished\":\"2026-11-01T10:50:56+00:00\",\"breadcrumb\":{\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/pir-motion-sensor\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/pir-motion-sensor\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/pir-motion-sensor\\\/#primaryimage\",\"url\":\"https:\\\/\\\/siratek.net\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/pir-motion-sensor-wiring.svg\",\"contentUrl\":\"https:\\\/\\\/siratek.net\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/pir-motion-sensor-wiring.svg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/pir-motion-sensor\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/siratek.net\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tutorials\",\"item\":\"https:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Detecting People with a PIR Sensor\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/siratek.net\\\/#website\",\"url\":\"https:\\\/\\\/siratek.net\\\/\",\"name\":\"siratek\",\"description\":\"Your Best Electronic Retail Shop\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/siratek.net\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Detecting People with a PIR Sensor - siratek","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:\/\/siratek.net\/index.php\/tutorials\/pir-motion-sensor\/","og_locale":"en_US","og_type":"article","og_title":"Detecting People with a PIR Sensor - siratek","og_description":"A passive infrared sensor watches for changes in the infrared light falling on it. Everything warm glows in the infrared, and when a person moves across the sensor&#039;s view the pattern shifts, which the module reports as a single digital...","og_url":"http:\/\/siratek.net\/index.php\/tutorials\/pir-motion-sensor\/","og_site_name":"siratek","og_image":[{"url":"http:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/pir-motion-sensor-wiring.svg","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/siratek.net\/index.php\/tutorials\/pir-motion-sensor\/","url":"http:\/\/siratek.net\/index.php\/tutorials\/pir-motion-sensor\/","name":"Detecting People with a PIR Sensor - siratek","isPartOf":{"@id":"https:\/\/siratek.net\/#website"},"primaryImageOfPage":{"@id":"http:\/\/siratek.net\/index.php\/tutorials\/pir-motion-sensor\/#primaryimage"},"image":{"@id":"http:\/\/siratek.net\/index.php\/tutorials\/pir-motion-sensor\/#primaryimage"},"thumbnailUrl":"http:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/pir-motion-sensor-wiring.svg","datePublished":"2026-11-01T10:50:56+00:00","breadcrumb":{"@id":"http:\/\/siratek.net\/index.php\/tutorials\/pir-motion-sensor\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/siratek.net\/index.php\/tutorials\/pir-motion-sensor\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/siratek.net\/index.php\/tutorials\/pir-motion-sensor\/#primaryimage","url":"https:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/pir-motion-sensor-wiring.svg","contentUrl":"https:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/pir-motion-sensor-wiring.svg"},{"@type":"BreadcrumbList","@id":"http:\/\/siratek.net\/index.php\/tutorials\/pir-motion-sensor\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/siratek.net\/"},{"@type":"ListItem","position":2,"name":"Tutorials","item":"https:\/\/siratek.net\/index.php\/tutorials\/"},{"@type":"ListItem","position":3,"name":"Detecting People with a PIR Sensor"}]},{"@type":"WebSite","@id":"https:\/\/siratek.net\/#website","url":"https:\/\/siratek.net\/","name":"siratek","description":"Your Best Electronic Retail Shop","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/siratek.net\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/siratek_tutorial\/52313","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/siratek_tutorial"}],"about":[{"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/types\/siratek_tutorial"}],"version-history":[{"count":0,"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/siratek_tutorial\/52313\/revisions"}],"wp:attachment":[{"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/media?parent=52313"}],"wp:term":[{"taxonomy":"siratek_tutorial_level","embeddable":true,"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/siratek_tutorial_level?post=52313"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}