Introduction: Refrigerator Door Timer

In this tutorial, we will step through the process of building and coding an abstraction of a refrigerator light timer. The main goal of our device is to save power by only turning on the refrigerator's light if someone is standing in front of it. Our Internet of Things device uses two sensors: a reed switch and an object avoidance sensor module. The reed sensor will send a signal whenever there is a magnetic field present. This will be used to detect if the door is open or closed. If the door is open, the proximity sensor is used to detect if someone is standing in front of the fridge. If no person is detected, the timer will start counting how long it has been since someone was in front of the door.

This project also includes an interface to control the device, which is run on a flask server. A user can check each of the timers, or reset them using this interface.

The following steps will guide you though the process of building this device.

Step 1: Setting Up the Hardware

The first step is to set up the circuits for the device. We will need:

- Raspberry Pi 3

- Breadboard

- Reed Module*

- Obstacle Avoidance Sensor Module*

- 10KOhm Resistor

- Wires

- One Magnet (for trying the device)

*From the Arduino 37-in-1 Sensors Kit (Documentation)

Once all of the materials have been collected, assemble the circuit based on the diagram shown above.

Step 2: The Code

Now that we have our hardware set up, we can begin writing the code. The code can be found in the attached zipped folder. The structure of the directories is tricky, so be careful not to move any of the files around.

Step 3: Using the Device

The program is run using Flask servers. Details for installing and using Flask can be found here.

First, using the command prompt, set the flask app to be iotapp.py:

> set FLASK_APP = iotapp.py

Next, run the app with:

> flask run --host 0.0.0.0

To access the interface, copy the URL that results from the last command. This page has two timers: one that keeps track of how long the door has been open, and one to monitor how long the door has been open without someone in front of it. Whenever the page is refreshed, both timers will update. A user can reset the timers using the "Reset Timers" button.

The magnet represents the fridge door. Whenever the magnet is present, the door can be considered closed. To simulate opening the door, take the magnet away from the reed sensor. To simulate a person standing in front of the fridge, place your hand over the proximity sensor. When you remove your hand, the timer will begin to count how long it has been since someone has been in front of the fridge.

Step 4: The Final Product

Here, we show an example of the device in action.

This Instructable was created by Ryan Anderson and Kevin Benson.