Joshua BaptistKathleen Rubio
Published © GPL3+

Home Security System

This product utilizes the Particle Photon platform to send an alert to the IFTTT app when the door connected to the system has been opened.

BeginnerShowcase (no instructions)5 hours2,321
Home Security System

Things used in this project

Hardware components

LED (generic)
LED (generic)
×2
Photon
Particle Photon
×2
Slide Switch
Slide Switch
×1
Jumper wires (generic)
Jumper wires (generic)
×4
Big Red Dome Button
SparkFun Big Red Dome Button
×1
Resistor 100 ohm
Resistor 100 ohm
×1
Breadboard (generic)
Breadboard (generic)
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×2

Software apps and online services

Maker service
IFTTT Maker service
ThingSpeak API
ThingSpeak API

Story

Read more

Schematics

Circuit Diagram

Code

Photon 1

C/C++
This code takes the input from the buttons (used as sensors to see when the doors are opened or closed) and uploads it to the cloud for the other photon to download and then graph.
// We will be using D1 to control our LED
int ledPin = D1;
int led = D7;
int lasttime = 0;

// Our button wired to D0
int buttonPin = D0;


void setup()
{


  pinMode( buttonPin , INPUT_PULLUP); // sets pin as input

 pinMode( led , OUTPUT ); 
  pinMode( ledPin , OUTPUT ); // sets pin as output
  Particle.subscribe("Task_Complete", anything, "200022001247343438323536");
}

void loop()
{
   // find out if the button is pushed
   // or not by reading from it.
   int buttonState = digitalRead( buttonPin );


  if(buttonState==1)
  {
    // turn the LED On
    digitalWrite( ledPin, HIGH);
  }
  else{
    // otherwise
    // turn the LED Off
    digitalWrite( ledPin, LOW);
    
  }    



    if ((lasttime == 0) && (buttonState == 1))
  {

        // Send a publish...
        int success = Particle.publish("Door_Status","1",PRIVATE);
        delay(2000);
        

      }else{
          // Otherwise, this isn't a new status, and we don't have to do anything.
          
         
      }
       if ((lasttime == 1) && (buttonState == 0))
  {

        // Send a publish...
        Particle.publish("Door_Status","0",PRIVATE);
        delay(2000);
        

      }else{
          // Otherwise, this isn't a new status, and we don't have to do anything.
          
         
      }
      lasttime = buttonState;
}
      
void anything(const char *event, const char *data)
{
    digitalWrite(led, HIGH);
    delay(1000);
    digitalWrite(led, LOW);
    delay(1000);
}
  

Photon 2

C/C++
This code pulls the data from the cloud and then blinks the on-board LED in pin D7 and graphs sensor data using the Blynk application.
int led = D7;
int lasttime = 0;
void setup() {


 pinMode(led, OUTPUT);
 digitalWrite(led, 0);
 Particle.subscribe("Door_Status", myHandler, "270034001247343438323536");

}
void loop() {
     int buttonstate = digitalRead(led);
     
     if ((buttonstate==1) && (lasttime == 0)){
         //Particle.publish("Task_Complete","Done", PRIVATE);
     }

    digitalWrite(led, 0);
    lasttime = buttonstate;
 }
 
void myHandler(const char *event, const char *data)
{
    digitalWrite(led, 1);
    delay(1000);
    //delay(1000);
    

    
}

Credits

Joshua Baptist

Joshua Baptist

1 project • 0 followers
Kathleen Rubio

Kathleen Rubio

1 project • 0 followers

Comments