Mirza Mehmedagic
Published © GPL3+

Lane Tech HS - PCL - Pantry Entry Detector

A simple device to detect entry into such a storage room like a pantry with only one entrance.

BeginnerFull instructions provided1.5 hours288
Lane Tech HS - PCL - Pantry Entry Detector

Things used in this project

Hardware components

Argon
Particle Argon
×1
Breadboard (generic)
Breadboard (generic)
×1
Elegoo HC-SR501 PIR Motion Sensor
*Any PIR Sensor should work for this. I used the HC-SR501 PIR Motion Sensor from Elegoo, which can be found in their 37-sensor kit or the link here.
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
LED (generic)
LED (generic)
*For testing.
×1
Resistor 220 ohm
Resistor 220 ohm
*For testing.
×1
Male/Male Jumper Wires
*For testing.
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Google Sheets
Google Sheets
IFTTT Particle Service
IFTTT Gmail Service
IFTTT Google Sheets Service

Hand tools and fabrication machines

Multitool, Screwdriver
Multitool, Screwdriver

Story

Read more

Schematics

Complete Hardware (Bird's Eye View)

PIR sensor with an LED detector & resistor on breadboard with Argon.

For the PIR Sensor: Black female-male jumper wire is connected to VUSB pin (5 Volt source), white female-male jumper wire is connected to D6 pin, gray female-male jumper wire is connected to ground power rail.

For the testing LED: Anode is connected to D5 pin through male-male jumper wire, Cathode is connected to ground power rail through resistor.

Ground power rail is connected to GND pin through male-male jumper wire.

Complete Hardware (Schematics)

Schematics of complete hardware described above (unfortunately not on Fritzing).

Code

Pantry-Entry-Detector

C/C++
To be used in Particle IDE. Lines 1, 10, 19, & 31 can be commented out if not testing with LED.
int ledPin = D5;                                    // Output pin for the LED
int inputPin = D6;                                  // Input pin for the PIR sensor
int pirState = LOW;                                 // Start with an assumption that there is no motion
int val = 0;                                        // Reading of the pin status
unsigned long motionEndTime = 0;                    
unsigned long motionStartTime = 0;                  
int motionTime = motionEndTime - motionStartTime;   // May be inaccurate because of motion sensitivity, but can show if enterer stayed for some time after 

void setup() {
    pinMode(ledPin, OUTPUT);                        // Set LED as output
    pinMode(inputPin, INPUT);                       // Set PIR sensor as input
    Serial.begin(9600);
}

void loop() {
    val = digitalRead(inputPin);                    // Read input value
    
    if (val == HIGH) {                              // Check if the input is HIGH 
        digitalWrite(ledPin, HIGH);                 // Turn on LED or keep it on
        
        if (pirState == LOW) {                      // See if a change in the state just happened
            motionStartTime = millis();
            
            // Only act on the output change, not on the state every iteration
            Serial.println("Motion detected!");                                      
            Particle.publish("Motion Change", "motion detected");                                       // Links to one spreadsheet through a webhook and another through IFTTT, and sends an email through IFTTT
            
            pirState = HIGH;
        }
    } else {                                        // Check if the input is LOW 
        digitalWrite(ledPin, LOW);                  // Turn LED off or keep it off
        
        if (pirState == HIGH) {                     // See if a change in the state just happened
            motionEndTime = millis();
            motionTime = (int) ((motionEndTime - motionStartTime) / 1000);
            
            // Only act on the output change, not on the state every iteration
            Serial.println("Motion of " + String(motionTime) + " seconds ended!");   
            Particle.publish("Motion Change", "motion of " + String(motionTime) + " seconds ended");    // (although probably unnecessary) Links to one spreadsheet through a webhook and another through IFTTT
            
            pirState = LOW;
        }
    }
}

Credits

Mirza Mehmedagic

Mirza Mehmedagic

3 projects • 2 followers

Comments

Add projectSign up / Login