

User avatar
By atux_null
#83193 Looking to create a home based security project with nodemcus by making use of:
    Reed switches
    PIR sensors
all of them reporting to the MQTT broker.

MQTT runs in a raspberry at the LAN. The whole project will have the 5 nodemcus with the following setup:
-1 nodemcus with 2 reed switches, PIR sensor and a relay
-2 nodemcus with 2 reed switches, PIR sensor running in battery. Since they reside in a remote place that it does not have power, but wifi's reception is strong.
-2 nodemcus with 5 reed switches running in battery. Since they reside in a remote place that it does not have power, but wifi's reception is strong.

Up to now i have connected a reedswitch to a nodemcu and it reports to the MQTT its status. I am stuck with:
-How to attach (schematics) the rest of the sensors
-Deep sleep for the battery operated nodemcus. Once the reed switch or PIR sensor is triggered, wake up, connect to wifi and then post the sensor's status to MQTT. Wait 15 minutes and then deep sleep again.
User avatar
By btidey
#83198 Basic principle for the battery powered versions is to allow the sensor signals to wake the device out of deep sleep.

On a raw ESP-12 module this can be achieved by using the EN input of the module using something like


In this the EN is kept low by the normally closed reed switches. If either of these opens or the PIR goes high then the module wakes up. A GPIO can then keep the EN signal high until the notification is completed. The GPIO hold can then be released and the module put into deep sleep to await for the EN signal to next go high again.

There are a couple of complications. First, the NodeMCU has an internal EN pull up of around 12K. That makes it difficult to use the EN signal in a low current fashion. Second if you want to notify which sensor has triggered then the you need to get them into GPIO as well as the trigger circuit.

So for a NodeMCU version with separate sensing of the inputs you will need a more sophisticated input circuit. Basically you need to logically OR the sensor outputs together and use the output from that to trigger a pulse which takes the EN low for a period.
User avatar
By btidey
#83204 Basic sequence is that after a sensor wakes the module up then it is just the same a normal reset boot sequence.

So ...

As early as possible set the GPIO hold pin up and set it to 1 to ensure the EN stays high even if sensor goes away,

Then set up wifi and perform the notification just the same way as you do in the non battery application.

Finally, release the GPIO hold by setting to 0 and enter a permanent deep sleep.

There is no point waiting after doing the notification, you should just enter the deep sleep to conserve as much battery power as possible.

I have an example code at but this does IFTTT notification rather than MQTTT. I also have a variant that does Pushover notification for getting easy notifications on a smart phone.