Jeffrey CecilHal Kosik
Published © GPL3+

MEGR 3171L Fall 2019 PIR Motion Sensing Security System

Wanna spy on your significant other, creep out your roommates, or figure out who's stealing all your beer? This motion detector will help!

BeginnerFull instructions provided10 hours82
MEGR 3171L Fall 2019 PIR Motion Sensing Security System

Things used in this project

Hardware components

Grove - PIR Motion Sensor
Seeed Grove - PIR Motion Sensor
×1
Argon
Particle Argon
×2
Breadboard (generic)
Breadboard (generic)
×2
Jumper wires (generic)
Jumper wires (generic)
×2
Grove – Chainable RGB Led V2.0
Seeed Grove – Chainable RGB Led V2.0
×2

Story

Read more

Schematics

Motion Sensor Wiring Diagram

LED Wiring Diagram

Code

First Argon with the PIR sensor

C/C++
Place this Argon and sensor in an area of choice, and let it keep an eye on what kind of human or animal motion is going on in there!
// First photon, Motion sensor by Jeffrey Cecil
int inputPin = D2;              
int ledPin = D5;                
int pirState = LOW;             
int val = 0;        
int calibrateTime = 10000;      
int ledd = D7;

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

void loop()
{

  
  if ( calibrated() )
  {

    readTheSensor();

   
    reportTheData();
    
    
    readTheIncoming();
    
  }
}

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

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

void reportTheData() {

  
  if (val == HIGH) {

   
    if (pirState == LOW) {
     
      Particle.publish("49er_mtb123456", "Motion sensed");
      
      pirState = HIGH;
      setLED( pirState );
    }
  } else {
    if (pirState == HIGH) {
     
      pirState = LOW;
      setLED( pirState );
    }
  }
}


void readTheIncoming() {
  
 Particle.subscribe("49er_mtb12345", myHandler, "Message Recieved by Second Argon");
delay(1000);
}


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


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

Second Argon with Notification LED

C/C++
Keep this Argon handy, in another room, or at the office, to notify you when motion has been detected in your area of interest.
//Buzzer Side by Hal
int led = D7;
int Buzzer = D0;
int state = 0;
int pirState = LOW;
int led2pin = D5;

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);
 	
 Particle.publish("49er_mtb12345", "1");
 
}

void loop() {
Particle.subscribe("49er_mtb123456", myHandler, "1");
delay(1000);
 	
}

Credits

Jeffrey Cecil

Jeffrey Cecil

1 project • 0 followers
Hal Kosik

Hal Kosik

0 projects • 0 followers

Comments

Add projectSign up / Login