I have a very simple code of door sensor (magnetic) which gives results in 1 & 0 format. But I want to run the NodeMCU only when a door is open or close. Rest of time I want to keep it in deep sleep mode. Here is my code looks like :

int doorClosed = 1;

#define REED_SWITCH D5

void setup() {
  // put your setup code here, to run once:

  digitalWrite(BUILTIN_LED, HIGH);


void loop() {
  // put your main code here, to run repeatedly


    if ((digitalRead(REED_SWITCH) == HIGH) && (doorClosed == 1))
      Serial.println("DOOR OPEN!!");
      doorClosed = 0;
      digitalWrite(BUILTIN_LED, LOW);
    else if ((digitalRead(REED_SWITCH) == LOW) && (doorClosed == 0))
      Serial.println("DOOR CLOSED!!");
      doorClosed = 1;
      digitalWrite(BUILTIN_LED, HIGH);

Here I am able to put the NodeMCU in deep sleep. But it never wakes up. How can I wake up my chip. After attaching the D0 with RST, I don't event get Serial Logs. I am not sure what kind of behaviour is this. If someone can help me to fix this code will be great!

Thank you!

  • 1
    According to this guide (randomnerdtutorials.com/esp8266-deep-sleep-with-arduino-ide) the pin to be connected to RST is D0 and not A0.
    – leoc7
    Commented Jan 9, 2019 at 21:49
  • I am sorry it was a typo mistake. I just fixed it. Commented Jan 10, 2019 at 5:33
  • After going in sleep mode, check D0 voltage value with a multimeter. Should be approximately to 0V.
    – leoc7
    Commented Jan 10, 2019 at 7:25
  • If D0 is not 0V, connect RST to GND and check if microcontroller wakes up.
    – leoc7
    Commented Jan 10, 2019 at 7:28
  • I just check the D0 voltage, but seems like its not going to 0V its showing me 3.25V. Which means its not going to deep sleep? in multimeter I am touching D0 and GND pin to check the voltage. Commented Jan 10, 2019 at 9:41

2 Answers 2


According to this guide:

The RST pin of the ESP8266 is always HIGH while the ESP8266 is running. However, when the RST pin receives a LOW signal, it restarts the microcontroller.

If you set a Deep Sleep timer with the ESP8266, once the timer ends, GPIO 16 sends a LOW signal. That means that GPIO 16 when connected to RST pin can wake up the ESP8266 every time the timer ends.

The only way to wakes up ESP8266 from deep sleep mode without timer is set a LOW signal on RST pin.

Example without timer:


Connect D0 (GPIO 16) to RST is available only when ESP8266 is in sleep mode with timer.

Example with 30sec timer:


In your case, you can use deep sleep with timer and connect Door sensor to D0 and will act as switch between the RST and D0.

  • can i do that programmatically? Commented Jan 11, 2019 at 5:06
  • also if its in deep sleep mode. Then how can i send a signal to it? i am using door sensor, will it be able to read its value in deep sleep? Commented Jan 11, 2019 at 5:07
  • You can’t do it programmatically! During deep sleep esp8266 is switched off and can’t do any operation. An approach can be to set a deep sleep mode with timer (e.g. 30sec) and connect D0 to RST. Every 30sec esp8266 wakes up, restart program and check door sensor.
    – leoc7
    Commented Jan 11, 2019 at 7:37
  • interrupt will also not work in this case? Commented Jan 11, 2019 at 7:58
  • No, if you use Deep Sleep, ESP8266 is off and the only way to wake up it is trigger physically RST pin. Consider to use other type of sleep mode (for example light-sleep) Take a look to this guide: losant.com/blog/making-the-esp8266-low-powered-with-deep-sleep
    – leoc7
    Commented Jan 11, 2019 at 8:33

My response is late but herewith my experience that may be of help to others.

NodeMcu in deep sleep will wake-up from external source on receiving a pulse from high to low on the RST pin.

An ADXL345 accelerometer raises an interrupt HIGH on sensing motion and remains high until (I2C) READ to prevent multiple devices from interfering with each other

The following post was instrumental in my finding a solution


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.