Things used in this project

Hardware components:
Photon new
Particle Photon
×2
Magnetic Reed Switch
×1
LED Light Strip
×1
Infrared Remote
×1
Phone with Camera
×1
11026 02
Jumper wires (generic)
×1
Software apps and online services:
Q8wtlimqnp04fzhtr9v5
IFTTT Maker service
Camio
Particle.build
Hackster
ThingSpeak API
Hand tools and fabrication machines:
Duct Tape

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 CodeArduino
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 CodeArduino
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);
  }
  


}
WebhookC/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

46e8c47fdc77c6ea53e58eea4860ef88
Chris Heiner
1 project • 0 followers
Contact
Batmanfin zbxxqjrtwz
Richard Bastian
1 project • 1 follower
I love Robots
Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Add projectSign up / Login