Outcome


Intention

I chose to create an IoT device that senses whether the front door is locked or unlocked (via magnets) and pushes a notification to the user if the door is unlocked. My roommate constantly forgets to lock the door. In fact, I now pay for rental insurance because I do not trust her to secure the apartment. Apparently, a busy schedule induces her lapses in judgement—she cannot find a way to remind herself to lock up when she is running from the apartment.

Goal

To solve the problem, I used a Hall Effect sensor to read a magnet attached to the front door lock. When the door is unlocked, the magnet moves away from the sensor and the Photon sends a notification (in the form of a variable value) to the cloud. IFTTT reads the variable and pushes a notification to the user's phone. Red and green LED lights quickly and intuitively display when the door is locked (green) and unlocked (red). Furthermore, the user can deactivate the unit by using a simple push button at the base.

Process

I assembled the circuit step by step, testing each component as I moved along. First, I installed the red and green LED lights, connecting them to ground and a digital input / output node. I then wrote a test code to ensure each LED functioned properly. Next, I installed the on / off switch, also connecting it to ground and a digital input / output node. I then progressed the code, testing the on / off capabilities by connecting the button to the red and green LEDs. When I depressed the button, the green light turned on, and when I released the button, the red light turned on.

After installing the button and the LEDs, I assembled the Hall Effect sensor. This required connections to power, ground, and a digital input / output node. A resistor between power and the digital feed helped indicate when the unit was activated and deactivated (via a magnet). After this, I changed the code so the Hall Effect sensor would change the LED outputs when activated / deactivated. I also connected a variable value to the cloud to indicate when a magnet was present / not present so IFTTT could push a notification to the user.

Finally, I changed the code slightly so the button activated / deactivated the code running the LEDs, the Hall Effect sensor, and the cloud variable (via a simple if statement). After this, I tested the on / off functionality, the LED lights (green = magnet present; red = magnet not present), and the push notifications. IFTTT is somewhat slow to read the variable (i.e., it's not immediate), so a notification takes approximately 30 seconds – 1 minute.

Code Sources: 

http://daraghbyrne.github.io/diotlabs/1-a-simple-internet-appliance/first-sketch/

http://daraghbyrne.github.io/diotlabs/5-getting-input/buttons/

http://garagelab.com/profiles/blogs/tutorial-how-to-use-the-hall-effect-sensor-with-arduino

Outcome

As stated above, the final prototype pushes a notification to the user if the door is not locked. A green LED indicates the door is locked, while a red LED indicates the door is not locked. The user can activate and deactivate the device using a simple on / off switch. Next, I would likely add a sound-based system that would notify the user if the door was unlocked for a certain period of time.

Reflection

Ultimately, I learned the importance of segmentation. It really helped to move through the circuit and the code piece by piece. This helped me to ensure every component worked so I could quickly identify, isolate, and correct the issue in either the code or the circuit. In the end, everything worked as I wanted it to. I particularly like the functionality of IFTTT. It was not incredibly intuitive connecting the information from the Photon to the cloud, but once I figured it out, everything came together.

Magnet present.thumb
Show Advanced Options
Magnet not present.thumb
Show Advanced Options
Unit off.thumb
Show Advanced Options
Show Advanced Options
Drop files here or click to select

You can upload files of up to 20MB using this form.