Shawn DashtySaul Avalos
Published © GPL3+

MEGR 3171 Fall 2018 - Security Motion Sensor

Our device serves a multipurpose motion sensor that will allow you to remain confident in your belongings whereabouts

EasyFull instructions provided5 hours20
MEGR 3171 Fall 2018 - Security Motion Sensor

Things used in this project

Hardware components

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

Software apps and online services

Google Sheets
Google Sheets
Maker service
IFTTT Maker service

Story

Read more

Schematics

PIR Motion Sensor Photon Circuit Diagram

Screen shot 2018 11 06 at 11 51 43 pm k65qbyy69f

LED Photon Circuit Diagram

Positive end of LED goes into D7 pin location, while the negative goes to the GRND position adjacent to D7.
Screen shot 2018 11 14 at 11 50 52 am tzsekkvbcx

Code

Motion Sensor Photon Code

C/C++
This code is responsible for the main subscribing and publishing of the two photons. It has a calibration time of 10 seconds (1000 ms) in order for you to set the sensor and leave the room/location that you are keeping watch of. Once calibrated, it reads the sensor which can be found in the loop. After the sensor is read, the data is reported. This allows for the instantaneous data tracking that the project requires. Using a binary system, we used two variables: HIGH & LOW, which are equivalent to 1 & 0, respectively. If the value is retrieved as a HIGH/1, the output is given a value/amplitude of 1. This data point is in the form of a bar graph, which depicts the number of counts/trips within the minute of sensing motion. If the output is LOW/0, the code loops back to beginning, where calibration takes place and the entire process thereafter.
// First photon, Motion sensor
int inputPin = D0;              
int ledPin = D7;                
int pirState = LOW;             
int val = 0;                    

int calibrateTime = 10000;      

void setup()
{
  pinMode( ledPin, OUTPUT );
  pinMode(inputPin, INPUT);     
}

void loop()
{

  
  if ( calibrated() )
  {

    readTheSensor();

   
    reportTheData();
  }
}

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

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

void reportTheData() {

  
  if (val == HIGH) {

   
    if (pirState == LOW) {
     
      Particle.publish("robot_penguin", "1");
      
      pirState = HIGH;
      setLED( pirState );
    }
  } else {
    if (pirState == HIGH) {
     
      pirState = LOW;
      setLED( pirState );
    }
  }
}


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

LED/Buzzer Photon Code

C/C++
This code is used to assure the user of proper photon communication by the use of an LED light and piezo buzzer. When the first photon with the motion sensor is tripped, it calls to the subscribed photon with the LED to shine as response. In sequence, the buzzer goes off as well. This is what is what is seen in the loop. Both pin D7 and the LED should light up when the motion sensor is tripped. The code also allows for the led to pulsate 2times, with a delay of 100 ms in between each pulse. This is also true for the buzzer alarm.
int led = D7;
int Buzzer = D0;
int state = 0;



void setup() {

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

pinMode(Buzzer,OUTPUT);
digitalWrite(Buzzer, LOW);
}




void myHandler(const char *event, const char *data)
{
  digitalWrite(led, HIGH);
  delay(100);
  digitalWrite(led, LOW);
  delay(100);
  
  digitalWrite(Buzzer,HIGH);
      delay(100);
  digitalWrite(Buzzer,LOW);
  
  digitalWrite(led, HIGH);
  delay(100);
  digitalWrite(led, LOW);
  delay(100);
  
  digitalWrite(Buzzer,HIGH);
      delay(100);
      digitalWrite(Buzzer,LOW);
      
  
  
}


void loop() {
Particle.subscribe("robot_penguin", myHandler, "2e0033000d47363330353437");
delay(1000);
}








    

Credits

Shawn Dashty

Shawn Dashty

0 projects • 0 followers
Saul Avalos

Saul Avalos

0 projects • 0 followers
Thanks to David Daniel, Kyle Byrd.

Comments

Add projectSign up / Login