Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Techatronic
Published

IoT Motion Detector With NodeMCU and Blynk

In this project, we are making an IoT motion detector using nodemcu and PIR motion sensor.

BeginnerFull instructions provided2 hours5,338
IoT Motion Detector With NodeMCU and Blynk

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
LED (generic)
LED (generic)
×1
Resistor 220 ohm
Resistor 220 ohm
×1
5 mm LED: Green
5 mm LED: Green
×1
Buzzer
Buzzer
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×1
Arduino UNO
Arduino UNO
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Code snippet #1

Plain text
 //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();  
 }  

Code snippet #2

Plain text
 //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();  
 }  

Github

https://github.com/ekstrand/ESP8266wifi

Github

https://github.com/blynkkk/blynk-library

Credits

Techatronic
73 projects • 132 followers
Electronic engineer
Contact

Comments

Please log in or sign up to comment.