Jessica Critchleyajw2115
Published © GPL3+

Cookie Jar Security

Keep your cookies safe with this security system.

BeginnerFull instructions provided5 hours749
Cookie Jar Security

Things used in this project

Story

Read more

Schematics

Led warning light.

This is the diagram for the alarm light.

Internet Button

This is the Internet Button Chip that plugs directly into the Particle Photon, for easy use.

Code

Accelerometer Motion Detector

C/C++
Use this with an internet button as a motion detector to keep your cookies safe! This code is for the photon that is on the lid of your cookie jar.
// This #include statement was automatically added by the Particle IDE.
#include <InternetButton.h>
#include "math.h"
InternetButton b = InternetButton();
// Led Position initialization
int ledPos = 0;

void setup() {
    b.begin();
    Particle.variable("ledPos",ledPos);
}    

void loop() {
    //reads X,Y,Z values of Accelerometer
    int xValue = b.readX();
    int yValue = b.readY();
    int zValue = b.readZ();
    
    //displays green led for led closest to the ground
        b.ledOn(ledPos,0,0,0);
        ledPos = b.lowestLed();
        delay(0);
        b.ledOn(ledPos,0,255,0);
        delay(200);
        //article.publish("motion","Closed",PUBLIC);
    //Flashes all leds red and plays error noise
    if(b.readY() < -25){
        if(b.readY() <= -25){
            b.playSong("G4,8,G4,8,G4,8,G4,8,G4,8,G4,8");
            b.allLedsOn(255,0,0);
            delay(250);
            b.allLedsOff();
            delay(250);
            b.allLedsOn(255,0,0);
            delay(250);
            b.allLedsOff();
            delay(250);
            b.allLedsOn(255,0,0);
            delay(350);
            b.allLedsOff();
        }
        if(b.readY()< 25){
            Particle.publish("motion","Open",PUBLIC);
            delay(2000);
        }
    }
    
    // Flashes all leds Yellow for warning
    else if(b.readY() <= -19){
        b.allLedsOn(230,130,0);
        delay(250);
        b.allLedsOff();
        delay(250);
        b.allLedsOn(230,130,0);
        delay(250);
        b.allLedsOff();
    }
}        

Stolen Cookie alarm!

C/C++
This is the code for the second photon. This code allows the second photo to receive data that the cookie jar was open from the other photon, and turns on led lights when the cookie jar is detected as open.
//Code for the recieving Photon that turns on the led lights when the cookie Jar is open.
int led = D7;   //Sets led as pin D7
int led1 = D0;  //Sets led1 as pin D0 for extra Led.
void setup() {
    pinMode(led, OUTPUT);       //sets Led as an output
    digitalWrite(led, LOW);     //Starts with led on low
    pinMode(led1, OUTPUT);      //Sets led1 as an output
    digitalWrite(led, LOW);     //Starts with led1 on low
    Particle.subscribe("motion", anything, "420024001451353432393433"); //subscribes to the "motion" detected event from the internet button
}
void anything(const char *event, const char *data){     //Allows the photon to recieve data from the other photon
    if(strcmp(data,"Open")==0){
        digitalWrite(led, HIGH); digitalWrite(led1, HIGH);      //Turns on both leds when Jar is open
        delay(2000);
        digitalWrite(led, LOW); digitalWrite(led1, LOW);        //Turns off both leds when Jar is closed
        }
}
void loop() {

}

Credits

Jessica Critchley

Jessica Critchley

1 project • 1 follower
ajw2115

ajw2115

1 project • 0 followers

Comments

Add projectSign up / Login