Sean PerryBenjamin Rankin
Published © GPL3+

IoT Home Security Motion Sensor (Swansonator)

This is a project that uses two Particle Photons and a PIR motion sensor to detect when someone enters your house.

EasyFull instructions provided4.5 hours9
IoT Home Security Motion Sensor (Swansonator)

Things used in this project

Hardware components

Photon
Particle Photon
×2
Grove - PIR Motion Sensor
Seeed Grove - PIR Motion Sensor
×1
5 mm LED: Red
5 mm LED: Red
×2
Male/Male Jumper Wires
×7
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×2
Cardboard Box
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1

Software apps and online services

Google Sheets
Google Sheets
Maker service
IFTTT Maker service

Story

Read more

Schematics

Motion Sensor Photon

Screen shot 2018 11 12 at 11 10 01 pm sf9rx16bec

LED Photon

Screen shot 2018 11 12 at 11 11 42 pm js9sygefhv

Code

Motion Sensor Photon

C/C++
// First photon, Motion sensor
int inputPin = D0;              
int ledPin = D7;                
int pirState = LOW;             
int val = 0; 
int myHandler =1;
int led = D7;


int calibrateTime = 5000;      

void setup()
{
  pinMode( ledPin, OUTPUT );
  pinMode(inputPin, INPUT);
  Particle.subscribe("Recieved", Good_Recieve, "360025000c51353432383931");
}
void Good_Recieve(const char *event, const char *data)
{
  digitalWrite(led, HIGH);
  delay(1000);
  digitalWrite(led, LOW);
  delay(1000);
  digitalWrite(led, HIGH);
  delay(1000);
  digitalWrite(led, LOW);
  delay(1000);
  digitalWrite(led, HIGH);
  delay(1000);
  digitalWrite(led, LOW);
}
void loop()
{

  
  if ( calibrated() )
  {

    readTheSensor();

   
    reportTheData();
  }
}

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

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

void reportTheData() {

  
  if (val == HIGH) {

   myHandler= myHandler;
   Particle.publish("Motion_alert", String(myHandler));
   delay(10000);
   }
   else if (pirState == LOW) {
     myHandler = 0;
    }
}

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

LED Photon

C/C++
//Second Photon, LED
int led = D7;
int state = 0;
int Good_Recieve = 1;



void setup() {

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

Particle.subscribe("Motion_alert", myHandler, "270034000c47363330353437");


}

void myHandler(const char *Motion_Alert, const char *myHandler)
{
Particle.publish("Recieved", String(Good_Recieve));
  digitalWrite(led, HIGH);
  delay(1000);
  digitalWrite(led, LOW);
  delay(1000);
  digitalWrite(led, HIGH);
  delay(1000);
  digitalWrite(led, LOW);
  delay(1000);
  digitalWrite(led, HIGH);
  delay(1000);
  digitalWrite(led, LOW);
  
}
void loop() {

}

Credits

Sean Perry

Sean Perry

0 projects • 0 followers
Benjamin Rankin

Benjamin Rankin

0 projects • 0 followers

Comments

Add projectSign up / Login