{"id":136752,"date":"2024-04-02T16:28:23","date_gmt":"2024-04-02T16:28:23","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=136752"},"modified":"2024-04-02T16:42:15","modified_gmt":"2024-04-02T16:42:15","slug":"raspberry-pi-pico-motion-pir-arduino","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-motion-pir-arduino\/","title":{"rendered":"Raspberry Pi Pico: Detect Motion using a PIR Sensor (Arduino IDE)"},"content":{"rendered":"\n<p>Learn how to interface a PIR motion sensor with the Raspberry Pi Pico to detect motion in your surroundings. We\u2019ll show you how to wire the sensor to the Pico board and we&#8217;ll write an Arduino sketch to execute a certain task when motion is detected.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/Raspberry-Pi-Pico-PIR-Motion-Sensor-arduino-ide.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Pico: Detect Motion using a PIR Sensor Arduino IDE\" class=\"wp-image-136754\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/Raspberry-Pi-Pico-PIR-Motion-Sensor-arduino-ide.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/Raspberry-Pi-Pico-PIR-Motion-Sensor-arduino-ide.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/Raspberry-Pi-Pico-PIR-Motion-Sensor-arduino-ide.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/Raspberry-Pi-Pico-PIR-Motion-Sensor-arduino-ide.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n<p><strong>Table of Contents:<\/strong><\/p>\n\n\n\n<p>Throughout this tutorial, we&#8217;ll cover the following topics:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"#motion-sensor-intro\" title=\"Introducing the PIR Motion Sensor\">Introducing the PIR Motion Sensor<\/a><\/li>\n\n\n\n<li><a href=\"#Raspberry-Pi-Motion-Sensor-circuit\" title=\"\">Wiring a PIR Motion Sensor to the Pi Pico<\/a><\/li>\n\n\n\n<li><a href=\"#pi-pico-detect-motion-arduino-ide\" title=\"\">PIR Motion Sensor &#8211; Detect Motion (Arduino IDE)<\/a><\/li>\n\n\n\n<li><a href=\"#intro-interrupts\" title=\"\">Introducing Interrupts<\/a>\n<ul class=\"wp-block-list\">\n<li><a href=\"#pi-pico-interrupt-arduino-ide\" title=\"\">Raspberry Pi Pico Setting Up an Interrupt in Arduino IDE<\/a><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><a href=\"#pi-pico-pir-arduino-code\" title=\"\">Raspberry Pi Pico with PIR Motion Sensor Using Interrupts &#8211; Arduino Code<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"prerequisites\">Prerequisites<\/h2>\n\n\n\n<p>You need to install the Raspberry Pi Pico boards on Arduino IDE and you must know how to upload code to the board. Check out the following tutorial first if you haven\u2019t already:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/programming-raspberry-pi-pico-w-arduino-ide\/\">Programming Raspberry Pi Pico with Arduino IDE<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"motion-sensor-intro\">Introducing the PIR Motion Sensor<\/h2>\n\n\n\n<p>A PIR motion sensor detects changes in infrared light in its field of view. This makes it ideal for detecting humans or animals because it will pick up living things (or heat-emitting objects) that move within their range but not inanimate objects. <\/p>\n\n\n\n<p>You can program the Pi to react to changes in infrared light by triggering an event such as turning on a light, sounding an alarm, sending a notification, or any other task. In this tutorial, we&#8217;ll print a message on the console, and we&#8217;ll light up an LED.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/04\/AM312-PIR-Motion-Sensor.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"AM312 PIR Motion Sensor Pinout labeled\" class=\"wp-image-130668\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/04\/AM312-PIR-Motion-Sensor.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/04\/AM312-PIR-Motion-Sensor.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><figcaption class=\"wp-element-caption\">Mini AM312 PIR Motion Sensor<\/figcaption><\/figure><\/div>\n\n\n<p>There are different PIR motion sensor modules, but all act in a similar way. They have a power pin, GND, and data. <\/p>\n\n\n\n<p>The PIR motion sensor outputs a <strong>HIGH <\/strong>signal on the Data pin when it detects movement, or a <strong>LOW <\/strong>signal if it doesn&#8217;t. It only has three pins: <strong>VCC<\/strong>, <strong>GND, <\/strong>and <strong>Data<\/strong>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"1200\" height=\"419\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/PIR-Motion-Sensor-How-it-works.png?resize=1200%2C419&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"How a PIR Motion sensor works\" class=\"wp-image-136745\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/PIR-Motion-Sensor-How-it-works.png?w=2813&amp;quality=100&amp;strip=all&amp;ssl=1 2813w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/PIR-Motion-Sensor-How-it-works.png?resize=300%2C105&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/PIR-Motion-Sensor-How-it-works.png?resize=1024%2C358&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/PIR-Motion-Sensor-How-it-works.png?resize=768%2C268&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/PIR-Motion-Sensor-How-it-works.png?resize=1536%2C537&amp;quality=100&amp;strip=all&amp;ssl=1 1536w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/PIR-Motion-Sensor-How-it-works.png?resize=2048%2C716&amp;quality=100&amp;strip=all&amp;ssl=1 2048w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/PIR-Motion-Sensor-How-it-works.png?w=2400&amp;quality=100&amp;strip=all&amp;ssl=1 2400w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n<p>Some models like the HC-SR501 might have two potentiometers (those two orange potentiometers in the picture below) to adjust the sensitivity and the time delay.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/HC-SR501-Motion-Sensor.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"HC-SR501 PIR Motion Sensor\" class=\"wp-image-136744\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/HC-SR501-Motion-Sensor.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/HC-SR501-Motion-Sensor.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><figcaption class=\"wp-element-caption\">HC-SR501 PIR Motion Sensor<\/figcaption><\/figure><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Sensitivity potentiometer:<\/strong> this adjusts the sensor&#8217;s detection range. Clockwise increases sensitivity, counterclockwise decreases it.<\/li>\n\n\n\n<li><strong>Time delay potentiometer:<\/strong> this controls how long the sensor remains triggered after detecting motion. Clockwise increases the delay, and counterclockwise decreases it.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"Raspberry-Pi-Motion-Sensor-circuit\">Wiring a PIR Motion Sensor to the Pi Pico<\/h2>\n\n\n\n<p>The PIR motion sensor has three pins: VCC, GND, and Data. You should connect VCC to the 3V3 pin (or 5V depending on the model), GND to a GND pin, and the Data pin to a suitable Raspberry Pi Pico GPIO\u2014we&#8217;ll connect it to GPIO 22 (<a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-w-pinout-gpios\/\" title=\"\">take a look at the Raspberry Pi Pico pinout<\/a>).<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/PIR-Motion-Sensor-Raspberry-Pi-Pico-LED-Circuit.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"PIR Motion Sensor with Raspberry Pi Pico Circuit\" class=\"wp-image-136747\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/PIR-Motion-Sensor-Raspberry-Pi-Pico-LED-Circuit.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/PIR-Motion-Sensor-Raspberry-Pi-Pico-LED-Circuit.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>PIR Motion Sensor<\/strong><\/td><td><strong>Raspberry Pi<\/strong><\/td><\/tr><tr><td><strong>Vin\/3v3<\/strong><\/td><td>3.3V or 5V (depending on the model)<\/td><\/tr><tr><td><strong>Data<\/strong><\/td><td>GPIO 22 (or another GPIO of your choice)<\/td><\/tr><tr><td><strong>GND<\/strong><\/td><td>GND<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>We&#8217;ll use the <a href=\"https:\/\/makeradvisor.com\/tools\/mini-hc-sr505-pir-motion-sensor\/\" target=\"_blank\" rel=\"noopener\" title=\"\">AM312 Mini PIR Motion<\/a> sensor because it works with 3.3V, which is perfect for the Raspberry Pi. But you can use any other PIR motion sensor module. The working principle is the same.<\/p>\n\n\n\n<p>We&#8217;ll also connect an LED to GPIO 21 to add visual feedback to our project.<\/p>\n\n\n\n<p>Here&#8217;s a list of components you need for this project:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/raspberry-pi-pico-w\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Raspberry Pi Pico board<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/mini-hc-sr505-pir-motion-sensor\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Mini PIR Motion Sensor<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/3mm-5mm-leds-kit-storage-box\/\" target=\"_blank\" rel=\"noopener\" title=\"\">LED<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/resistors-kits\/\" target=\"_blank\" rel=\"noopener\" title=\"\">220 Ohm resistor<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Breadboard<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Jumper Wires<\/a><\/li>\n<\/ul>\n\n\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"586\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/raspberry-pi-pico-pir-motion-sensor-circuit.png?resize=1024%2C586&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Pico PIR Motion Sensor Circuit\" class=\"wp-image-136755\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/raspberry-pi-pico-pir-motion-sensor-circuit.png?resize=1024%2C586&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/raspberry-pi-pico-pir-motion-sensor-circuit.png?resize=300%2C172&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/raspberry-pi-pico-pir-motion-sensor-circuit.png?resize=768%2C440&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/raspberry-pi-pico-pir-motion-sensor-circuit.png?w=1149&amp;quality=100&amp;strip=all&amp;ssl=1 1149w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"pi-pico-detect-motion-arduino-ide\">PIR Motion Sensor &#8211; Detect Motion<\/h2>\n\n\n\n<p>There are many different ways to write a program to detect motion using a PIR motion sensor. The simplest way is to simply read the state of the PIR sensor as you would read any other <a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-outputs-inputs-arduino\/\" title=\"\">digital input<\/a>.<\/p>\n\n\n\n<p>For example:<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*********\n  Rui Santos &amp; Sara Santos - Random Nerd Tutorials\n  Complete project details at https:\/\/RandomNerdTutorials.com\/raspberry-pi-pico-motion-pir-arduino\/\n\n  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.\n  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n*********\/\n\nint led = 21;                \/\/ the pin that the LED is atteched to\nint sensor = 22;              \/\/ the pin that the sensor is atteched to\nint state = LOW;             \/\/ by default, no motion detected\nint val = 0;                 \/\/ variable to store the sensor status (value)\n\nvoid setup() {\n  pinMode(led, OUTPUT);      \/\/ initalize LED as an output\n  pinMode(sensor, INPUT);    \/\/ initialize sensor as an input\n  Serial.begin(9600);        \/\/ initialize serial\n}\n\nvoid loop(){\n  val = digitalRead(sensor);   \/\/ read sensor value\n  if (val == HIGH) {           \/\/ check if the sensor is HIGH\n    digitalWrite(led, HIGH);   \/\/ turn LED ON\n    delay(100);                \/\/ delay 100 milliseconds \n    \n    if (state == LOW) {\n      Serial.println(&quot;Motion detected!&quot;); \n      state = HIGH;       \/\/ update variable state to HIGH\n    }\n  } \n  else {\n      digitalWrite(led, LOW); \/\/ turn LED OFF\n      delay(200);             \/\/ delay 200 milliseconds \n      \n      if (state == HIGH){\n        Serial.println(&quot;Motion stopped!&quot;);\n        state = LOW;       \/\/ update variable state to LOW\n    }\n  }\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Raspberry-Pi-Pico\/Arduino\/PIR_Detect_Motion.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>However, this might not be the best solution because you need to constantly poll the state of the pin that the sensor is connected to. Usually, the best way to detect the precise moment when the state goes from LOW to HIGH (rising mode) and have a better responsiveness is to use <strong><a href=\"#intro-interrupts\" title=\"\">interrupts<\/a><\/strong>. But, there&#8217;s nothing wrong with using this previous simplified code, if it works good for your project application.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"intro-interrupts\">Introducing Interrupts<\/h2>\n\n\n\n<p>Interrupts are useful for making things happen automatically in microcontroller programs and can help solve timing problems. With interrupts, you don\u2019t need to constantly check the current pin value. When a change is detected, an event is triggered (a function is called\u2014this function is often called an ISR (interrupt service routine).<\/p>\n\n\n\n<p>When an interrupt happens, the processor stops the execution of the main program to execute a task, and then gets back to the main program as shown in the figure below.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"992\" height=\"291\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/03\/interrupt.png?resize=992%2C291&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Interrupts MicroPython Raspberry Pi Pico\" class=\"wp-image-81979\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/03\/interrupt.png?w=992&amp;quality=100&amp;strip=all&amp;ssl=1 992w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/03\/interrupt.png?resize=300%2C88&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/03\/interrupt.png?resize=768%2C225&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 992px) 100vw, 992px\" \/><\/figure><\/div>\n\n\n<p>This is especially useful to trigger an action whenever motion is detected or whenever a pushbutton is pressed without the need for constantly checking its state.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"pi-pico-interrupt-arduino-ide\">Raspberry Pi Pico Setting Up an Interrupt in Arduino IDE<\/h2>\n\n\n\n<p>Before going to the complete example, let&#8217;s take a quick look at how to set up an interrupt on one of the Raspberry Pi Pico GPIOs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">attachInterrupt() Function<\/h3>\n\n\n\n<p>To set an interrupt in the Arduino IDE, you use the <span class=\"rnthl rntliteral\">attachInterrupt()<\/span> function, which accepts as arguments: the GPIO interrupt pin, the name of the function to be executed, and the mode.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>attachInterrupt(digitalPinToInterrupt(GPIO), ISR, mode);<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">GPIO interrupt pin<\/h4>\n\n\n\n<p>The first argument is a GPIO interrupt. You should use <span class=\"rnthl rntliteral\">digitalPinToInterrupt(GPIO)<\/span> to set the actual GPIO as an interrupt pin. For example, if you want to use GPIO 22 as an interrupt, use:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>digitalPinToInterrupt(22)<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">ISR<\/h4>\n\n\n\n<p>The second argument of the <span class=\"rnthl rntliteral\">attachInterrupt()<\/span> function is the name of the function that will be called every time the interrupt is triggered \u2013 the interrupt service routine (ISR).<\/p>\n\n\n\n<p>The ISR function should be as simple as possible, so the processor gets back to the execution of the main program quickly. You should avoid tasks like printing to the serial monitor, delays, and other tasks that might take time.<\/p>\n\n\n\n<p>The best approach is to signal the main code that the interrupt has happened by using a global variable and within the <span class=\"rnthl rntliteral\">loop()<\/span> check and clear that flag, and execute code.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Interrupt modes<\/h3>\n\n\n\n<p>The third argument is the mode and there are 3 different modes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>CHANGE:<\/strong> to trigger the interrupt whenever the pin changes value \u2013 for example from HIGH to LOW or LOW to HIGH;<\/li>\n\n\n\n<li><strong>FALLING:<\/strong> for when the pin goes from HIGH to LOW;<\/li>\n\n\n\n<li><strong>RISING:<\/strong> to trigger when the pin goes from LOW to HIGH.<\/li>\n<\/ul>\n\n\n\n<p>For our example, we&#8217;ll use the RISING mode, because when the PIR motion sensor detects motion, the GPIO it is connected to goes from LOW to HIGH.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"pi-pico-pir-arduino-code\">Raspberry Pi Pico with PIR Motion Sensor Using Interrupts &#8211; Arduino Code<\/h2>\n\n\n\n<p>The following Arduino sketch for the Raspberry Pi Pico monitors a PIR motion sensor connected to GPIO 22. When the PIR sensor detects motion, the Pico turns on an LED for visual feedback and prints &#8220;Motion detected!&#8221; to the console. When the motion stops, it turns off the LED and prints &#8220;Motion stopped&#8221; to the console.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*********\n  Rui Santos &amp; Sara Santos - Random Nerd Tutorials\n  Complete project details at https:\/\/RandomNerdTutorials.com\/raspberry-pi-pico-motion-pir-arduino\/\n\n  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.\n  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n*********\/\n\n#define timeSeconds 10\n\n\/\/ Set GPIOs for LED and PIR Motion Sensor\nconst int led = 21;\nconst int motionSensor = 22;\n\n\/\/ Timer: Auxiliary variables\nunsigned long now = millis();\nunsigned long lastTrigger = 0;\nboolean startTimer = false;\nboolean motion = false;\n\n\/\/ Runs when motion is detected, sets LED HIGH and starts a timer\nvoid detectsMovement() {\n  digitalWrite(led, HIGH);\n  startTimer = true;\n  lastTrigger = millis();\n}\n\nvoid setup() {\n  \/\/ Serial port for debugging purposes\n  Serial.begin(115200);\n  \n  \/\/ PIR Motion Sensor mode INPUT_PULLUP\n  pinMode(motionSensor, INPUT_PULLUP);\n  \/\/ Set motionSensor pin as interrupt, assign interrupt function and set RISING mode\n  attachInterrupt(digitalPinToInterrupt(motionSensor), detectsMovement, RISING);\n\n  \/\/ Set LED to LOW\n  pinMode(led, OUTPUT);\n  digitalWrite(led, LOW);\n}\n\nvoid loop() {\n  \/\/ Current time\n  now = millis();\n  if((digitalRead(led) == HIGH) &amp;&amp; (motion == false)) {\n    Serial.println(&quot;MOTION DETECTED!!!&quot;);\n    motion = true;\n  }\n  \/\/ Turn off the LED after the number of seconds defined in the timeSeconds variable\n  if(startTimer &amp;&amp; (now - lastTrigger &gt; (timeSeconds*1000))) {\n    Serial.println(&quot;Motion stopped...&quot;);\n    digitalWrite(led, LOW);\n    startTimer = false;\n    motion = false;\n  }\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Raspberry-Pi-Pico\/Arduino\/PIR_Detect_Motion_Interrupt.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How Does the Code Work?<\/h3>\n\n\n\n<p>Continue reading to learn how the code works or skip to the <a href=\"#demonstration\" title=\"\">Demonstration <\/a>section.<\/p>\n\n\n\n<p>The previous code detects motion using a PIR motion sensor. When motion is detected, the Pico turns on an LED and starts a timer. If no further motion is detected within a defined time period, it turns off the LED. Let&#8217;s break down the code step by step.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Constants and Variables<\/h4>\n\n\n\n<p>You start by defining several constants and variables that are used throughout the program.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define timeSeconds 10\n\n\/\/ Set GPIOs for LED and PIR Motion Sensor\nconst int led = 21;\nconst int motionSensor = 22;\n\n\/\/ Timer: Auxiliary variables\nunsigned long now = millis();\nunsigned long lastTrigger = 0;\nboolean startTimer = false;\nboolean motion = false;<\/code><\/pre>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">timeSeconds<\/span> defines the duration (in seconds) for which the LED will remain on when motion is detected &#8211; you can change that value.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define timeSeconds 10<\/code><\/pre>\n\n\n\n<p>We also create variables to hold the GPIOs that the LED and sensor are connected to. We&#8217;re connecting the sensor to GPIO 22 and the LED to GPIO 21, but you can use any other <a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-w-pinout-gpios\/\" title=\"\">suitable Raspberry Pi Pico pins<\/a>.<\/p>\n\n\n\n<p>Then, create variables that will allow you to set a timer to turn the LED off after motion is detected.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Timer: Auxiliar variables\nlong now = millis();\nlong lastTrigger = 0;\nboolean startTimer = false;<\/code><\/pre>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">now<\/span> variable holds the current time. The <span class=\"rnthl rntliteral\">lastTrigger<\/span> variable holds the time when the PIR sensor detects motion. The <span class=\"rnthl rntliteral\">startTimer<\/span> is a boolean variable that starts the timer when motion is detected.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">detectsMovement()<\/h4>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">detectsMovement()<\/span> function will be called when motion is detected by the PIR sensor. It turns on the LED, sets the <span class=\"rnthl rntliteral\">startTimer<\/span> flag to <span class=\"rnthl rntliteral\">true<\/span> (so that the time starts counting), and records the current time as the <span class=\"rnthl rntliteral\">lastTrigger<\/span> time.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Runs when motion is detected, sets LED HIGH and starts a timer\nvoid detectsMovement() {\n  digitalWrite(led, HIGH);\n  startTimer = true;\n  lastTrigger = millis();\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">setup()<\/h4>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, start by initializing the Serial port at 115200 baud rate.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.begin(115200);<\/code><\/pre>\n\n\n\n<p>Set the PIR Motion sensor as an <span class=\"rnthl rntliteral\">INPUT_PULLUP<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>pinMode(motionSensor, INPUT_PULLUP);<\/code><\/pre>\n\n\n\n<p>To set the PIR sensor pin as an interrupt, use the <span class=\"rnthl rntliteral\">attachInterrupt()<\/span> function as described earlier.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>attachInterrupt(digitalPinToInterrupt(motionSensor), detectsMovement, RISING);<\/code><\/pre>\n\n\n\n<p>The pin that will detect motion is GPIO 22 and it will call the function <span class=\"rnthl rntliteral\">detectsMovement()<\/span> on <span class=\"rnthl rntliteral\">RISING<\/span> mode.<\/p>\n\n\n\n<p>The LED is an <span class=\"rnthl rntliteral\">OUTPUT<\/span> whose state starts at LOW.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>pinMode(led, OUTPUT);\ndigitalWrite(led, LOW);<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">loop()<\/h4>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">loop()<\/span> function is constantly running over and over again. In every loop, the <span class=\"rnthl rntliteral\">now<\/span> variable is updated with the current time.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>now = millis();<\/code><\/pre>\n\n\n\n<p>Nothing else is done in the <span class=\"rnthl rntliteral\">loop()<\/span>. But, when motion is detected, the <span class=\"rnthl rntliteral\">detectsMovement()<\/span> function is called because we\u2019ve set an interrupt previously on the <span class=\"rnthl rntliteral\">setup()<\/span>.<\/p>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">detectsMovement()<\/span> function, as we&#8217;ve mentioned previously prints a message in the Serial Monitor, turns the LED on, sets the <span class=\"rnthl rntliteral\">startTimer<\/span> boolean variable to <span class=\"rnthl rntliteral\">true<\/span>, and updates the <span class=\"rnthl rntliteral\">lastTrigger<\/span> variable with the current time.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>void IRAM_ATTR detectsMovement() {\n  Serial.println(\"MOTION DETECTED!!!\");\n  digitalWrite(led, HIGH);\n  startTimer = true;\n  lastTrigger = millis();\n}<\/code><\/pre>\n\n\n\n<p>After this step, the code goes back to the <span class=\"rnthl rntliteral\">loop()<\/span>.<\/p>\n\n\n\n<p>This time, the <span class=\"rnthl rntliteral\">startTimer<\/span> variable is true. So, when the time defined in seconds has passed (since motion was detected), the following <span class=\"rnthl rntliteral\">if<\/span> statement will be true.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>if(startTimer &amp;&amp; (now - lastTrigger &gt; (timeSeconds*1000))) {\n  Serial.println(\"Motion stopped...\");\n  digitalWrite(led, LOW);\n  startTimer = false;\n}<\/code><\/pre>\n\n\n\n<p>The &#8220;Motion stopped&#8230;&#8221; message will be printed in the Serial Monitor, the LED is turned off, and the <span class=\"rnthl rntliteral\">startTimer<\/span> variable is set to <span class=\"rnthl rntliteral\">false<\/span>.<\/p>\n\n\n\n<p>And that&#8217;s a summary of how the code works.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Uploading the Code to the Raspberry Pi Pico<\/h2>\n\n\n\n<p>For you to be able to upload code to the Raspberry Pi Pico, it needs to be in bootloader mode.<\/p>\n\n\n\n<p>If the Raspberry Pi is currently running MicroPython firmware, you need to manually put it into bootloader mode. For that, connect the Raspberry Pi Pico to your computer while holding the BOOTSEL button at the same time.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/05\/Raspberry-Pi-Pico-Bottloader-mode.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Pico Bootloader mode\" class=\"wp-image-130903\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/05\/Raspberry-Pi-Pico-Bottloader-mode.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/05\/Raspberry-Pi-Pico-Bottloader-mode.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>For future uploads using Arduino IDE, the board should go automatically into bootloader mode without the need to press the BOOTSEL button.<\/p>\n\n\n\n<p>Now, select your COM port in <strong>Tools <\/strong>&gt; <strong>Port<\/strong>. It may be the case that the COM port is grayed out. If that&#8217;s the case, don&#8217;t worry it will automatically find the port once you hit the upload button.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"595\" height=\"684\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-Pi-Pico-COM-port-not-showing.png?resize=595%2C684&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Pico - COM port not found Arduino IDE\" class=\"wp-image-132415\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-Pi-Pico-COM-port-not-showing.png?w=595&amp;quality=100&amp;strip=all&amp;ssl=1 595w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/Raspberry-Pi-Pico-COM-port-not-showing.png?resize=261%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 261w\" sizes=\"(max-width: 595px) 100vw, 595px\" \/><\/figure><\/div>\n\n\n<p>Upload the code.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"30\" height=\"30\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/05\/arduino-2-0-upload-button.png?resize=30%2C30&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino 2.0 Upload Button\" class=\"wp-image-103678\"\/><\/figure><\/div>\n\n\n<p>You should get a success message.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"595\" height=\"249\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/success-uploading-code-Rpi-pico.png?resize=595%2C249&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Done uploading Arduino IDE Raspberry Pi Pico\" class=\"wp-image-132414\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/success-uploading-code-Rpi-pico.png?w=595&amp;quality=100&amp;strip=all&amp;ssl=1 595w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/06\/success-uploading-code-Rpi-pico.png?resize=300%2C126&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 595px) 100vw, 595px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"demonstration\">Demonstration<\/h2>\n\n\n\n<p>After uploading the code, open the Serial Monitor at a baud rate of 115200. Now, test your setup. Wave your hand in front of the motion sensor. It will print &#8220;MOTION DETECTED!&#8221; in the Serial Monitor.<\/p>\n\n\n\n<p>And the LED will light up for 10 seconds (or whatever value you defined on the <span class=\"rnthl rntliteral\">timeSeconds<\/span> variable).<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/Raspberry-Pi-Pico-PIR-Motion-Sensor-Detect-Motion-Demonstration.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Pico PIR Motion Sensor Detect Motion Demonstration Example\" class=\"wp-image-136749\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/Raspberry-Pi-Pico-PIR-Motion-Sensor-Detect-Motion-Demonstration.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/Raspberry-Pi-Pico-PIR-Motion-Sensor-Detect-Motion-Demonstration.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>After 10 seconds (or the specified time), the LED will turn off and you&#8217;ll get a &#8220;Motion stopped&#8230;&#8221; message.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"601\" height=\"385\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/Pico-PIR-Motion-Arduino-IDE-Serial-Monitor-Test.png?resize=601%2C385&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Detect Motion Raspberry Pi Pico Arduino IDE\" class=\"wp-image-136759\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/Pico-PIR-Motion-Arduino-IDE-Serial-Monitor-Test.png?w=601&amp;quality=100&amp;strip=all&amp;ssl=1 601w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/Pico-PIR-Motion-Arduino-IDE-Serial-Monitor-Test.png?resize=300%2C192&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 601px) 100vw, 601px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In this tutorial, you learned how to use a PIR sensor with the Raspberry Pi Pico to detect motion. You learned how to use interrupts to execute tasks when motion is detected. <\/p>\n\n\n\n<p>To keep things simple, we just turned an LED on and off. In a real-world scenario, you may want to send a notification to your smartphone, send an email, turn on a lamp, send a message via MQTT, or any other task.<\/p>\n\n\n\n<p>We hope you&#8217;ve found this tutorial useful. We have other Raspberry Pi Pico tutorials that you may like:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-analog-inputs-arduino\/\">Raspberry Pi Pico: Read Analog Inputs (Arduino IDE)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-pwm-analogwrite-arduino\/\">Raspberry Pi Pico: Fading an LED using PWM (Arduino IDE)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-dht11-dht22-arduino\/\">Raspberry Pi Pico: DHT11\/DHT22 Temperature<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-ds18b20-arduino\/\">Raspberry Pi Pico: DS18B20 Temperature Sensor (Arduino IDE) \u2013 Single and Multiple<\/a><\/li>\n<\/ul>\n\n\n\n<p><a href=\"https:\/\/randomnerdtutorials.com\/projects-raspberry-pi-pico\/\">Check out all our Raspberry Pi Pico Guides \u00bb<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to interface a PIR motion sensor with the Raspberry Pi Pico to detect motion in your surroundings. We\u2019ll show you how to wire the sensor to the Pico &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Raspberry Pi Pico: Detect Motion using a PIR Sensor (Arduino IDE)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-motion-pir-arduino\/#more-136752\" aria-label=\"Read more about Raspberry Pi Pico: Detect Motion using a PIR Sensor (Arduino IDE)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":136754,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[324,325],"tags":[],"class_list":["post-136752","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-raspberry-pi-pico","category-raspberry-pi-pico-arduino-ide"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/09\/Raspberry-Pi-Pico-PIR-Motion-Sensor-arduino-ide.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/136752","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=136752"}],"version-history":[{"count":14,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/136752\/revisions"}],"predecessor-version":[{"id":151646,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/136752\/revisions\/151646"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/136754"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=136752"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=136752"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=136752"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}