DIY Security System

Made by Evan Adkins

Track motion and trigger events on cloud and local hardware

Created: February 22nd, 2017

0

20170202_182127.jpg  

Intention

The idea for this project stemmed from a desire for a low cost home security system. Through the use of a PIR motion sensor, the component circuit will notify a user when motion is detected via email. The Photon microcontroller utilizes cloud variables to communicate with the IFTTT API in order to trigger email notification. A user will be able to call local authorities or a neighbor to ensure the safety of their home and belongings.

Context

After experiencing robberies of several close friends, I naturally drifted toward the idea of a security system for my own home. Although there are technologies already developed that solve this issue, it was simple enough to build a DIY kit that gets the job and has the potential for customization. I will address the idea of customization in my description of the product.

Process

I began by integrating functionality of the PIR sensor, debugging my code through the serial monitor. Due to the Photon Desktop app’s inability to run with my microprocessor, accessing the serial monitor took some researching, resulting in the use of the CLI. The sensor itself was simple to read from (digital output) and power correctly. I then created a schema for how and when the device knows to notify the user and when to enable the added component (in this case the LED). I created 2 states and a cloud variable whose transitions were controlled by a variable reading the sensor. The simple FSM is shown below:

If the val variable is HIGH and pirState was previously LOW then the detected cloud variable is set. I then found that additional functionality would be nice soI integrated the use of an LED acting as an additional component that is enabled with the detected variable and disabled after a specific time interval.

20170202_182158.jpg  

Product

Above are a image and diagram of the finished circuit. The PIR sensor is able to detect motion at a variable sensitivity (potentiometer) in a given room and successfully communicate with the IFTTT API to notify the user via email. It does so by monitoring a cloud variable that reads the digital input of the PIR sensor. I implemented the use of an additional component (LED) to show how it may interface with a light or alarm. Imagine the LED is a loud siren that could alert neighbors or scare an intruder away. Or perhaps an autonomous light switch that enables a room’s lighting while it detects movement in it. A problem that arises with this addition is the ability to turn back off the component when necessary. We wouldn't want the alarm to continue long after the intruder has left, or a light to always be kept on. To solve this issue I implemented an FSM and sampled time at the last detected time of motion and the current time if no motion is present. If the difference between these two times is greater than a user specified time interval, say 5 minutes, the component will automatically shut itself off. Attached is a video of the circuit in use. The LED activates on first detection of movement, sending an email to the user. It then blinks every time it detects further motion. We can note that 10 seconds after the last detected motion, the LED turns off.

Video: https://drive.google.com/file/d/0BxNmbkzFcwOjZzN3X1pVczZzdVE/view?usp=sharing

Reflection

I have not been exposed to cloud communication via a microprocessor before, so it was very cool to see it come to fruition. Retrospectively, it would make more sense to use Particle’s publish function to create an event based action for this application rather than constantly monitoring a variable. Although current technologies already solve this issue, this circuit provides a simple and cheap way to get the job done. Additionally, it provides the ability to customize the security system to a user’s desire. Perhaps instead of an LED, one could interface a net to trap the intruder.


0
unsigned long SET_TIME = 10000;    //10 seconds
int pir = D0;                
int led = D1;  
int alarm = D7;
int pirState = LOW;      
int val = LOW; 
int detected = 0;
unsigned long onTime;
unsigned long currTime;
unsigned long timeDiff;                 
 
void setup() {
  pinMode(pir, INPUT); 
  pinMode(led, OUTPUT); 
  pinMode(alarm, OUTPUT);
  digitalWrite(led,LOW);
  Particle.variable("status", &detected, INT);
  Serial.begin(9600);
}

void loop(){
  tone(alarm, 1000); 
  delay(1000);        
  noTone(alarm);     
  delay(1000); 
  val = digitalRead(pir);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    if ((pirState ==  LOW) && (detected == 0)){
      digitalWrite(led,HIGH);
      detected = 1;
      delay(2000);
      Serial.print("detected\n");
    }
    else{
        digitalWrite(led,LOW);      //indicate motion still present
        delay(100);
        digitalWrite(led,HIGH);
        delay(100);
    }
    onTime = millis();    //set most recent detect time
    pirState = HIGH;
  }
  else {
    currTime = millis();
    timeDiff = currTime-onTime; 
    if (timeDiff >= SET_TIME){
      digitalWrite(led,LOW);
      detected = 0;
    }
    pirState = LOW;
  } 
}
Click to Expand
x
Share this Project


About

Track motion and trigger events on cloud and local hardware