ESP8266 NodeMCU Deep Sleep with Arduino IDE

Using the Arduino IDE, this tutorial shows how to use the ESP8266 NodeMCU deep sleep. We'll go over deep sleep with timer wake-up as well as deep sleep with external wake-up using the reset (RST) pin.

To put the ESP8266 into deep sleep mode, use ESP.deepSleep(uS) and pass the sleep time in microseconds as an argument. To wake up the ESP8266, connect GPIO 16 to the reset (RST) pin.

Use ESP.deepSleep(0) to put the ESP8266 into deep sleep mode for an infinite period of time. When the RST pin receives a LOW signal, the ESP8266 will wake up.

Introducing Deep Sleep Mode

If you created a project using a battery-powered ESP8266 board or if you just linked your ESP8266 NodeMCU board to a power bank. After running it for a bit, you realize the battery life is short, especially if you're using Wi-Fi.

Portable Power Sources ESP8266 ESP32

If you put your ESP8266 into deep sleep mode, it reduces power consumption and makes your batteries last longer.

lilygo Official Store

The ESP8266 in deep power sleep mode means cutting down on activities that cost more power while operating (like Wi-Fi) but leaving just enough activity to wake up the processor when anything interesting occurs.

Types of Sleep

Light sleep, deep sleep, and moderate sleep are the three types of sleep modes. The table below shows the differences between each mode (taken from the ESP8266 datasheet).

ItemModem-sleepLight-sleepDeep-sleep
Wi-FiOFFOFFOFF
System clockONOFFOFF
RTCONONON
CPUONPendingOFF
Substrate current15 mA0.4 mA~20 uA
Average current (DTIM = 1)16.2 mA1.8 mA
Average current (DTIM = 3)15.4 mA0.9 mA
Average current (DTIM = 10)15.2 mA0.55 mA

Note: The table's power consumption refers to the ESP8266 as a standalone chip. If you're using a development board, you'll see that it contains more passive components that use more current.

They should all be employed in different applications since they all serve diverse functions.

We'll go over deep sleep mode in this essay. Except for the Real Time Clock (RTC), which is how the ESP8266 keeps track of time, everything is always turned off.

ESP8266 Deep Sleep Mode for Power Saving

This is the most power-efficient alternative, with the ESP chip drawing only around 20 uA. However, you won't be able to attain such a low power state if you use a full-featured development board with a built-in programmer, LEDs, and so on.

keyestudio Official Store

Deep Sleep Sketch

With deep sleep, an example application looks like this:

  1. The ESP8266 connects to Wi-Fi.
  2. The ESP8266 performs a task (reads a sensor, publishes an MQTT message, etc).
  3. Sleeps for a predefined period of time.
  4. The ESP8266 wakes up.
  5. The process is repeated over and over again.

Wake up Sources

After putting the ESP8266 in deep sleep mode, there are different ways to wake it up:

  • #1 timer wake up: the ESP8266 wakes itself up after a predefined period of time.
  • #2 External wake up: the ESP8266 wakes up when you press the RST button (the ESP8266 restarts).

1) ESP8266 NodeMCU Deep Sleep with Timer Wake Up

You need to connect the RST pin to GPIO 16, which is labeled D0, on a NodeMCU board to use timer wake-up with the ESP8266. Simply follow the next schematic diagram:

ESP8266 NodeMCU GPIO16 to RST (Deep Sleep)

After uploading the code, connect the RST pin to GPIO 16 only.

Take a look at the NodeMCU pinout, and you'll see that GPIO 16 is a special pin with a wake feature.

TSCINBUNY Official Store

GPIO 16 Wake Up Pin ESP8266 NodeMCU

Recommended reading: ESP8266 Pinout Reference Guide

While the ESP8266 is running, the RST pin is always HIGH. When the RST pin receives a LOW signal, the microcontroller is restarted.

After you use the ESP8266 to set a deep sleep timer, GPIO 16 delivers a LOW signal after the timer expires. That means that when GPIO 16 is connected to the RST pin, it may wake up the ESP8266 after a set wake period.

ESP8266 NodeMCU Timer Wake Up Sketch

If you have the ESP8266 add-on for Arduino IDE installed (see How to Install the ESP8266 Board in Arduino IDE), go to “Tools” and select “NodeMCU (ESP-12E Module)“. Here is the code you need to upload to your ESP:

/*
 * ESP8266 Deep sleep mode example
 * LEDEdit PRO 
 * Complete Project Details https://lededitpro.com
 */
 
