Chris HeinerRichard Bastian
Published © GPL3+

Apartment Security System

Simple and effective way to keep your apartment secure. Receive live feed and updates relating to activity within your apartment.

IntermediateWork in progress3 hours699
Apartment Security System

Things used in this project

Hardware components

Photon
Particle Photon
×2
Magnetic Reed Switch
×1
LED Light Strip
×1
Infrared Remote
×1
Phone with Camera
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Maker service
IFTTT Maker service
Camio
Particle.build
ThingSpeak API
ThingSpeak API

Hand tools and fabrication machines

Duct Tape

Story

Read more

Schematics

First Photon

This photon activates when the door is opened and sends info to Camio app, IFTTT, and second photon.
First photon bb 1dsjsriqzz

Second Photon

This photon activates the remote to turn the lights on in the individual rooms.
Photon 2 bb 11116aqog6

Code

Photon 1 Code

Arduino
This code senses the magnetic reed switch which tells whether the door is open or closed. This information is published to think speak and photon 2.
int state; // state is used in the loop portion of the code,
//it funtions in a way that only lets the code publish every time the state of the door changes.
int door=0; // this is the value being sent to thingspeak, 0 means the door is closed and 1 means open.

void setup() {
	pinMode(D7,OUTPUT);
	pinMode(D0,INPUT); // D0 is reading the input from the reed switch
	pinMode(D2,OUTPUT); // D2 is connected to an LED that will be on when the reed switch is open and off otherwise
	
	digitalWrite(D7,HIGH); // D7 is always outputting a high signal
Particle.subscribe("roomate2017rc3557", switcher);//D7 is outputing the signal that will go to pin D0,

}
void loop() {
	
   if (digitalRead(D0)==HIGH){ //reads HIGH when the reed switch (whih is connected to ground) is disonected due to the door opening
    	if(state != 0){
    	Particle.publish("roomate2017rc3557","open");// publish open to roomate2017rc3557, which is the channel that the other photon is listening and reacting to
    	state=0;
    	door=1; //door is open
    	Particle.publish("thingSpeakWrite_", "{ \"1\": \"" + String(door) + "\", \"k\": \"API KEY HERE\" }", 60, PRIVATE); //tell thingspeak that the door is open (1)
    	
    	}
	}
	else if (digitalRead(D0)==LOW){ //reads LOW when the reed switch (whih is connected to ground) is connected due to the door being closed
    	if (state !=1){
    	Particle.publish("roomate2017rc3557","closed");//publish closed to buddy photon
    	state=1;
    	door=0; //door is open
    	delay(1000);
    	Particle.publish("thingSpeakWrite_", "{ \"1\": \"" + String(door) + "\", \"k\": \"API KEY HERE\" }", 60, PRIVATE);//tell thingspeak the door is closed
    	}
	}
	
}

void switcher(const char *roomate2017rc3557, const char *data) { //this portion is subscribing to my own publish, so that I can check that its working.
  	if (strcmp(data,"open")==0) {
	
	digitalWrite(D2,HIGH); //if the door is opened, turn on the LED.
	Particle.publish("iftttcheck2017","opened");
	
  	}
	else {
    	digitalWrite(D2,LOW);
	}
}

Individual Room Particle Code

Arduino
This code will set the light sensor off in each room to alert the occupant of a break in.
int state;

void setup() {


 pinMode(D0,OUTPUT); 
 digitalWrite(D0,LOW);
 
  Particle.subscribe("roomate2017rc3557", switcher);
}

void loop() {

}
 void switcher (const char *roomate2017rc3557, const char *data) {
Particle.publish("ifttt_securityproject",open);


// this part of the code says that when the door opens that power is gernerated through the photon.
  if (strcmp(data,"open")==0) {
      Particle.publish("ifttt_securityproject",open);



    digitalWrite(D0,HIGH);
   
  
}
//This part of the code says that when the door closes the power is turned off.
    else if (strcmp(data,"closed")==0) {
        Particle.publish("ifttt_securityproject",closed);


        digitalWrite(D0,LOW);
        delay(1000);
        digitalWrite(D0,HIGH);
        delay(1000);
        digitalWrite(D0,LOW);
  }
  


}

Webhook

C/C++
use to integrate Thingspeak
{
    "event": "thingSpeakWrite_",
    "url": "https://api.thingspeak.com/update",
    "requestType": "POST",
    "form": {
        "api_key": "{{k}}",
        "field1": "{{1}}",
        "field2": "{{2}}",
        "field3": "{{3}}",
        "field4": "{{4}}",
        "field5": "{{5}}",
        "field6": "{{6}}",
        "field7": "{{7}}",
        "field8": "{{8}}",
        "lat": "{{a}}",
        "long": "{{o}}",
        "elevation": "{{e}}",
        "status": "{{s}}"
    },
    "mydevices": true,
    "noDefaults": true
}

Credits

Chris Heiner

Chris Heiner

1 project • 0 followers
Contact
Richard Bastian

Richard Bastian

1 project • 1 follower
I love Robots
Contact

Comments

Add projectSign up / Login