Honey I'm Home

Made by Melissa Powel

Found in Home Hack

This hall effect sensor is triggered by a magnet in your key that turns on specific lights in your house before you even open the door. Now spot will no longer set off the motion sensor all day long, driving up your electric bill and you never come home to a dark empty house again.

0

Intention

I made this device for my roommate, Sonam, so she never has to come home to a dark house again.

0

Process

  • First I looked at using RFIDs, but was advised against using that sensor as it can be difficult to work with due to security settings. I ended up using the Hall Effect US5881 and a magnet and started research how to set it up on a breadboard. It was small and really easy to work with.
  • Next I set up my sensor as input in D2 and my LED as OUTPUT in D0. I used 1,000 ohm resistors for both the Hall Effect and the LED. To make sure my circuit was working, I blinked my LED.
  • I wrote the following pseudocode to help plan my code and then looked online for sample content. I only had to make minor adjustments to get the code to perform the way I wanted.
  1. //Hall effect sensor detects a magnet
  2. //Turns on LED light
  3. //Sends a text message to roommate "Hey roomie, I'm home!"
  4. //Manually able to switch the light off

0

Product

This is a basic breadboard circuit configuration with a hall effect US5881 sensor that turns on an LED light. The code is programmed to turn on the LED when it senses a magnet nearby. The application of this in real life is, for example, a simulation of a magnetized key turning on the lights when the door is unlocked.

The code is programmed to keep the light on even when the magnet is removed. At first, my if else statement was turning it off when the magnet was removed. The fix was frustratingly simple! By deleting the else, the loop stopped after turnOnLED(); and the light remained in the on state. (See code below).

A three prong, one sided switch was added to be able to turn off the light.

0
Hall Effect Sensor
Melissa Powel - https://youtu.be/56b5APfmjQ8
0

Final Code

0
int LED = D0;
int HALL_SENSOR = D2;

void setup ()
{
  pinMode(HALL_SENSOR, INPUT);
  pinMode(LED, OUTPUT);
}

void loop ()
{
  if(isNearMagnet())
  {
    digitalWrite(LED, HIGH);
  }

}

//Code that detects when a magnet is near the sensor.
boolean isNearMagnet()
{
  int sensorValue = digitalRead(HALL_SENSOR);
  if(sensorValue == LOW)  //detects user is within close proximity
  {
    return true;
  }
  else
  {
    return false;
  }
}
Click to Expand
0

Reflection

I didn't push myself as far technically as I could have for this project, but I still invested a lot of time. Rather than rush myself to finish it, I spent a lot of time watching tutorials, reading blogs, and understanding the sensors and code I was working with. The code I used was really easy to understand and applied to my project almost perfectly, but it gave me a chance to play with each line of code and really understand what was happening.

I tried working with the the NeoPixel RBGW Ring that I have, but couldn't figure it out given the deadline. I'm not giving up and I know we have course resources that could help me. Hopefully for my next project I'll be able to get them to work.

I also started to become more familiar with some of the help sites. For example, I didn't realize adafruit had a learning center: https://learn.adafruit.com/adafruit-neopixel-uberguide/neopixel-rings


0

--Alternate Code--

0

Making the LED Stay On

Original if else statement where the LED light turned off when magnet was removed:

0
void loop ()
{
  if(isNearMagnet()) //How do I loop the light to remain on?
  {
    turnOnLED();
  }else
  {
    turnOffLED();
  }
}
Click to Expand
0

Updated code where LED light stays on until manually switched off:

0
void loop ()
{
  if(isNearMagnet()) 
  {
    turnOnLED();
  }
}
Click to Expand
0

Sending SMS Messages

I was able to send a message using ifttt.com but wasn't able to get the loop to stop firing, so I've since commented that feature out. So far the only solution classmates have found to stop the sudden barrage of sms messages is to add a really long delay in the loop (see below). The issue with this is that stops the code and makes the device unresponsive for whatever period of time you have set.

Code credit: http://integratedinnovation.xsead.cmu.edu/gallery/projects/turn-down-for-what

1
//Sending an SMS through ifttt.com
//Add the following before void setup()

unsigned long lastPublishTime=0;


//Update the void loop() with the sendSMS(); method

void loop ()
{
  if(isNearMagnet()) 
  {
    turnOnLED();
    sendSMS();
  }
}

//Add the following to a new method below the void loop()

void sendSMS()
{ 
  if (millis()-lastPublishTime>60000)
  { 
      Particle.publish("messageToRoomie", "Hey roomie, I'm home!");
      lastPublishTime = millis();
  }
}
Click to Expand
x
Share this Project

Found In
Courses

49-713 Designing for the Internet of Things

· 26 members

A hands-on introductory course exploring the Internet of Things and connected product experiences.


About

This hall effect sensor is triggered by a magnet in your key that turns on specific lights in your house before you even open the door. Now spot will no longer set off the motion sensor all day long, driving up your electric bill and you never come home to a dark empty house again.

Created

January 26th, 2017