Adding a Door Sensor to the Wireless Sensor Network

"Did I forget to close the garage?"  It's always unnerving when you're not sure if you left a door open or not.  By simply adding a hall effect sensor to the wireless sensor network, you can have the peace of mind that JEDI One is monitoring the data from your door sensor and will alert you if it is left open for more than a preset time interval.  

Garage-door.jpg

garage-email.jpg

In this article, we show you how in four easy steps, you can use a hall effect sensor, magnet and JEDI One to track door activity and send alerts if something is amiss.

What you will need:

Since we already have the environmental sensor hooked up, we will have the added benefit of knowing the temperature, humidity, and pressure in the garage!  

Step 1 - Install the magnet and the sensor on the door

For the prototype, we fashioned two metal brackets: one for the magnet, the other for the hall-effect switch.  

bracket1a.jpgbracket2a.jpg

Step 2 - Connect the sensor to the wireless module

Let's get the Hall effect switch hooked up (the one recommended above requires 5 volt power which is available on the NodeMCU module Vin pin).  The output of this sensor is compatible with our 3.3v GPIO pins, so no concerns there.

IMG_4504.jpg

Here are the connections for the Hall effect sensor:

NodeMCU-NJK.jpg

Note: You can leave the environmental sensor hooked up as well - from the wireless sensor network article.

Step 3 - Modify the sketch

Attached you will find the complete sketch with all of the modifications made to the source from the Wireless Sensor Network article.  This new code will allow us to read the state of the switch.  Here is a summary of the changes made:

Above the setup section:

// Declare the variable for the Hall effect sensor
uint8_t inPin = D5;

In the Setup section:

//Let the NodeMCU know inPin is an INPUT
pinMode(inPin, INPUT);

In the Loop section:

// Store Hall effect sensor state
// State is "true" if door is open
String door_state;

if (digitalRead(inPin) == LOW)
{
door_state = "false";
}
else
{
door_state = "true";
}

-----------

//Add door_state to debug output
Serial.println(door_state);

-----------
//Modify the post data to include door_state
postData = "{\"context\":{\"target_id\":\"BMESensorNode1\"}, \"data\":{\"tempC\":" + String(tempC) + ", " +
"\"humi\":" + String(humi) + ", " +
"\"pressure\":" + String(pressure) + ", " +
"\"door_state\":" + String(door_state) +
" }}";

 STEP 4 - Setup a rule and notification in JEDI One

In this video we setup a rule to send an email and text message if the garage door is left open for more than 5 minutes:

And here is the resulting email:

garage-email.jpg

And the text message:

 Garage-text.jpg

The information in this article is broadly applicable to any binary (true/false, on/off, 1/0) output sensor you may wish to capture data from using JEDI One.

Source code listing from Github:

Was this article helpful?
1 out of 1 found this helpful