This tutorial will show you how to use NodeMCU with an AH180 Hall Effect Sensor for transmitting data to the readiness.io service. The nodeMCU uses the ESP8266 Chip from Espressif. It has built in Wifi and is compatible with the Arduino IDE. If you haven't used a NodeMCU before check out this quick start guide.
The digital hall effect sensor that we've used essentially behaves like a switch. When a magnet is detected it closes the switch. So you can change the sensor to another switch, like a reed switch or push button and the code will continue to work.
This example is quite generic but the applications are quite wide. Some include - checking a door/gate is open or closed, if the water level on a tank is low. You can even use it for things like Rain Gauges or Pulse Flow Meters
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Components
Step 2: Wiring It Up
The wiring diagram shows you how to connect the sensor and an LED. Firstly we connect the digital Hall effect sensor up to D5 and connecting the 10K resistor between the Vcc and signal pins on the sensor. For the LED it is connected to D3 with a 1K resistor.
However, if you are using a Hall effect sensor - like the one we've linked in the components list - the LED and resistors are already included, so you just need to connect the three pins to the ground (- pin), Vcc (middle pin) and D5 (S pin).
Step 3: Source Code
We are going to be posting to the readiness.io service every time we see a change in state on the sensor. We'll be using the readiness.io library to manage the wifi and service connections.
In order to reduce the number of false positives - we've include a software debounce with a 200ms window, which you can change in the config file.
To read when the Hall effect sensor changes state we are connecting D5 up as an interrupt so as to keep the loop free from any unnecessary work. Once a change it detected we set a flag in the INTERRUPT variable and then send the state back to the readiness.io service.
Sending data back to the readiness.io service should happen inside the loop and not in the interrupt function as it will time out before it has had a chance to complete the action.
You can find the full source code here
Step 4: The Finished Product
Here is the final board. As you can see we've used a Hall effect sensor attached to a breakout board - which includes the LED and resistors. You simply need to raise the magnet up to the sensor and you will see the LED light up. It will then transmit the state to readiness.io.