ESP8266 Deep Sleep with Arduino IDE (NodeMCU)

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.

ESP-01 ESP8266 NodeMCU Deep Sleep with Arduino IDE

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.

Watch the Video Tutorial

This guide is available in video format (watch below) and in written format (continue reading this page).

Related Content: ESP32 Deep Sleep with Arduino IDE and Wake Up Sources

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.

Portable Power Sources ESP8266 ESP32

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).

System clockONOFFOFF
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

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.

ESP8266 Deep Sleep Mode for Power Saving

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:

  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)

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:

ESP8266 NodeMCU GPIO16 to RST (Deep Sleep)

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.

GPIO 16 Wake Up Pin ESP8266 NodeMCU

Recommended reading: ESP8266 Pinout Reference 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 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:

 * ESP8266 Deep sleep mode example
 * Rui Santos 
 * Complete Project Details
void setup() {

  // 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");
  // 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");

void loop() {

View raw code

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.


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.

ESP8266 Deep Sleep with Timer Wake Up ESP8266 Serial Monitor

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.

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

Recommended reading: ESP8266 Pinout Reference

#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 reed 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.

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
 * Rui Santos 
 * Complete Project Details
void setup() {

  // 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");
  // 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");

void loop() {

View raw code

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:


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.

Measure Current in Deep Sleep Mode ESP8266

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

Measure Current in Deep Sleep Mode ESP8266

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

Wrapping up

Now that you know how to use the deepSleep() function, your battery powered project can last longer.

ESP8266 Deep Sleep and Wake Up Sources

You may also like other ESP8266 projects:

We have other guides about deep sleep that you might be interested in:

This is an excerpt from my Home Automation using ESP8266 eBook. If you like ESP8266 and you want to learn more about it. I recommend downloading my course: Home Automation using ESP8266.

I hope this guide was useful. Thanks for reading!

Updated July 29, 2019

Learn how to program and build projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD »

Learn how to program and build projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our weekly newsletter!

57 thoughts on “ESP8266 Deep Sleep with Arduino IDE (NodeMCU)”

  1. Thank you for wonderful explanation.
    In your explanation, you mentioned ESP-01 its hard to solder the GPIO16 to Reset.
    However in Live example you have used ESP-01 to show connect circuit and, I did not figure out how you managed to solder the GPIO to Reset? (I notice you had a Green PCB below the ESP-01 though, not sure if that did the trick)

    Question is: Can you advise how one can use ESP-01 with deepSleep()? If it really needs the Solder then what is trick to do it?

    • I managed to solder a very thin wire to GPIO 16, and that’s the only way to do it… At least I don’t know any other tricks to do it. (The green PCB only made the ESP-01 breadboard friendly..)

  2. Hi, I am using the code with a NodeMCU board, and I have a consumption of 11m [A] in deep-sleep mode and I do not know why I can´t have 20 u [A].

    • Hello Luciano,
      The ESP8266 chip might consume 20 uA, but the NodeMCU board has many passive components that consume a lot of current, so it has a bad performance. For a real world solution, you should use the ESP8266 chip in a custom PCB board to lower the power consumption.

  3. Great tutorial, many thanks.


    P.S. You have reversed the terminals of the amp-meter. Proof: from the power source follow its positive terminal, which is connected to a red wire, which then is connected to the black lead of the amp-meter, which is connected to the common (negative) terminal on the amp-meter. Therefore the current will flow through the amp-meter from its negative to its positive terminal, which is in reverse. A digital amp-meter will show

  4. (cont) a digital amp-meter will show a negative number, an analogue one will show its needle struggling to turn left beyond the zero mark and/or pushing against the small vertical pin just left of tbe zero mark.

    Apologies for the interrupted post (fingers trouble).

    • Hi Plamen.
      You are right. We’ve switch the red probe with the black probe.
      In the case of a digital multimeter, the only difference is that we see a negative number.
      But it can be problematic using an analog multimeter, you are right!
      Thank you for noticing that and sharing it with us.
      Sara 🙂

  5. When I run the sleep routine it crashes after the set time (prints out garbage and then restarts) this is both on an Node MCU and an ESP-01 with the hardware modified. Any comment?

  6. Hi Dear
    In this article, you say:
    “Now, when I press the pushbutton the ESP wakes up does some action, in this case it prints a message in the Arduino IDE serial monitor. After a few milliseconds it goes to Deep Sleep”.

    The way I programmed the ESP8266 – 01 is by using an FTDI to do the communication. To do this, it requires some cable connections between them. I have done that in my breadboard and code was downloaded successfully on the ESP01. In a second breadboard, I built the circuit with the push button, which seems to work ok (every time I push the button, the light flashes). But I have 2 problems:
    1- How am I gonna check on the Serial Monitor if ESP is not connected to my PC?
    2- Im using a Li-Ion Battery 3.7v to power the circuit. I used my digi muiltimeter to measure the current. It shows 22mA. I think this is way to high.

    • Hi Diego.
      if your ESP is not connected to your computer, you can connect an LED and add a few lines of code to blink the LED when the ESP wakes up. This way you can keep that that woken up.
      It shows 22mA in deep sleep mode?
      Sara 🙂

  7. Hey,could you please guide me here…I want my nodeMCU to go to deep sleep just after connecting to client as a server and send data to it…….when i get it to practice,and go for web page formed ,my esp goes to deepsleep and i cant get any data!!!!
    now,is there a way in which i can use both the properties of nodeMCU,ie. i want it to connect to server then send data then go to deep sleep

    • Hi Sabi.
      Are you using the same ESP to send data and host the web server?
      When the ESP is in deep sleep you can’t access the web server because it is sleeping, so it can’t respond to client requests.

  8. hiii
    we want code for esp8266 with temperature sensor(ds18b20)
    we want some feature in our code
    if you interested to write sketch for us
    please inform us with your quotation

  9. Thanks very much: I want to do some battery-operated temperature sensors, and needed info on how to do deep sleep. This is just what I needed (including, alas, the fact that the soldering to use my ESP-01s is too fiddly for an old through-hole guy. 🙁 Ah, well: ESP-12s are cheap now…).

  10. Hi Sara,

    I have ESP8266-01 module and Arduino UNO.

    I have connected VCC and CH_PD of ESP8266 with 3.3V of Arduino UNO, GND with GND and RX and TX of ESP8266 with Pin 4 and 3 respectively of Arduino UNO. They both are working accordingly.

    Now to enable deep sleep mode:
    1. After the soldering of GPIO16 and RST, is there need to install ESP8266 board on IDE or by just simply writing the code will work as I have already connected ESP with Arduino IDE.

    2. Except soldering and NodeMCU, by just writing the code deep sleep mode work?

    3. Is there need to include library of ESPWIFI.h in my code?

  11. Hello

    I am working on ESP 8266 and I have a doubt in the deep-sleep function along with auto-connection, I saw that on the site that has an example with auto-connection but and providing the SSID and password of the WIFI network.

    Could you help me get an idea

    Thank you very much in advance

  12. Hi Sara. Is there any similar way that will allow me to wake up?
    The problem is I have only 3 seconds for the reed-switch and I need to connect and send web request. So not enough time even with static IP. Thank you in advance. Majo

  13. Ah, I just spotted it. I don’t have any ESP-01s so I didn’t know they had a “power on LED”. That’s why your minimum current is ~ 300uA. A red LED’s forward voltage is ~ 1.8V, so (3.3V – 1.8V) / 4700 (the current limiting resistor) = 313uA. It looks like it’s at the limit of your meter’s range, so 333uA (including the 20uA) is shown as 0.3mA. My Fluke has lower ranges. 🙂 One of the other Espressif docs showed the 20uA Deep Sleep current as being at 3.6V and I was running my D1 Mini a hair over 3V, so 16uA for me.

    • can you show the exact circuit you use to have a 16uA?
      I’ve see also that there is a ‘sleep’ contact behind the d1 mini, what is it for ?

  14. If you want to play with some other low-power modes, the Low-Power demo is released,
    It includes the elusive Timed/Forced Light Sleep that took *lots* of googling to figure out how to engage. Forced Light Sleep only sleeps at ~360 to 380uA, but it recovers with an interrupt in less than 5ms, compared to the 120ms+ that Deep Sleep takes to boot, and your program doesn’t have to start from scratch afterwards.

  15. Rui and Sara,

    Loved the video. However, you missed an important use case that I have been struggling with. I have a Feather that I want to put into deepsleep with a switch. The switch is too be used to turn both on and off. In the above ESP.deepSleep(0) code, the switch is only used to turn back on.

    While you might say just use the EN-GND pin (, I don’t know of a way to run code before the power is turned off, which is needed.

    Can you provide any suggestions? Is there any documentation I can look at. I have had no success in finding anything in my own searches.

    Thanks in advance.

  16. Hello,
    I have a very important decision to take based in the wake up from deep sleep.
    If ESP32, or ESP8266 can wake up from deep sleep based on RX pin status, then i use ESP. If not i have to use a regular transceiver.
    What is all about. I have an RFID reader connected to an NodeMcu – ESP8266 RX pin.
    When i read a card, i send the numbers of the card to a second ESP.
    I must use Deep sleep for ESP board as it is powered by batteries. I must wake up the ESP only when i do a read with the RFID reader, and this transmit the ID of the card to ESP RX pin.
    Between that, full deep sleep. I do not need RTC, no Wifi, no nothing. Just the ESP sleeping.
    Please help me on this.
    Thank you

  17. ESP.deepSleep(0) is misleading as the ESP8266 cannot sleep for more than ~3.5h at the time. I think you should mention that. Great article otherwise!

    See for details.

  18. Hi
    You put a lot of effort into these tutorials – thank you.
    I’ve got a Wemos ESP8266 board with an integrated 18650 battery. I want to use it to monitor the oil boiler (input and output temperature and burn time) which has no mains nearby other than the demand.
    I’d like to be able to put it into deep sleep to be woken up when it gets power through the micro USB charging input (ie when the demand mains power is back on).
    My only thought is to use a transistor to draw the RST down to ground when power is applied. Some research and fiddly soldering to get to the signal i need and the RST pin which is not on the header.
    Any advice would be appreciated.

    • Maybe i misunderstand your requirements but I think you should be able to to use the transistor to connect and disconnect the GND of the ESP. That way it just powers off when there is no charge on the demand. And it powers back up when the demand switches on. Ofcourse you do need to put it to sleep when done so uses less power.I guess it’s not needed, but If you want the ESP to reset itself periodically during the demand is on. Then you could can solder GPIO16 to reset.

      • Lauren – Thanks for replying.
        I really want the unit to be running all the time and reporting instantly when the burner is turned on or off. Also i want the temperatures reported every minute or so. Reporting is over WiFi to an MQTT broker and Home Assistant. When the boiler is off for a while temperature reporting can be at a greater interval.
        I was thinking I could wake up every minute to report temperature but wanted the appliance of power to also wake the unit up to give more accuracy to burn timings (which I will equate to oil consumption in Home Assistant).
        The battery will keep the thing going for over a day if i use modem sleep but I’m not sure if the charge will be sufficient in the summer when the boiler is only used for hot water. Still considering my options.
        My board has an LED on GPIO16 and it does not wake the unit up from deep sleep (I’ve just found this out). The LED does comes on at the end of the sleep period, but when connected to the RST it goes off again but does not restart the sketch.
        Maybe I’ll just let the battery run out when no meaningful measurements can be taken and the unit will restart pretty much as soon as the power is applied. Just doesn’t seem very professional.

        • Aha yes that makes sense.

          Having both the timer and a external wakeup is exactly what i wasn’t able to get working either.

          In my most recent project i used an ATTINY13 for that purpose. I programmed the Attiny to wakeup when it gets an interrupt (in my case from a PIR Sensor) and i also programmed a watchdog so it always wakes up after 2 minutes of sleep. When the Attiny wakes up i put a GPIO to a transistor HIGH and then connect the ESP GND that way. I forward the input of the Interrupt PIN via a GPIO to the ESP so it knows if the PIR (Could be your “demand” input) was high or LOW.

          First step in ESP is to put a GPIO from ESP to ATTINY to HIGH so it knows the ESP is awake. After the sketch of the ESP is done, just before deepsleep (not sure if it’s really needed) i put that GPIO to LOW so ATTINY knows it can go to sleep and therefor it will also disconnect the GND of the ESP again.

          Attiny is more efficient in Deepsleep than ESP so it’s also a battery saver.

          • I’ve done some testing and coding using light sleep (which I can waken with other GPIOs).
            Running it consumes about 50mA and in light sleep less than 10mA. So with the right duty cycle I get the average current about 10mA. The battery will keep it going for 12 days. It charges at about 0.5A so it only needs to be powered for 30 minutes each day (250mAh). I should get away with that in the summer.
            Now to code for real! Nothing else to do during lockdown!

Leave a Comment

Download our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.