PIR Sensor IC and Espressif ESP8266 ESP-01

In this DIY project, we will learn how to design a motion sensor. In Addition, it will give notifications to your phone when any movement is detected at the sensor installed zone. The whole setup works over the internet so it’s limitless.

Components Used In Making This Project


  • Espressif ESP8266 ESP-01

It is a Wi-Fi module manufactured by Espressif with ESP8266 integrated chip. It is one of the cheapest Wi-Fi modules used in multiple IoT projects.  This board operates on 3.3V dc.

  • PIR Motion Sensor

It is basically used to detect movements with approx 10m from the sensor. However, the actual detection range is between 5m to 12m. PIR Motion Sensor is developed by a pyroelectric sensor. It is very beneficial for various projects

  • ESP8266 Serial Adaptor

It is one of the most important components in every hardware hacker’s toolbox. The ESP8266 was specifically designed to use with Wi-Fi adapters. We need this device to gain 3.3V TTL into a Wi-Fi connection


  • Arduino IDE

It is an open-source software developed by Arduino. It simplifies to write codes and upload it to the board.  In addition, it runs on all major platforms like Windows, Mac, and Linux. Its platform is based on java and other open-source software.

  • IFTTT Maker Service

It enhances our DIY projects by integrating IFTTT services. Various applets can be created in order to receive web requests. If you really want to make own custom applets then do check the IFTTT platform

The basic Working Principle

  • Firstly we need to connect the PIR Motion Sensor to one of the GPIO pins of Espressif ESP8266 ESP-01.
  • Whenever any movements get detected by the PIR Motion Sensor. The output of the PIR changes its states which will immediately get detected by the Espressif ESP8266 ESP-01 controller chip.
  • We need to program the Espressif ESP8266 ESP-01 in such a way that it generates HTTP GET requests to the IFTTT webhooks applets.
  • As soon as the ESP8266 ESP-01 controller chip generates an HTTP GET request then it will reflect notifications on your mobile device.

Pin Configurations  And Diagrams

Circuit Diagrams

Common steps:

  • All Gnd need to be connected together.
  • Give 3.3Volts to the VCC pin of ESP8266 ESP-01 and PIR HC-SR501.
  • Connect GPIO 0 pin of ESP8266 ESP-01 to the OUT pin of PIR HC-SR501.

Creation Of IFTTT Applet

  • All you need to create an IFTTT account by visiting their website. www.ifttt.com.
  • Log in with your credentials and create your custom Applet in IFTTT.
  • After that, download and install IFTTT app from Google store or app store to your mobile device.
  • Lastly, after downloading login with your credentials and give all the permission the app needs.

Step1:  Select the create option from the drop-down menu.

Step 2:  Next click on +This button.

Step 3:  Now you need to search for webhooks, and click on it.

Step 4: Now from “choose trigger” just tap on the “Receive a web request”.

Step 5: Type a name for the event, I entered “iot_Motion_sensor”. now click on Create Trigger.

Step 6: Now simply tap on +That button.

Step7: It’s the time to choose active service, search notification and click on it.

Step 8: Now choose which options you want. There are 2 types of notifications simple and rich. However, I choose a simple one.

Step 9: Write the message need want when motion is detected. It is customizable you can give time also.

Step 10: Tap on the Finish button.

Step 11: You are done creating an applet successfully.

Receiving HTTP GET URL request

Step1: Click on your profile pic and choose My services from drop down menu.

Step 2: Select Webhooks

Step 3: Tap on Documentation.

Step 4: follow the things mentioned in the screenshot.

The detailed code using C/C++

#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;



Time to Upload and test

Upload the code to ESP8266 ESP-01 using ESP8266 Serial Adaptor

Give 30 seconds to calibrate PIR.

Now you will start receiving a notification when motion is detected.

%d bloggers like this: