Austin MorganJon Lewis
Published

PIR Motion Sensor Camera Security System

Small IOT security system consisting of a PIR sensor and digital camera. Set the camera out to catch whoever walks by.

IntermediateFull instructions provided8 hours2,136
PIR Motion Sensor Camera Security System

Things used in this project

Hardware components

Photon
Particle Photon
×2
Breadboard (generic)
Breadboard (generic)
×2
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Resistor 220 ohm
Resistor 220 ohm
×1
LED (generic)
LED (generic)
×1
General Purpose Transistor NPN
General Purpose Transistor NPN
×2
Key-chain Camera
×1

Software apps and online services

ThingSpeak API
ThingSpeak API
Maker service
IFTTT Maker service

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

PIR Sensor Circuit Diagram

PIR Sensor Circuit Diagram

Camera Circuit Diagram

Camera Circuit Diagram

Code

Camera subscribe

C/C++
Controls the camera which is subscribed to an event published by another photon connected to a PIR sensor.
int shutter = D7;
int mod = D1; //mode button on camera used to turn camera on/off


void setup() {
pinMode(shutter, OUTPUT);
pinMode(mod, OUTPUT);
Particle.subscribe("Camera", myHandler); //recieves signal from photon with PIR sensor 
}

void loop() {
delay(500);
digitalWrite(shutter,LOW);
digitalWrite(mod,LOW);
}

void myHandler(const char *event,const char *data){
    if (strcmp(data,"1")==0) {
      digitalWrite(mod, HIGH);// switches mode button to turn the camera on
        delay(300);
        digitalWrite(mod,LOW);
          delay(200);
        digitalWrite(shutter, HIGH);//takes picture
        delay(300);
        digitalWrite(shutter,LOW);
        delay(600);
        
        digitalWrite(mod, HIGH);//changes the mode to OFF
        delay(300);
        digitalWrite(mod,LOW);
          delay(200);
        digitalWrite(shutter, HIGH);//switches camera off
        delay(300);
        digitalWrite(shutter,LOW);
        
        Particle.publish("CamON","HIGH",60);
        delay(5000);
        
      
    }
}

PIR Sensor to Camera and Thingspeak

C/C++
int PIR = D7;
double count=0;
int var1=0;             
int last = 0;

void setup() {

pinMode(PIR,INPUT);
  // Subscribe to the integration response event
  Particle.subscribe("hook-response/PhotonMotion1", myHandler, MY_DEVICES);

}

void myHandler(const char *event, const char *data) {
  // Handle the integration response
}

void loop() {
     var1=digitalRead(PIR);
     
       if ((var1 == HIGH) && (last == LOW)) {  //basically just determining if motion has been sensed or not and if so inducing the count and publishes
           count++;                              //running count to send to ThingSpeak for graphing
            Particle.publish("PhotonMotion1",String(count),60); //publish command to trigger the data to be sent to ThingSpeak
            Particle.publish("Camera","1"); //publish that the other photon is subscribed to to capture a picture with the camera
            delay(10000); //10 second delay, make sure to have a long enough delay not to overload the console and trip things up
        
       }
       
       last = var1; //the other aspect of the count function to keep a running count ie. 1,2,3,4,5,6......
                    //you can reflash the code to reset the count
  }

Credits

Austin Morgan

Austin Morgan

1 project • 0 followers
Jon Lewis

Jon Lewis

1 project • 0 followers

Comments