Haseeb HaiderGrandeur Technologies
Published © GPL3+

Automated Door Security System

This system informs us that whenever a door is opened on our website. This system utilizes IR sensors to detect the movement of the door.

IntermediateFull instructions provided10 hours1,022
Automated Door Security System

Things used in this project

Story

Read more

Schematics

IR module pin configuration

Here's the pin configuration for our IR sensor...!

Code

Source code for Door automation system

C/C++
here you go guys our code...!
/* Import WIFI library */
#include <ESP8266WiFi.h>

/* Import Grandeur library */
#include <Grandeur.h>

/* Import DHT library */

#define Door1 D4
#define DHTTYPE DHT11

// DHT dht(temp, DHTTYPE);

int timestamp;

/* SSID and Password */
#define ssid "HUAWEI-geHt"
#define password "myJSNmmk"

/* Define Credentials Here */
#define deviceID "devicel7kbyp9b00d70lj1cg6igsm0" 
#define apiKey "grandeurl7kbyoe700d40lj1fm2f20oj"
#define accessToken "f0072e383e963b3d156442c2f18c2aa8ee9477ce5ec2a5b735d42fd1ae2ba043"

/* Define Grandeur Variables */
Grandeur::Project project; 
Grandeur::Project::Device device;


bool door1flag = false;
int armed = 0; 

void statusChange(bool status) {
    switch(status) {
        case CONNECTED:
          /* Device connected to the cloud */
          Serial.println("Device is connected to the cloud.");
          return;

        case DISCONNECTED:
          /* Device disconnected from cloud */
          Serial.println("Device is disconnected from the cloud.");
          return;
    }
}


char* readDoors(){


    int door1 = digitalRead(D4);
    if(armed == 1){
        if (door1 == 1){
            door1flag = true;
        }
        if(door1flag == true){
            return "There has been a breach!";
        }
        else{
            return "Secure";
        }
    }
    else{
        return "System Disarmed";
    }


    if (door1 == 1){
        return "Door Opened!!!";
    }
    else {
        return "Closed";
    }
}

/* Function to display temperature */
void displayTemp(const char* code, int temperature) {
    Serial.println(temperature);
}


void connectWifi() {
    /* Configure in WIFI client mode */
    WiFi.mode(WIFI_STA);

    /* Connect to a router */
    WiFi.begin(ssid, password);

    /* Wait for wifi to connect */
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }

    /* Print message */
    Serial.println("");
    Serial.println("WiFi connected");
}

/* Update Temperature */
void update_curr_handler(const char* code, const char* val) {
    Serial.printf("Updated value is: %s\n", val);

}

void update_armed_handler(const char* code, const char* Armed){
    armed = atoi(Armed);
    if(armed == 1){
        int doorval = digitalRead(Door1);
        if(doorval == 1){
            armed = 0;
            device.data().set("Armed", setArmed());            
        }
        else{
            door1flag = false;
        }
    }
}

/* The setup function runs once when you press reset or power the board */

void setup() {
    /* Serial for debug */
    Serial.begin(9600);

    /* Configure led pin */
    // pinMode(temp, INPUT);

    /* Connect to wifi */
    connectWifi();

    /* Connect to Grandeur server */
    project = grandeur.init(apiKey, accessToken);

    /* Detect connection status */
    project.onConnection(statusChange);

    /* Get reference to device */
    device = project.device(deviceID);

    device.data().on("door1val", update_curr_handler);
    device.data().on("Armed", update_armed_handler);
    device.data().get("Armed", updateHandler);
    /* Start timer */
    /* Number of milliseconds passed since the program started */
    timestamp = millis();
}

void updateHandler(const char* path, const char* Armed) {
    /* Converting from string to int */
    armed = atoi(Armed);

    /* Print state */
    Serial.printf("Updated state is %d\n", armed);

    /* Update pin level */
    digitalWrite(LED_BUILTIN, !armed);
}


/* The loop function runs over and over again forever */
void loop() {
    if (millis() - timestamp > 3000) {  
        
         /* Sending data to grandeur cloud */
        device.data().set("door1val", readDoors());  
        timestamp = millis();
    }
int door1val = digitalRead(Door1);
Serial.println(door1val);

    delay(10);
    project.loop();
}

int setArmed(){
    return armed;
}

Credits

Haseeb Haider

Haseeb Haider

1 project • 1 follower
Grandeur Technologies

Grandeur Technologies

9 projects • 54 followers
Simplifying IoT dev; abridging that huge gap between our softwares and hardwares.

Comments