Maker Pro

IoT Motion Sensor using ESP01 & PIR Sensor

July 06, 2022 by AFZAL REHMANI

In this tutorial, we are going to make IoT Motion Sensor using ESP01


Have you ever gone to the places where as you walk or merely take a step in that location, the lights turn on? Do you know how that get possible? Because of motion sensors. Motion sensors are used in these locations. The PIR motion detection sensor is among the most popular and affordable sensors for this use. It is a passive infrared sensor that operates at little power and is typically seen in security equipment and automatic lighting systems. It notifies the user of the movement but does not reveal the person who moved. But, this article is not only about PIR motion sensors, it's about "IoT Motion Sensor using ESP01 & PIR"

PCBWay commits to meeting the needs of its customers from different industries in terms of quality, delivery, cost-effectiveness, and any other demanding requests. As one of the most experienced PCB manufacturers in China. They pride themselves to be your best business partners as well as good friends in every aspect of your PCB needs.

So, here we are converting the PIR motion sensor into an IoT motion sensor. It will send us a notification on our mobile phone when it detects the motion. The distance between the sensor and the phone is not a limitation because everything is internet-based. As long as the internet is there you will get the readings.

Circuit Diagram



#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

const char* ssid = "*****"; //Your WiFI ssid
const char* password = "*****"; //Your WiFi password
boolean PIRstate ; //variable to store PIR state
boolean lastPIRstate = HIGH;
int PIR = 0; //PIR connected to GPIO 0

void setup () {

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED)

  pinMode(PIR, INPUT); //digitalWrite(PIR, LOW);




void loop()

  PIRstate = digitalRead(PIR);  //HIGH when motion detected, else LOW

  if (PIRstate != lastPIRstate)  //Checking if there is any motion

    digitalWrite(LED_BUILTIN, LOW);
    digitalWrite(LED_BUILTIN, HIGH);
    if (WiFi.status() == WL_CONNECTED)  //Check WiFi connection status
      HTTPClient http;  //Declare an object of class HTTPClient

      http.begin("paste the link from ifttt");  //Specify request destination
      http.GET();   //Send the request
      http.end();   //Close connection

    lastPIRstate = PIRstate;


Related Content



You May Also Like