Hackster is hosting Hackster Holidays, Ep. 5: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 5 on Friday!
Brandon RamseyMatt Keough
Published

Motion Sensing Home Security Device

Feel safe while away from your home with this motion security device that can detect motion from anywhere with a wifi connection

BeginnerShowcase (no instructions)49
Motion Sensing Home Security Device

Things used in this project

Hardware components

PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Photon 2
Particle Photon 2
×2
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Story

Read more

Schematics

Circuit Diagram

Data Chart

Code

Device 1 code

C/C++
int inputPin = D4;              
int ledPin = D7;                
int pirState = LOW;            
int val = 0;
int ledout = D6;
int calibrateTime = 10000;      

void setup()
    {
        pinMode( ledPin, OUTPUT );
        pinMode(inputPin, INPUT);  
        pinMode(ledout, OUTPUT);
        digitalWrite(ledout, LOW);
        Particle.subscribe("Matt_Keough_IOT_Device", myHandler, "0a10aced202194944a04ad5c");
    }

void loop()
    {
        if ( calibrated() )
            {
               readTheSensor();
               reportTheData();
            }
    }

void readTheSensor()
    {
        val = digitalRead(inputPin);
    }

bool calibrated()
    {
        return millis() - calibrateTime > 0;
    }

void reportTheData()
    {
       
        if (val == HIGH)
            {
                Particle.publish("BRpho", "1");
                pirState = HIGH;
                setLED( pirState );
                delay(60000);
            }
           
        else
            {   pirState = LOW;
                setLED( pirState );
                Particle.publish("BRpho","0");
            }
    }

void setLED( int state )
    {
        digitalWrite( ledPin, state );
    }

void myHandler(const char *event, const char *data)
    {
        digitalWrite(ledout, HIGH);
        delay(5000);
        digitalWrite(ledout, LOW);

Device 2 code

C/C++
int led = D7;



void setup() {

pinMode(led, OUTPUT);
digitalWrite(led, LOW);

Particle.subscribe("BRpho", myHandler, "0a10aced202194944a049f6c");


}

void myHandler(const char *event, const char *data)
{
if (strcmp(data,"1")==0) {
  digitalWrite(led, HIGH);
  Particle.publish("Matt_Keough_IOT_Device","1");


  }else if (strcmp(data,"0")==0) {
      digitalWrite(led, LOW);

  
}}

Credits

Brandon Ramsey

Brandon Ramsey

1 project • 1 follower
Matt Keough

Matt Keough

1 project • 1 follower

Comments