Software apps and online services
Hand tools and fabrication machines
The mysterious disappearance of chips and cookies calls the need for action. In order to definitively show that someone is taking even small amounts of food from a pantry with a single way for both entry and exit, the simple use of a sensor to detect entry with a Particle Argon microcontroller comes in very handy.Testing Hardware
The kind of sensor to use depends on the features of the particular pantry. Most ideally, the pantry has a single physical door to be opened in which many possibilities exist; one can use:
- A kind of light sensor used to detect either a sudden burst of light (for when the door is opened) or a sudden lack of light (for when the door covers the range of the sensor hidden behind the door when opened).
- A sound sensor when the door is opened and exposed to footsteps and sounds outside the pantry.
- … and more
While the hidden light sensor behind the door when opened was initially what I wanted to do, I was limited by my case, being the lack of a physical door to the pantry:
As a result, I simply used a motion sensor, hoping that those that enter without wanting to be seen are most focused on avoiding actual people and on the noisiness of the food they’ll be moving and eating rather than a machine. The HC-SR501 PIR Motion Sensor from Elegoo was provided in a 37-sensor kit:
On most PIR sensors, there are two settings that are physically adjustable by a screwdriver: sensitivity and time delay.
The sensitivity setting determines the radius of the 110-degree spherical sector cone (in which motion is detected) from 3 to 7 meters. Since pantry rooms are quite small, the bare minimum of 3 meters (the rightmost adjustment) should be sufficient.
The time delay determines how long motion cannot be detected for after motion is detected (and thus delays the time window for detection) from 3 seconds to 5 minutes. For the purposes of testing the hardware, we can use the bare minimum (the leftmost adjustment) of 3 seconds.
Above, the PIR sensor is set up with signal from the digital pin D6 on the breadboard with the Argon, and a LED is set to light up (for the purposes of testing) through digital pin D5 when motion is detected. When the code on this page is used in the Particle IDE with the proper device on the hardware above, the result is this:
The LED changes states (ON to OFF, OFF to ON) when the PIR sensor changes states (HIGH to LOW, LOW to HIGH), and only these changes in states are printed on the serial monitor accordingly.Setting up Data Storage
Only these moments of changes in states for the PIR sensor that we set up are what we are interested in to set up triggers for data storage accordingly.
I used a simplified version of Gustavo Gonnet’s "Pushing Data to Google Docs" project, compiled into one doc by my teacher, to have a Google Sheet to store data. Collecting the times at which any person enters the pantry is very useful for deducing whether they were trying to be sneaky or even who that person could be. The data cells are updated immediately; the testing set-up yielded this:
As you can see above, I additionally set up another event to publish when motion ends (i.e. the state goes from HIGH to LOW). This doesn’t necessarily indicate the length of motion because, when the sensor detects motion for some time, it thinks that there is no motion if the object stops moving within its range. However, a slightly longer time than a couple of seconds could still show that someone was entering the pantry and staying there for some time even if they become still (and invoke a LOW state and the time delay) during their time there.
In case the webhook method does not work or one cannot figure it out, IFTTT can be used to upload data to Google Sheets. I made a second spreadsheet for data just to try this. I deleted all the rows below the top header row to set up my trigger and my action as such:
Additionally, to be able to catch someone in the act in real time, IFTTT can be used to send an email to as such:
Just as the sensor entirely depends on the type of pantry one has (see Testing Hardware), the set-up does too. Usually, a battery pack (of ideally of 3.3 to 5 volts for the Argon and lasting at least 24 hours) is required due to the lack of an outlet, but my pantry has an outlet directly above a laundry basket and (in a seemingly hidden manner) on the wall left of and behind the entrance.
Because we do not need to have the LED anymore for testing (and because it would surely give our secretive placement of the hardware away), we can remove it, the resistor, and the male-male jumper wires from the breadboard and comment out the lines involving the integer variable ledPin in the code. Additionally, we can alter the tie delay setting on the PIR sensor to the maximum of 5 minutes (the leftmost adjustment).
I found an extension wire to make the breadboard, Argon, sensor, and wiring comfortably (and mostly in a hidden manner, the best I could) on a position by the basket and able to detect full entry through the single doorway.
Data-collection (through Google Sheets) and immediate alerts (through Gmail) are completely set up, but I have not set up the hardware in the pantry room for a long period of time. It is able to successfully catch people when they enter; with the time that motion is detected (the event "motion of X seconds ended"), one is able to deduce easily if someone completely entered the pantry room and didn't just set up the sensitive sensor by moving slightly outside the room.
A possible addendum to this project is to use a Raspberry Pi to capture a video of the motion. For this particular project, I’ve mostly relied on knowing the movements and whereabouts of my family and when some of them try to crave snacks and thus possibly would try to sneak into the pantry for them, but an extension of a video capture would solve the problems with certain assumptions.