fbpx

ESP8266 – Motion Detector

Motion detector uses the infra-red(IR) radition to detect the motion.It detect an object which moved in or out of the sensor range

Block Diagram

Flow Chart

Component Required

  1. Node MCU.
  2. PIR
  3. Jumper wire
  4. BreadBoard

Software Required

  1. MIT App inventor – Android
  2. Firebase
  3. Arduino 

Circuit diagram

Firebase

Login To firebase

  • create new project
  • Create database for Motion detector
  • Set firebase security rules to test mode to allow esp8266 to set and read database
  • Set Rules of firebase to read and write in real timedatabase
  • Select Real-time Database 
  • Copy the URL- Required in code as firebase host-id to communicate with firebase
  • Click to add child to Create a field to hold data in firebase
  • Create motion field to hold motion detected data in firebase.
  • Motion detected field in realtime database hold motion_detecteion data.

Android Application:

  • Create New project from mit app inventor for motion detector 
  • Select layout to place the userinterface component
  • Create a header from the Android application:            
  • Drag and drop label in the screen for app header
  • use the firebase database url, you can ignore the FirebaseToken 

Logic for Motion Detection App

Android App

Code

#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
#define FIREBASE_HOST " "
const char* ssid = "IMAKE"; // Your ssid
const char* password = "12345678"; // Your Password
#define PIR 5
void setup()
{
pinMode(PIR,OUTPUT);
Serial.begin(115200);
delay(100);
dht.begin();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi is connected");
Serial.println(WiFi.localIP());
delay(1000);
Firebase.begin(FIREBASE_HOST);
}

void loop()
{
if(digitalRead(PIR) == HIGH)
{
Firebase.setString("Motion","Motion_Detected");
}
else if(digitalRead(PIR) == LOW)
{
Firebase.setString("Motion","Motion_Not_Detected");
}
} 

Leave a Reply

Your email address will not be published. Required fields are marked *