30 Minutes or Less: Build a Wireless Entry Sensor with NodeMCU

Machinechat Jedi
6 min readJul 23, 2020

“Did I leave the door or the garage open?” It’s always unnerving when you’re not sure if an entry has been left open or not. In this article we’ll show you how to build a wireless entry sensor using an inexpensive NodeMCU module and a hall effect sensor.

NodeMCU is a tiny, low-cost WiFi-enabled microcontroller that supports direct connectivity to multiple sensors via SPI, I2C, ADC, GPIO, etc. Programming of the module is made easier with support for the Arduino Integrated Development Environment (IDE). You can build up as many wireless sensor nodes as needed to create your wireless sensor network.

The wireless hall effect sensor will send data to the Universal Sensor Hub that we showed you how to build in our prior article. The Universal Sensor Hub uses Machinechat JEDI One software running on the Raspberry Pi. JEDI One enables you to collect data from all the sensors and display the data on a dashboard accessible from any browser on the network.

Here is an example of a JEDI One system view of multiple sensors including a garage sensor:

The Machinechat JEDI One system view allows you to see IoT data in the context of your project environment.

We will show you in just 6 steps, how to get a wireless sensor network started and set up email and text notifications. A few items you will need:

  1. NodeMCU modules — less than $5 each
  2. Hall Effect Sensor and magnet — $10 (this one is nice, comes with wires and mounting hardware)
  3. Micro USB cable — $5
  4. Arduino IDE — Free
  5. Universal Sensor Hub with Machinechat JEDI One installed

Step 1: Setting up the Arduino IDE

Download the IDE here for your MAC, PC or Linux computer. If you are new to Arduino, please review this tutorial. Once you have it installed and running, you should see this:

We need the Arduino IDE to know how to talk to our NodeMCU module. Select:

  1. Arduino -> Preferences -> Additional Boards Manager URLs:
  2. Enter: http://arduino.esp8266.com/stable/packageesp8266comindex.json
  3. Click: OK

That window looks like this:

It’s important to carefully and correctly set up your NodeMCU Tools settings…not doing so can result in undesired behavior to occur!

Finally, setup the details about your NodeMCU under Tools. This is important; if not correct, undesired behavior may occur! If you purchased the NodeMCU in the link above, the settings you want to select are:

  • Tools -> Board -> NodeMCU 1.0 (ESP-12E Module)
  • Tools -> Flash Size -> 4M (3M SPIFFS)
  • Tools -> CPU Frequency -> 80 Mhz
  • Tools -> Upload Speed -> 921600

Here’s a video that shows you how to configure the board support package:

Now, close the Arduino IDE program.

Step 2 — 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.

View of set up with magnet (under blue tape) on the left and hall-effect switch on right.

Step 3: Connect the Hall Effect Sensor to the NodeMCU

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.

Step 4: Loading, configuring, and running the software

Plug the micro USB cable into your PC and attach the NodeMCU to the other end. Important: The NodeMCU module will get power from the USB cable. Open the Arduino IDE. Your screen should look like this (take special note of the bottom line to verify connection):

Download the sketch (source code) here. Within the Arduino IDE click on FILE -> Open and then select the file you just downloaded. It will prompt to create a directory, agree to this.

Find the following lines of code in the sketch and change the “Your_SSID” and “Your_WiFi_Password” with the settings for your wireless router or access point in quotes.

// Wi-Fi settings - replace with your Wi-Fi SSID and password, in quotes
const char* ssid = "Your_SSID";
const char* password = "Your_WiFi_Password";

Also, edit the line in the sketch with the IP address and port number for your Universal sensor hub running on the Raspberry Pi. The default HTTP listener for JEDI One is on port 8100. For this example we use 192.168.1.7:8100:

// Change to IP address of Raspberry Pi running Machinechat JEDI software
// If you changed the JEDI port number, replace 8100 with the new port
const char* host = "192.168.1.7:8100";

Save the sketch by clicking on the Save Arrow button.

It is finally time to compile and load the sketch into the NodeMCU. Make sure you click on the Serial Monitor icon after the code downloads (if you open it too soon, it will interfere with download). Here is a video of the sketch being compiled and downloaded to the NodeMCU:

Success! Now that the code is in the NodeMCU flash, the Arduino IDE can be closed and the unit moved to another location. A USB charger can be used to power the NodeMCU; no need for the computer at this point.

The serial window in the video above shows that the information from the sensor is being successfully sent to our Universal Sensor hub. The LED on the NodeMCU will blink every five seconds when data is transmitted.

Step 5: Create a data dashboard with Machinechat JEDI One to monitor your entry status

JEDI One allows you to view your data in two ways:

  • As a system view dashboard, which allows you to view real-time data in the context of the environment your sensors and devices are operating in; or
  • In a data dashboard

In this example, we will add the status of the entry way (garage) value from the wireless NodeMCU sensor to a data dashboard that includes information on other sensors attached to our Universal Sensor Hub:

Notice how the entry status automatically showed up along with its the properties. These are being collected by the default HTTP listener. Our software below is sending the data via HTTP POST.

STEP 6: Set up a rule notification

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:

And the text message:

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.

Check out the following links to learn how you can easily configure JEDI One to view, store and monitor your data in different ways:

--

--

Machinechat Jedi

Passionate about Raspberry Pi, BeagleBone and creating software that enables IoT developers and enthusiasts to deploy their projects faster — and beautifully.