John Moorelalardieri
Published © GPL3+

Snack Security

Snack security is a simple anti-theft system that captures photos of anyone stealing your snacks and sends them immediately via email.

BeginnerFull instructions provided10 hours2,394
Snack Security

Things used in this project

Story

Read more

Schematics

Sensor Switch Circuit Diagram

Receiver Circuit Diagram

Code

Sensor Switch

C/C++
Switches security system to active, thus telling the camera to take pictures when motion sensor is activated.
int PIR = D7;
int Button = D6;
int count = 0;

void setup() {
pinMode(Button,INPUT);
pinMode(PIR,INPUT);
}

void loop() {
    int var1=digitalRead(PIR);
    int var2=digitalRead(Button);
    
    if (var2 == HIGH && count == 0){ //Counter for initial button push when leaving household
        delay(5000);
        count = count + 1;
    }
    else if (var2 == LOW){ //Resets button counter when button is turned off
        count = 0;
    }
        if (var1 == HIGH && var2 == HIGH) { //Sends signal to other particle when PIR is tripped
            Particle.publish("your event here","HIGH",60,PUBLIC);
            delay(5000);
            }
        else {
            delay(2000);  
        }
       
}

Photon Receiver Code

C/C++
Receives code to take picture when from sensor switch is on.
int led = D7;

void setup() {
pinMode(led, OUTPUT);
Particle.subscribe("your event here", myHandler);
}

void loop() {
delay(2000);
digitalWrite(led,LOW);
}

void myHandler(const char *event,const char *data){
    if (strcmp(data,"HIGH")==0) {
        digitalWrite(led, HIGH);
        Particle.publish("your event here2","HIGH",60,PUBLIC);
        delay(5000);
    }
}

Webcam Mail Shell Script

SH
Program captures picture with fswebcam and records the date and time as the title. Then uses mpack, an ssmtp tool, to email the photo.
#!/bin/bash

DATE=$(date +"%Y-%m-%d_%H%M")

fswebcam -r 640x480 --no-banner /home/pi/webcam/$DATE.jpg

mpack -s "PiCam" /home/pi/webcam/$DATE.jpg *insert-your-email-here*

Raspberry Pi Webcam Control

Python
Receives physical particle signal and initiates webcam email script on Raspberry Pi.
import RPi.GPIO as GPIO
from time import sleep
import os

GPIO.setmode(GPIO.BOARD)
GPIO.setup(40, GPIO.IN)

condition = True
sleep(5)

print("begin")
while condition == True:
  if GPIO.input(40) == True:
    print("input recieved")
    os.system("./webcammail.sh")
    sleep(5)

Credits

John Moore

John Moore

1 project • 0 followers
lalardieri

lalardieri

1 project • 0 followers

Comments