IoT Motion Detector With NodeMCU and Blynk


Hello guys, hope you doing fine.

HTML Image as link

Did you know what is a PIR sensor and how it is used to make a security system? Well in this article we are going to make an IoT motion detector with NodeMCU and Blynk app.

For making this we are using a NodeMCU esp8266 board and a PIR motion sensor. You can also check some more projects on IoT

PIR stands for passive infrared radiation and it generates high output when capturing some movement. Check Arduino-based home security system using PIR sensor made by us.

HTML Image as link

IoT Motion detector Working

  • You have to provide your network’s SSID and PASSWORD so that the NodeMCU can send data over the internet. Also, specify your authentication token number.
  • When the PIR sensor detects some motion near it the red LED will turn on and the buzzer will start beeping.
  • The green LED will glow in normal conditions.

Please check how to use Arduino IDE for uploading the code in NodeMCU.

A preview image of the setup so, you can get an idea that what would you need.

Open the serial monitor to see the activities and the IP address.


iot motion detector with nodemcu and blynk
iot motion detector with nodemcu and blynk

Activate PIR Sensor

Turn on the PIR sensor by clicking the on button.

If it detects some movement near it or in its range then an alert notification will send by the app on the smartphone.

Set up the Blynk app

You have to install the Blynk IoT app and then open the app. Create a new project by clicking on the box whose image is given below.

Then name the project as you want and select NodeMCU as the device. Choose WiFi as the connection type. Tap on create to create your project.

The Blynk app will send a unique authentication code automatically to your given email address. Then press ok to continue.

Add token to mail

Now tap on the + symbol to open the widget’s box.

Create new button

Select a button and a notification widget as shown in the image below. Adjust the position of both widgets on the screen.

iot motion detector with nodemcu and blynk

Open the configuration settings by tapping on the highlighted button.

Tap on the button and set the pin to V0. You can name the button as an on/off switch. Make it a switch, not a push-button. For notification, do the setting as given in the image below.

iot motion detector with nodemcu and blynk
iot motion detector with nodemcu and blynk

Click the marked button so that the app start working and your NodeMCU can link through it.

Components Required

  • NodeMCU esp8266 board
  • PIR sensor
  • LEDs and 220-ohm resistors
  • Buzzer
  • Breadboard and Jumper wires
  • USB cable for uploading the code
  • Smartphone with a good internet connection

IoT motion sensor Circuit diagram:-

Connection is clear and easy to make. make sure to turn of the power supply during the connection. still if you have any doubt you can ask in the comment section.

iot motion detector with nodemcu and blynk

Connection Table

Nodemcu esp8266PIR Motion Sensor
VV, Vin VCC 
D5 Pin OUT Pin
Nodemcu esp8266Buzzer
GND Negative
D2 PinPositive
NodemcuLED RLED G220 Ohm Resistor
D1 PinAnode Pin  
D3 Pin Anode Pin 
 Cathode PinCathode PinTerminal 1
GND ( Ground )  Terminal 2


  • VCC pin of the PIR -> VIN pin of the NodeMCU
  • GND pin of the PIR -> GND pin of the NodeMCU
  • OUT pin of the PIR -> digital-5 pin of the NodeMCU
  • Positive pin of the buzzer -> digital-2 pin of the NodeMCU
  • Positive pin of the red LED -> digital-1 pin of the NodeMCU
  • Positive pin of the green LED -> digital-3 pin of the NodeMCU
  • GND pin of the NodeMCU -> negative pin of the buzzer and LEDs

Code for the Project

Note: Please upload the code which is given below to the NodeMCU. You have to install <ESP8266WiFi.h> and <BlynkSimpleEsp8266.h> libraries first. Check here how to install zip libraries to the Arduino IDE.

 // ESP8266 LIBRARY  
 #define BLYNK_PRINT Serial  
 #include <ESP8266WiFi.h>  
 #include <BlynkSimpleEsp8266.h>  
 char auth[] = "54wl_i7SD0dMWrXBopu0sBt"; //Enter your Blynk application auth token  
 char ssid[] = "DESKTOP"; //Enter your WIFI name  
 char pass[] = "asdfghjkl"; //Enter your WIFI passowrd  
 BlynkTimer timer;  
 int pinValue = 0;  
 void setup()   
  pinMode(D1, OUTPUT); // RED LED  
  pinMode(D2, OUTPUT); // BUZZER  
  pinMode(D3, OUTPUT); // LED GREEN  
  pinMode(D5, INPUT);  // PIR SENSOR OUTPUT PIN D5  
  Blynk.begin(auth, ssid, pass);  
  timer.setInterval(1000L, notifiaction);  
  pinValue = param.asInt();  
 void notifiaction()   
  bool sensor = digitalRead(D5); // PIR SENSOR OUTPUT PIN D5  
  if (pinValue == 1)   
   Serial.println("System is ON");  
   if (sensor == 1)   
    Blynk.notify("WARNING! Please check your security system");  
    digitalWrite(D1, HIGH); // LED RED ON  
    digitalWrite(D2, HIGH); // BUZZER ON  
    digitalWrite(D3, LOW);  // LED GREEN OFF  
   else if (sensor == 0)   
    digitalWrite(D1, LOW); // LED RED OFF  
    digitalWrite(D2, LOW); // BUZZER OFF  
    digitalWrite(D3, HIGH); // LED GREEN ON  
  else if (pinValue == 0)   
   Serial.println("System is OFF");  
   digitalWrite(D3, LOW);  // LED GREEN OFF  
 void loop() {;;  

If you like this project please tell us in the comments section below. Now try to make it on your own. You can also check tutorials on Arduino and Raspberry PI written by us.

Video Sample

Spread the love

1 thought on “IoT Motion Detector With NodeMCU and Blynk”

Leave a Comment