Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Hackster is hosting Impact Spotlights: Industrial Automation. Watch the stream live on Thursday!Hackster is hosting Impact Spotlights: Industrial Automation. Stream on Thursday!
Heather Anne MackenzieKacy Vanden Bergh
Published

Security System 3171 Project

Are you worried someone may break into your home without you knowing? Not anymore with our security system!

IntermediateFull instructions provided170
Security System 3171 Project

Things used in this project

Hardware components

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

Story

Read more

Schematics

Circuit

Circuit Diagram

Code

Motion Sensor / Notification

C/C++
This code activates the motion sensor and sends notifications to a device of your choosing on the status of the motion sensor
int buzzerPin = D0;                 
int inputPin = D1;               
bool available = false;          
int motionCounter = 0;           
bool loadfirst = false;

Timer timer(30000, determineMotion);

void setup() {
  pinMode(buzzerPin, OUTPUT);   
  pinMode(inputPin, INPUT);      
  determineMotion();
  timer.start(); 
}

void determineMotion() {    
    if(motionCounter < 1) { 
        if(loadfirst == false){
             loadfirst = true;
             motionCounter = 0;
             Particle.publish("apartment", "Motion Detector Starting", PRIVATE);
             delay(500); 
        }
        else if(available == false) { 
             motionCounter = 0;
             Particle.publish("apartment", "Apartment is Available", PRIVATE);
             delay(500); 
            }
        available = true;
    } else if (motionCounter >= 1) {
        if(available == true) { 
            loadfirst = true;
            Particle.publish("apartment", "Motion Detected", PRIVATE);
             delay(500); 
            }
        available = false; 
         motionCounter = 0;
    }
}

void loop() {
  if (digitalRead(inputPin) == HIGH) {  
    digitalWrite(buzzerPin, HIGH);         
    motionCounter++;                    
  } else {
    digitalWrite(buzzerPin, LOW);          
  }
  delay(500);                           
}

Buzzer

C/C++
This code receives data from the motion sensor to activate the buzzer once motion is detected.
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("motion_sensor_2", myHandler, "0a10aced202194944a0497dc");
delay(1000);
}

Credits

Heather Anne Mackenzie
1 project • 1 follower
Contact
Kacy Vanden Bergh
1 project • 1 follower
Contact

Comments

Please log in or sign up to comment.