swastikchakraborty
Published © GPL3+

Esp8266 door security system using Blynk

Esp8266 door security system using Blynk where the nodemcu board will notify when was the door opened last time

BeginnerFull instructions provided92
Esp8266 door security system using Blynk

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
Infrared Module (Generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Blynk
Blynk

Story

Read more

Schematics

annotation_2022-09-17_101924_FktX5th7Cp.png

Code

Untitled file

Arduino
#include <NTPClient.h>
#include <WiFiUdp.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define BLYNK_TEMPLATE_ID "TMPLklvCnzID"
#define BLYNK_DEVICE_NAME "Waterlevel"
#define BLYNK_AUTH_TOKEN "NiynCgMlR27a_U9YJwrDWoSHBFsPhEOK"
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "GNXS-716170";  // Enter your Wifi Username
char pass[] = "12032008"; 
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org");

//Week Days
String weekDays[7]={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

//Month names
String months[12]={"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};

BlynkTimer timer;
int InPin = 5;
void setup() {
  pinMode(InPin, INPUT);
    Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
    Serial.begin(9600);
  timer.setInterval(100L, sensor);
  timeClient.begin();
  // Set offset time in seconds to adjust for your timezone, for example:
  // GMT +1 = 3600
  // GMT +8 = 28800
  // GMT -1 = -3600
  // GMT 0 = 0
  timeClient.setTimeOffset(19800);
}
void sensor() {
  int  currentState = digitalRead(InPin);
  Serial.println(currentState);
  if (currentState == 1){
    timeClient.update();

  time_t epochTime = timeClient.getEpochTime();
  
  String formattedTime = timeClient.getFormattedTime();

  String weekDay = weekDays[timeClient.getDay()];

  //Get a time structure
  struct tm *ptm = gmtime ((time_t *)&epochTime); 

  int monthDay = ptm->tm_mday;
  int currentMonth = ptm->tm_mon+1;

  String currentMonthName = months[currentMonth-1];

  int currentYear = ptm->tm_year+1900;

  //Print complete date:
  String currentDate = String(monthDay) + "-" + String(currentMonth) + "-" + String(currentYear);
    String tim = formattedTime + " , " + currentDate;
    String string = "door was last opened at " + tim;
    Blynk.virtualWrite(V0, string);
    delay(3000);
  }
}
void loop() {
  Blynk.run();//Run the Blynk library
  timer.run();//Run the Blynk timer
}

Credits

swastikchakraborty

swastikchakraborty

3 projects • 1 follower

Comments

Add projectSign up / Login