Paul CoadyKyle Ward
Published

Security Camera

Catch em' red handed without lifting a finger!

BeginnerShowcase (no instructions)4 hours1,423
Security Camera

Things used in this project

Hardware components

Photon
Particle Photon
×2
Breadboard (generic)
Breadboard (generic)
×2
Jumper wires (generic)
Jumper wires (generic)
×6
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Servos (Tower Pro MG996R)
×1
AAA Batteries
×3
SanDisk Ultra PLUS UHS-1 16GB SD Card, Class 10
×1
18 Megapixel Digital Camera
×1

Software apps and online services

Maker service
IFTTT Maker service

Story

Read more

Schematics

Servo Setup - 3D

Servo Setup - Schematic

PIR Sensor Setup- 3D

PIR Sensor Setup - Schematic

Code

Servo

C/C++
Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created


int pos = 0;    // variable to store the servo position

void loop()
{
     Particle.publish("connected","go");
}

void setup()
{
    Particle.subscribe("cabinet_open",snap_pic);
    myservo.attach(D0);   // attach the servo on the D0 pin to the servo object
    myservo.write(25);    // test the servo by moving it to 25°
    pinMode(D7, OUTPUT);  // set D7 as an output so we can flash the onboard LED
}

int snap_pic(const char *event, const char *data)
{
    if (strcmp(data,"open")==0){
        myservo.write(40);       // move servo to 40° - ding!
        digitalWrite(D7, HIGH); // flash the LED (as an indicator)
        delay(100);             // wait 100 ms
        myservo.write(25);      // move servo to 25°
        digitalWrite(D7, LOW);  // turn off LED
        return 1;               // return a status of "1"
    }
    else {  
    }
}

PIR Sensor

C/C++
int ledPin = D7;                 // choose the pin for the LED
int inputPin = D0;               // choose the PIR sensor pin
bool closed;                  // status of cabinet
int motionCounter = 0;           // variable to count motion events

Timer timer(3000, determineMotion); // software timer to check every 3s

void setup() {
  pinMode(ledPin, OUTPUT);       // set LED as output
  pinMode(inputPin, INPUT);      // set sensor as input
  Particle.subscribe("connected",lightOn);   //looks for partner's photon

  timer.start(); // start the determineMotion timer
}

void determineMotion() {    // this function determines if there's motion
    if(motionCounter < 2) { // if very little motion was detected
        if(closed == false) { // only publish if the status changed
        
            }
        closed = true; // set the status to closed
    } else if (motionCounter >= 2) {
        if(closed == true) { // only publish if the status changed
            
            Particle.publish("cabinet_open","open");
            
            }
        closed = false; // set the status to open
    }
    motionCounter = 0; // reset motion counter
}

int lightOn(const char *event, const char *data)  //funtion notifies when partner's photon is ready
{
    if (strcmp(data,"go")==0){
        digitalWrite(ledPin, HIGH); // turn LED ON 
        delay(5000);                // Wait 5s
        digitalWrite(ledPin, LOW);  // turn off LED
    }
    else {  
    }
}

void loop() {
  if (digitalRead(inputPin) == HIGH) {  // check if the input is HIGH
    motionCounter++;                    // increment motion counter
  } else {
    
  }
  delay(500);                           // wait 0.5s
}

Credits

Paul Coady

Paul Coady

1 project • 1 follower
Kyle Ward

Kyle Ward

1 project • 1 follower

Comments