IoT Motion Detector With NodeMCU and Blynk

Hello guys, hope you doing fine. 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.

About the Project

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.

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

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.

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

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
S.No Component Name Quantity Buy Link
1. Nodemcu esp8266 1 https://amzn.to/3EUGhuu
2. Nodemcu cable 1 https://amzn.to/3F1ywmu
3. PIR Motion Sensor 1 https://amzn.to/3AIuhK1
4. Buzzer 1 https://amzn.to/3zN2LJL
5. led 1 https://amzn.to/39AGSTA
6. Breadboard 1 https://amzn.to/39vsRX2
7. Jumper wire 40 https://amzn.to/39q43jr
8. 220-ohm Resistor 2 https://amzn.to/3EWIPIy

iot motion detector with nodemcu and blynkCircuit Diagram for the Project

Nodemcu esp8266 PIR Motion Sensor
VV, Vin ( +5V ) VCC ( Positive + )
G, GND ( Ground ) GND ( Ground – )
D5 Pin  OUT Pin
Nodemcu esp8266 Buzzer
GND ( Ground )    ( –  ) Negative
D2 Pin ( + ) Positive
Nodemcu LED R LED G 220 Ohm Resistor
D1 Pin Anode Pin    
D3 Pin   Anode Pin  
  Cathode Pin Cathode Pin Terminal 1
GND ( Ground )     Terminal 2

Connections:-

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.

 //TECHATRONIC.COM  
 // BLYNK LIBRARY  
 // https://github.com/blynkkk/blynk-library  
 // ESP8266 LIBRARY  
 // https://github.com/ekstrand/ESP8266wifi  
 #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()   
 {  
  Serial.begin(9600);  
  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);  
 }  
 BLYNK_WRITE(V0)  
 {  
  pinValue = param.asInt();  
 }  
 void notifiaction()   
 {  
  bool sensor = digitalRead(D5); // PIR SENSOR OUTPUT PIN D5  
  Serial.println(sensor);  
  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() {  
  Blynk.run();  
  timer.run();  
 }  

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.

HAPPY LEARNING!