Nicholas EdgertonJared Lee Sumner
Published

Door Trespasser Detector

This system of Particle devices notifies you when someone has entered your room and logs data for when your door opens and closes.

BeginnerShowcase (no instructions)4 hours1,238
Door Trespasser Detector

Things used in this project

Hardware components

Photon
Particle Photon
×2
Resistor 221 ohm
Resistor 221 ohm
×2
Wire Cable - By the Foot
OpenBuilds Wire Cable - By the Foot
×1
aluminum foil
×2
command strips
×2

Software apps and online services

Maker service
IFTTT Maker service
Particle App
AtomIOT
Fritzing

Story

Read more

Schematics

Door Sensor Circuit Diagram

Door Sensor Setup

Picture of the Door Sensor

Door Frame Setup

The wires are held in the door frame by command strips. They are then wrapped in aluminum foil and taped again to ensure that they stay.

Particle Subscribe Circuit Diagram

Particle Subscribe Photon

A picture of the photon kit that subscribes the published function

Graphical Representation of Door Trespasser Detector

On the graph, a value of 0 represents the closed door, and a value of 1 represents the door opening. The data for the graph was taken over the course of a few days.

Code

Door Sensor Code

Arduino
int digitalvalue=0;
int status=0;

void setup() {

    pinMode(D7,OUTPUT);
    pinMode(D1,INPUT);
 
    Particle.variable("digitalvalue", &digitalvalue, INT);
    Particle.variable("status", &status, INT);
    Particle.function("digitalvalue",digitalvalueToggle);
}

void loop() {

        status = digitalRead(D7);
        digitalvalue = digitalRead(D1);
        delay(10000);
    
    if (status==0) {
       Particle.publish("doorstatus","inactive");
    }
    else if (digitalvalue==0) {
        Particle.publish("doorstatus","open");
        
    }
    else if (digitalvalue==1) {
        Particle.publish("doorstatus","closed");
    }

}


int digitalvalueToggle(String command) {

    if (command=="on") {
        digitalWrite(D7,HIGH);
     
        return 1;
    }
    else if (command=="off") {
        digitalWrite(D7,LOW);
        
        return 0;
    }
    else {
        return -1;
    }
   
}

Particle Subscribe Code

Arduino
int digitalvalue;


void setup() {


    pinMode(D7,OUTPUT);
    Particle.function("digitalvalue",digitalvalueToggle);
    pinMode(D0,INPUT);
    Particle.variable("digitalvalue", &digitalvalue, INT);
    
    Particle.subscribe("doorstatus",door);
}
void loop() {

    
        digitalvalue = digitalRead(D0);
        delay(100);
}

void door(const char *event, const char *data)
{
  if (strcmp(data,"inactive")==0) {
    digitalWrite(D7,LOW);
    delay(5000);
  }
  if  (strcmp(data,"open")==0) {

   digitalWrite(D7,HIGH);
   delay(5000);
  }
  else if (strcmp(data,"closed")==0) {

    digitalWrite(D7,LOW);
    delay(5000);
  }
   
}
int digitalvalueToggle(String command) {

    if (command=="on") {
        digitalWrite(D7,HIGH);
     
        return 1;
    }
    else if (command=="off") {
        digitalWrite(D7,LOW);
        
        return 0;
    }
    else {
        return -1;
    }
   
}

Credits

Nicholas Edgerton

Nicholas Edgerton

1 project • 0 followers
Jared Lee Sumner

Jared Lee Sumner

1 project • 0 followers

Comments