void setup() {
  Serial.begin(115200);
  Serial.setTimeout(2000);

  // Wait for serial to initialize.
  while(!Serial) { }
  
  // Deep sleep mode for 30 seconds, the ESP8266 wakes up by itself when GPIO 16 (D0 in NodeMCU board) is connected to the RESET pin
  Serial.println("I'm awake, but I'm going into deep sleep mode for 30 seconds");
  ESP.deepSleep(30e6); 
  
  // Deep sleep mode until RESET pin is connected to a LOW signal (for example pushbutton or magnetic reed switch)
  //Serial.println("I'm awake, but I'm going into deep sleep mode until RESET pin is connected to a LOW signal");
  //ESP.deepSleep(0); 
}

void loop() {
}

In this example, we print a message in the Serial Monitor:

Serial.println("I'm awake, but I'm going into deep sleep mode until RESET pin is connected to a LOW signal");

After that, the ESP8266 goes to sleep for 30 seconds.

ESP.deepSleep(30e6);

To put the ESP8266 into a deep sleep, you use ESP.deepsleep(uS) and pass as an argument the sleep time in microseconds.

In this case, 30e6 is equivalent to 30000000 microseconds, or 30 seconds.

After uploading the code, press the RST button to start the code running, and then connect RST to GPIO 16. Every 30 seconds, the ESP8266 should wake up and print a message on the Serial Monitor, as shown below.

ESP8266 Deep Sleep with Timer Wake Up ESP8266 Serial Monitor

In this example, you simply print a message to the Serial Monitor, but in a real-world application, you would do a useful task like sending a request, publishing sensor values, and so on.

ESP-01 Timer Wake Up Circuit

If you wish to create a similar setup using an ESP-01 board, you need to solder a wire as shown. GPIO 16 is the tiny pin that needs to be linked to the RST pin.

ESP8266 ESP-01 Enable Timer Wake Up GPIO 16 to RST

However, the pins are so tiny that it is really hard to solder a wire like that to GPIO 16 on the ESP-01. So, for this wake-up mode, you should use the NodeMCU board or a bare ESP12-E chip.

ESP8266 Chip Pinout GPIO 16 pin GPIO

2) ESP8266 NodeMCU Deep Sleep with External Wake Up

You may also wake up the ESP8266 using an external wake-up device, like a button press or a reed switch. To wake up the ESP8266, all you need to do is put it in deep sleep mode for an endless period and then set the RST pin to LOW.

Wire a pushbutton to your ESP8266 board as shown in the schematic diagram below to test this setup at low power. The RST pin goes LOW when you press the pushbutton.

ESP8266 NodeMCU External Wake Up Circuit Schematic Diagram

If you’re using an ESP-01, follow the next diagram instead.

ESP8266 ESP-01 External Wake Up Circuit Schematic Diagram

ESP8266 External Wake Up Sketch

Then, upload the following code to your ESP8266 board.

/*
 * ESP8266 Deep sleep mode example
 * LEDEdit PRO 
 * Complete Project Details https://lededitpro.com
 */
 
void setup() {
  Serial.begin(115200);
  Serial.setTimeout(2000);

  // Wait for serial to initialize.
  while(!Serial) { }
  
  // Deep sleep mode for 30 seconds, the ESP8266 wakes up by itself when GPIO 16 (D0 in NodeMCU board) is connected to the RESET pin
  //Serial.println("I'm awake, but I'm going into deep sleep mode for 30 seconds");
  //ESP.deepSleep(30e6); 
  
  // Deep sleep mode until RESET pin is connected to a LOW signal (for example pushbutton or magnetic reed switch)
  Serial.println("I'm awake, but I'm going into deep sleep mode until RESET pin is connected to a LOW signal");
  ESP.deepSleep(0); 
}

void loop() {
}

This code puts the ESP8266 into deep sleep mode for an indefinite period of time. You just need to pass 0 as an argument to the deepSleep() method to do this:

ESP.deepSleep(0);

When anything resets the board, the ESP will only wake up. In this case, the press of a pushbutton pulls the RST pin to GND.

When you press the pushbutton, the ESP8266 wakes up, does the programmed task, and then goes back to sleep until a new reset event occurs.

Measuring current

When the board is in deep sleep mode, use a multimeter to measure the current consumption to see how much power it is using.

Here’s how you should place your multimeter probes:

Measure Current in Deep Sleep Mode ESP8266

When the ESP-01 is in deep sleep mode, it’s only using 0.3 mA, which is approximately 300 uA.

Measure Current in Deep Sleep Mode ESP8266

Keep in mind that during normal usage with Wi-Fi, the ESP8266 can consume between 50 mA and 170 mA.

If you like ESP8266, you may also like:

We hope you find this tutorial useful. Thanks for reading.

Oh hi there It’s nice to meet you.

Sign up to receive awesome content in your inbox, every month.

We don’t spam! Read our privacy policy for more info.

Leave a Reply

Your email address will not be published. Required fields are marked *

ESP8266 Home Automation Projects

Leverage the power of this tiny WiFi chip to build exciting smart home projects