In this tutorial we will show how to build door/window sensor only with ESP8266 and NodeMCU(LUA) - without Arduino. We will use nice EasyIoT interface to display door/windows status on our phone, tablet or desktop computer.
First step when building this sensor is to upload correct firmware to our ESP8266 module. We will use node NodeMCU firmware. This firmware is capable of executing LUA script. Latest NodeMCU firmware can be download here NodeMCU. Read ESP8266 firmware update tutorial for instructions how to update ESP8266 firmware.
Next we will add virtual door/window sensor to EasyIoT server. You can download EasyIoT server (Windows or Raspberry Pi version) on EasyIoT server download page.
- ESP8266 module
- Reed relay
- 100nF ceramic capacitor
See buying guide at the end of tutorial.
EasyIoT server configuration
Go to Configure->Drivers->Virtual driver and press button Add node. Virtual driver must be enabled.
Remember node address. In this case is N9S0.
Then go back in Groups and modules and newly added module (address N9S0).
Then name senosr and change type to Door/Window(Di) sensor.
After you add sensor it should be like this.
Upload LUA program
To upload LUA program to ESP8266 we need LUAloader. It can be found here. If you just updated firmware don't forget to disconnect GND wire connected to GPIO0 - we do not need it any more.
LUA program can be found on GitHub. There are two files: init.lua and lua_easyiot_doorwindow.lua. Download both files and correct AP and AP password in init.lua. In file lua_easyiot_doorwindow.lua correct server IP address EasyIoT username and password and node address. In our case node address is N9S0, but in your case can be different.
Change this line in init.lua:
and this in lua_easyiot_doorwindow.lua:
easyiot_username = "admin"
easyiot_password = "test"
easyiot_server = "192.168.1.5"
easyiot_node_address = "N9S0"
Now we just need to connect wires. Add magnetic reed relay switch and 100nF capacitor for debouncing and two AA batteries. See buying guide for details.
Check also EasyIoT Cloud ESP8266 door/window sensor.
See more tutorials at http://iot-playground.com/build
To support this site and EasyIoT framework development please buy in our store.