This guide shows how to use deep sleep with the ESP8266 (NodeMCU) using Arduino IDE. We’ll cover deep sleep with timer wake up and deep sleep with external wake up using the reset (RST) pin.

To put the ESP8266 in deep sleep mode, use ESP.deepSleep(uS) and pass as argument sleep time in microseconds. GPIO 16 must be connected to reset (RST) pin so the ESP8266 is able to wake up.
To put the ESP8266 in deep sleep mode for an indefinite period of time use ESP.deepSleep(0). The ESP8266 will wake up when the RST pin receives a LOW signal.
//video
Introducing Deep Sleep Mode
If you’ve made a project with an ESP8266 board that is battery powered, or if you just connected your ESP8266 NodeMCU board to a power bank. After running it for a while, you realize the battery doesn’t last long, specially if you’re using Wi-Fi.

If you put your ESP8266 in deep sleep mode, it reduces power consumption and your batteries will last longer.
Having the ESP8266 in deep sleep mode means cutting with the activities that consume more power while operating (like Wi-Fi) but leave just enough activity to wake up the processor when something interesting happens.
Types of Sleep
There are three different types of sleep mode: modem sleep, light sleep, and deep sleep. The table below shows the differences between each mode (information from the ESP8266 datasheet).
Item | Modem-sleep | Light-sleep | Deep-sleep |
Wi-Fi | OFF | OFF | OFF |
System clock | ON | OFF | OFF |
RTC | ON | ON | ON |
CPU | ON | Pending | OFF |
Substrate current | 15 mA | 0.4 mA | ~20 uA |
Average current (DTIM = 1) | 16.2 mA | 1.8 mA | – |
Average current (DTIM = 3) | 15.4 mA | 0.9 mA | – |
Average current (DTIM = 10) | 15.2 mA | 0.55 mA | – |
They all have different purposes and they should be used in different applications.
In this article, we’ll cover deep sleep mode. Everything is always off, except the Real Time Clock (RTC), which is how the ESP8266 keeps track of time.

This is the most power efficient option and the ESP chip only draws approximately 20uA. However, if you use a full-feature development board with built-in programmer, LEDs, and so on, you won’t be able to achieve such a low power state.
Deep Sleep Sketch
With deep sleep, an example application looks like this:
- The ESP8266 connects to Wi-Fi
- The ESP8266 performs a task (reads a sensor, publishes an MQTT message, etc)
- Sleeps for a predefined period of time
- The ESP8266 wakes up
- 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)
For low-power projects, you might consider using the ESP32 board which offers more deep sleep modes and wake up sources.
#1 ESP8266 Deep Sleep with Timer Wake Up
To use timer wake up with ESP8266, you need to connect the RST pin to GPIO 16 which is labeled as D0, in a NodeMCU board. Simply follow the next schematic diagram:

Connect the RST pin to GPIO 16 only after uploading the code.
If you take a look at the NodeMCU pinout, you can see that GPIO 16 is a special pin and it has a WAKE feature.

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 the RST pin, can wake up the ESP8266 after a set period of time.
ESP8266 NodeMCU Timer Wake Up Sketch
Having the ESP8266 add-on for Arduino IDE installed (how to Install the ESP8266 Board in Arduino IDE), go to Tools and select “NodeMCU (ESP-12E Module)”. Here’s the code that you need to upload to your ESP:
/*
Welcomr to Gnd_To_vcc!!
*/
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 in deep sleep, you use ESP.deepsleep(uS) and pass as argument the sleep time in microseconds.
In this case, 30e6 corresponds to 30000000 microseconds which is equal to 30 seconds.
After uploading the code, press the RST button to start running the code, and then connect RST to GPIO 16. The ESP8266 should wake up every 30 seconds and print a message in the Serial Monitor as shown below.

This example simply prints a message in the Serial Monitor, but in a real world application, you’ll perform a useful task like making a request, publish sensor readings, etc.
ESP-01 Timer Wake Up Circuit
If you want to make a similar setup with an ESP-01 board, you need to solder a wire as shown below. That tiny pin is GPIO 16 and it needs to be connected to RST pin.

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.

#2 ESP8266 Deep Sleep with External Wake Up
You can also wake up the ESP8266 with an external wake up, like the press of a button or a read switch. You just need to put the ESP8266 in deep sleep mode for an indefinite period of time, and then set the RST pin to LOW to wake it up.
To test this setup, wire a pushbutton to your ESP8266 board as shown in the following schematic diagram. When you press the pushbutton, the RST pin goes LOW.

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

ESP8266 External Wake Up Sketch
Then, upload the following code to your ESP8266 board.
/*
* ESP8266 Deep sleep mode example
Welcome to Gnd_To_Vcc!!
*/
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 in deep sleep mode for an indefinite period of time. For that, you just need to pass 0 as an argument to the deepSleep() function:
ESP.deepSleep(0);
The ESP will only wake up when something resets the board. In this case, it’s the press of a pushbutton that pulls the RST pin to GND.
When you press the pushbutton, the ESP8266 wakes up, does the programmed task and goes back to sleep until a new reset event is triggered.
Measuring current
When the board is in deep sleep mode, measure the current consumption with a multimeter to see how much power it is draining.

Here’s how you should place your multimeter probes.
When the ESP-01 is in deep sleep mode it’s only using 0.3mA which is approximately 300uA.

Keep in mind that during normal usage with Wi-Fi the ESP8266 can consume between 50mA and 170mA.
Conclusion
Now that you know how to use the deepSleep() function, your battery powered project can last longer.
You may also like other ESP8266 projects:
- ESP8266 Wi-Fi Button – DIY Amazon Dash Button Clone
- ESP8266: DHT Temperature and Humidity Readings in OLED Display
- Hack a PIR Motion Sensor with an ESP8266
- How to Use a Multimeter – Beginner’s Guide
We have other guides about deep sleep that you might be interested in:
- MicroPython: ESP32 Deep Sleep and Wake Up Sources
- MicroPython: ESP8266 Deep Sleep and Wake Up Sources
- ESP32 Deep Sleep with Arduino IDE and Wake Up Sources
I hope this guide was useful. Thanks for reading!
7 thoughts on “ESP8266 Deep Sleep with Arduino IDE (NodeMCU)”