Wesley Sturdivant
Published © GPL3+

Food Security

A motion detector that sits in my food cabinet. Can be used to detect motion next to rat traps or to notify you of hungry roommates.

BeginnerFull instructions provided3 hours1,855
Food Security

Things used in this project

Hardware components

SparkFun RedBoard
SparkFun RedBoard
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1

Software apps and online services

Maker service
IFTTT Maker service

Story

Read more

Schematics

PIR detector to Photon circuit diagram

It is a simple connection of Vin and GND on the PIR detector to their respective pins on the Photon, then Vout to pin SDA/D0 and used as a digitalRead. If the pin returns LOW value, it means the detector picked up motion.

Code

PirMotionDetectorV2

Arduino
Detects motion, publishes count value based on reentry to apartment location.
int pirPin = D0; // PIR is connected to D3
int led = D7;    // Onboard LED is D7
int counter = 0;

void setup()
{
  pinMode(pirPin, INPUT_PULLUP); // Initialize D3 pin as input with an internal pull-up resistor
  pinMode(led, OUTPUT);          // Initialize D7 pin as output
  Particle.function("Armed", youAreAway);
  Particle.function("Disarmed", youAreHome);
  Particle.variable("counter", &counter);
}

void loop()
{
  int pirValState;

  pirValState = digitalRead(pirPin);

  if(pirValState == LOW){      // Was motion detected
    digitalWrite(led, HIGH);   // Turn ON the LED
    counter = counter + 1;
    delay(30000); // wait 30 sec to aviod scanning too often 
  }
  else
  {
    digitalWrite(led, LOW);  // Turn the LED off
  }

}

int youAreAway(String){
    Particle.publish("Armed","textAlert1");
    counter = 0; //reset counter upon exit of appartment location
    return counter;
}

int youAreHome(String){
    
    if (counter == 0){
    Particle.publish("foodSafe","textalert4");
    }
    else if (counter > 0){
    Particle.publish("Intruder","textalert5");
    }
    return counter;
}

Credits

Wesley Sturdivant

Wesley Sturdivant

1 project • 3 followers
Mechanical Engineering Student at UNCC

Comments