Important note: the esp.deepsleep function uses microseconds, not milliseconds.

I posted another question here asking for clarification on how an RTC can be used to put a NodeMCU 12 to sleep for a long time (~24hrs or more).

This question concerns the use of ESP.deepSleep([microseconds]) with the NodeMCU 12 board. There is a discussion here and I have followed the advice but have been unable to successfully implement the ESP.deepSleep() function using the Arduino IDE and a NodeMCU 12 board.

Initial findings:
-Connecting gpio16 (D0) to the RST pin causes a reset immediately upon entering sleep. The entire boot process and loop are repeated over and over again.
-Simply using the ESP.deepSleep() function without gpio16-to-RST generates gibberish on the serial monitor and illuminates the red led on the board.

My code is here (I just drop "deepsleep();" where I want the sleep process to begin):

void deepsleep() {
  Serial.println("sleeping hr 1");
  ESP.deepSleep(3600000); //1hr
  Serial.println("sleeping hr 2");
  ESP.deepSleep(3600000); //2hr
  Serial.println("sleeping hr 3");
  ESP.deepSleep(3600000); //3hr
  Serial.println("sleeping hr 4");
  ESP.deepSleep(3600000); //4hr
  Serial.println("sleeping hr 5");
  ESP.deepSleep(3600000); //5hr
  Serial.println("sleeping hr 6");
  ESP.deepSleep(3600000); //6hr
  Serial.println("sleeping hr 7");
  ESP.deepSleep(3600000); //7hr
  Serial.println("sleeping hr 8");
  ESP.deepSleep(3600000, WAKE_RF_DEFAULT);  //8hr

What is wrong with this approach and why am I (apparently) causing an error?

  • 1
    just one point you may not be aware of ... the code you show suggests you think the ESP will continue on from after the deepsleep once it wakes up - that's not the case. after it wakes from deepsleep, it goes through the boot process (with a boot reason that indicates it has woken from sleep) - when you say "the entire boot process are repeated", do you mean immediately? or after 1 hour? – Jaromanda X Apr 29 '18 at 0:25
  • Immediate. Sorry for the confusion. – acpilot Apr 29 '18 at 1:08
  • well, that's not good - if it were after 1 hour, then the solution is easy, but immediate is problematic – Jaromanda X Apr 29 '18 at 1:11
  • What's the solution for the 1hr error? – acpilot Apr 29 '18 at 1:13
  • 2
    but that's not your problem - Anyway, the solution I'm speaking of regarding the code you posted is simply knowing that when a ESP awakes from deepsleep, it goes through full boot process, does not continue from where it left off. You can use system_rtc_mem to save some simple "state" so that when you boot, you know if this is an initial boot, or wake from deep sleep (and which deep sleep you've woken from) - the guy with a swiss accent has some nice code examples – Jaromanda X Apr 29 '18 at 2:29

Use a resistor between GPIO16 and RST. I usually use a 470 Ohm resistor. Shorting the pins with a wire does not work.


Maximum deep sleep is about 71 minutes. 3600000 microseconds = 3.6 seconds, not 1 hour. 1 hour in microseconds is 3600000000UL.

As mentioned in the comments, waking from deep sleep on the ESP8266 is a hardware reset so execution begins at the start of the setup function.

  • Every circuit for deep sleep I've ever seen has no resistor. I think the only issue was the sleep interval – Jaromanda X Apr 30 '18 at 3:22
  • inputs are high-impedance, so adding 470 ohms makes no practical diff – dandavis Apr 30 '18 at 22:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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