{"id":44608,"date":"2019-07-29T16:59:29","date_gmt":"2019-07-29T16:59:29","guid":{"rendered":"http:\/\/randomnerdtutorials.com\/?p=44608"},"modified":"2021-11-16T15:57:29","modified_gmt":"2021-11-16T15:57:29","slug":"esp8266-deep-sleep-with-arduino-ide","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp8266-deep-sleep-with-arduino-ide\/","title":{"rendered":"ESP8266 Deep Sleep with Arduino IDE (NodeMCU)"},"content":{"rendered":"\n<p>This guide shows how to use deep sleep with the ESP8266 (NodeMCU) using Arduino IDE. We&#8217;ll cover deep sleep with timer wake up and deep sleep with external wake up using the reset (RST) pin.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/Deep-sleep-blog-1280.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP-01 ESP8266 NodeMCU Deep Sleep with Arduino IDE\" class=\"wp-image-44653\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/Deep-sleep-blog-1280.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/Deep-sleep-blog-1280.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/Deep-sleep-blog-1280.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/Deep-sleep-blog-1280.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n\n<p class=\"rntbox rntclblue\">To put the ESP8266 in deep sleep mode, use <span class=\"rnthl rntliteral\">ESP.deepSleep(uS)<\/span> 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.<\/p>\n\n\n\n<p class=\"rntbox rntclgreen\">To put the ESP8266 in deep sleep mode for an indefinite period of time use <span class=\"rnthl rntliteral\">ESP.deepSleep(0)<\/span>. The ESP8266 will wake up when the RST pin receives a LOW signal.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Watch the Video Tutorial<\/h2>\n\n\n\n<p><em>This guide is available in video format (watch below) and in written format (continue reading this page).<\/em><\/p>\n\n\n<p style=\"text-align:center\"><iframe width=\"720\" height=\"405\" src=\"https:\/\/www.youtube.com\/embed\/Q8GT-GBH7ok?rel=0\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n\n\n\n<p><strong>Related Content:<\/strong> <a href=\"https:\/\/randomnerdtutorials.com\/esp32-deep-sleep-arduino-ide-wake-up-sources\/\">ESP32 Deep Sleep with Arduino IDE and Wake Up Sources<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introducing Deep Sleep Mode<\/h2>\n\n\n\n<p>If you\u2019ve 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\u2019t last long, specially if you&#8217;re using Wi-Fi.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"858\" height=\"295\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/Slide3-Copy.png?resize=858%2C295&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Portable Power Sources ESP8266 ESP32\" class=\"wp-image-44615\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/Slide3-Copy.png?w=858&amp;quality=100&amp;strip=all&amp;ssl=1 858w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/Slide3-Copy.png?resize=300%2C103&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/Slide3-Copy.png?resize=768%2C264&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 858px) 100vw, 858px\" \/><\/figure><\/div>\n\n\n\n<p>If you put your ESP8266 in deep sleep mode, it reduces power consumption and your batteries will last longer. <\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Types of Sleep<\/h3>\n\n\n\n<p>There are three different types of sleep mode: <strong>modem sleep<\/strong>, <strong>light sleep<\/strong>, and <strong>deep sleep<\/strong>. The table below shows the differences between each mode (information from the ESP8266 datasheet).<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-regular\"><table><tbody><tr><td><strong>Item<\/strong><\/td><td><strong>Modem-sleep<\/strong><\/td><td><strong>Light-sleep<\/strong><\/td><td><strong>Deep-sleep<\/strong><\/td><\/tr><tr><td><strong>Wi-Fi<\/strong><\/td><td>OFF<\/td><td>OFF<\/td><td>OFF<\/td><\/tr><tr><td><strong>System clock<\/strong><\/td><td>ON<\/td><td>OFF<\/td><td>OFF<\/td><\/tr><tr><td><strong>RTC<\/strong><\/td><td>ON<\/td><td>ON<\/td><td>ON<\/td><\/tr><tr><td><strong>CPU<\/strong><\/td><td>ON<\/td><td>Pending<\/td><td>OFF<\/td><\/tr><tr><td><strong>Substrate current<\/strong><\/td><td>15 mA<\/td><td>0.4 mA<\/td><td>~20 uA<\/td><\/tr><tr><td><strong>Average current (DTIM = 1)<\/strong><\/td><td>16.2 mA<\/td><td>1.8 mA<\/td><td>&#8211;<\/td><\/tr><tr><td><strong>Average current (DTIM = 3) <\/strong><\/td><td>15.4 mA<\/td><td>0.9 mA<\/td><td>&#8211;<\/td><\/tr><tr><td><strong>Average current (DTIM = 10) <\/strong><\/td><td>15.2 mA<\/td><td>0.55 mA<\/td><td>&#8211;<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"rntbox rntclgray\"><strong>Note: <\/strong> the power consumption on the table refers to the ESP8266 as a standalone chip. If you&#8217;re using a development board, they have passive components that use more current.<\/p>\n\n\n\n<p>They all have different purposes and they should be used in different applications.<\/p>\n\n\n\n<p>In this article, we&#8217;ll cover deep sleep mode. Everything is always off, except the Real Time Clock (RTC), which is how the ESP8266 keeps track of time.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"600\" height=\"210\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/Slide10.png?resize=600%2C210&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 Deep Sleep Mode for Power Saving\" class=\"wp-image-44618\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/Slide10.png?w=600&amp;quality=100&amp;strip=all&amp;ssl=1 600w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/Slide10.png?resize=300%2C105&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/figure><\/div>\n\n\n\n<p>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\u2019t be able to achieve such a low power state.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Deep Sleep Sketch<\/h3>\n\n\n\n<p>With deep sleep, an example application looks like this:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>The ESP8266 connects to Wi-Fi<\/li><li>The ESP8266 performs a task (reads a sensor, publishes an MQTT message, etc)<\/li><li>Sleeps for a predefined period of time<\/li><li>The ESP8266 wakes up<\/li><li>The process is repeated over and over again<\/li><\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Wake up Sources<\/h3>\n\n\n\n<p>After putting the ESP8266 in deep sleep mode, there are different ways to wake it up:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>#1 timer wake up:<\/strong> the ESP8266 wakes itself up after a predefined period of time<\/li><li><strong>#2 external wake up:<\/strong> the ESP8266 wakes up when you press the RST button (the ESP8266 restarts)<\/li><\/ul>\n\n\n\n<p>For low-power projects, you might consider using the ESP32 board which offers more <a href=\"https:\/\/randomnerdtutorials.com\/esp32-deep-sleep-arduino-ide-wake-up-sources\/\">deep sleep modes and wake up sources<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">#1 ESP8266 Deep Sleep with Timer Wake Up<\/h2>\n\n\n\n<p>To use timer wake up with ESP8266, you need to connect the RST pin to GPIO 16 which is labeled as D0, in a <a href=\"https:\/\/makeradvisor.com\/tools\/esp8266-esp-12e-nodemcu-wi-fi-development-board\/\">NodeMCU board<\/a>. Simply follow the next schematic diagram:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"579\" height=\"389\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/enable_deep_sleep_esp8266.png?resize=579%2C389&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 NodeMCU GPIO16 to RST (Deep Sleep)\" class=\"wp-image-85349\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/enable_deep_sleep_esp8266.png?w=579&amp;quality=100&amp;strip=all&amp;ssl=1 579w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/enable_deep_sleep_esp8266.png?resize=300%2C202&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 579px) 100vw, 579px\" \/><\/figure><\/div>\n\n\n\n<p>Connect the RST pin to GPIO 16 only after uploading the code.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"785\" height=\"584\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/Slide14-i.jpg?resize=785%2C584&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"GPIO 16 Wake Up Pin ESP8266 NodeMCU\" class=\"wp-image-44624\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/Slide14-i.jpg?w=785&amp;quality=100&amp;strip=all&amp;ssl=1 785w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/Slide14-i.jpg?resize=300%2C223&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/Slide14-i.jpg?resize=768%2C571&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 785px) 100vw, 785px\" \/><\/figure><\/div>\n\n\n\n<p class=\"rntbox rntclblue\"><strong>Recommended reading:<\/strong> <a href=\"https:\/\/randomnerdtutorials.com\/esp8266-pinout-reference-gpios\/\">ESP8266 Pinout Reference Guide<\/a><\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">ESP8266 NodeMCU Timer Wake Up Sketch<\/h3>\n\n\n\n<p>Having the ESP8266 add-on for Arduino IDE installed (<a rel=\"noreferrer noopener\" href=\"https:\/\/randomnerdtutorials.com\/how-to-install-esp8266-board-arduino-ide\/\" target=\"_blank\">how to Install the ESP8266 Board in Arduino IDE<\/a>), go to <strong>Tools<\/strong> and select \u201c<strong>NodeMCU (ESP-12E Module)<\/strong>\u201d. Here&#8217;s the code that you need to upload to your ESP:<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n * ESP8266 Deep sleep mode example\n * Rui Santos \n * Complete Project Details http:\/\/randomnerdtutorials.com\n *\/\n \nvoid setup() {\n  Serial.begin(115200);\n  Serial.setTimeout(2000);\n\n  \/\/ Wait for serial to initialize.\n  while(!Serial) { }\n  \n  \/\/ 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\n  Serial.println(&quot;I'm awake, but I'm going into deep sleep mode for 30 seconds&quot;);\n  ESP.deepSleep(30e6); \n  \n  \/\/ Deep sleep mode until RESET pin is connected to a LOW signal (for example pushbutton or magnetic reed switch)\n  \/\/Serial.println(&quot;I'm awake, but I'm going into deep sleep mode until RESET pin is connected to a LOW signal&quot;);\n  \/\/ESP.deepSleep(0); \n}\n\nvoid loop() {\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/DeepSleep\/deep_sleep_esp12E.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>In this example, we print a message in the Serial Monitor:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.println(\"I'm awake, but I'm going into deep sleep mode until RESET pin is connected to a LOW signal\");<\/code><\/pre>\n\n\n\n<p>After that, the ESP8266 goes to sleep for 30 seconds.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>ESP.deepSleep(30e6);<\/code><\/pre>\n\n\n\n<p>To put the ESP8266 in deep sleep, you use <span class=\"rnthl rntliteral\">ESP.deepsleep(uS)<\/span> and pass as argument the sleep time in microseconds.<\/p>\n\n\n\n<p>In this case, 30e6 corresponds to 30000000 microseconds which is equal to 30 seconds.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"692\" height=\"445\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/esp8266-deep-sleep-timer-wake-up-serial-monitor.png?resize=692%2C445&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 Deep Sleep with Timer Wake Up ESP8266 Serial Monitor\" class=\"wp-image-87670\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/esp8266-deep-sleep-timer-wake-up-serial-monitor.png?w=692&amp;quality=100&amp;strip=all&amp;ssl=1 692w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/07\/esp8266-deep-sleep-timer-wake-up-serial-monitor.png?resize=300%2C193&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 692px) 100vw, 692px\" \/><\/figure><\/div>\n\n\n\n<p>This example simply prints a message in the Serial Monitor, but in a real world application, you&#8217;ll perform a useful task like making a request, publish sensor readings, etc. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">ESP-01 Timer Wake Up Circuit<\/h3>\n\n\n\n<p>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.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"199\" height=\"296\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/esp-01.png?resize=199%2C296&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 ESP-01 Enable Timer Wake Up GPIO 16 to RST\" class=\"wp-image-44609\"\/><\/figure><\/div>\n\n\n\n<p>However, the pins are so tiny that it is really hard to solder a wire like that to GPIO 16 on the ESP-01\u2026 So, for this wake up mode you should use the <a href=\"https:\/\/randomnerdtutorials.com\/esp8266-pinout-reference-gpios\/\">NodeMCU board or a bare ESP12-E chip<\/a>.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"773\" height=\"715\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/Slide21.png?resize=773%2C715&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 Chip Pinout GPIO 16 pin GPIO\" class=\"wp-image-44620\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/Slide21.png?w=773&amp;quality=100&amp;strip=all&amp;ssl=1 773w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/Slide21.png?resize=300%2C277&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/Slide21.png?resize=768%2C710&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 773px) 100vw, 773px\" \/><\/figure><\/div>\n\n\n\n<p><strong>Recommended reading:<\/strong> <a href=\"https:\/\/randomnerdtutorials.com\/esp8266-pinout-reference-gpios\/\">ESP8266 Pinout Reference<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"external\">#2 ESP8266 Deep Sleep with External Wake Up<\/h2>\n\n\n\n<p>You can also wake up the ESP8266 with an external wake up, like the press of a button or a <a href=\"https:\/\/randomnerdtutorials.com\/door-status-monitor-using-the-esp8266\/\">reed switch<\/a>. 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. <\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"895\" height=\"567\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/esp8266-external-wake-up-micropython_bb.png?resize=895%2C567&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 NodeMCU External Wake Up Circuit Schematic Diagram\" class=\"wp-image-85374\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/esp8266-external-wake-up-micropython_bb.png?w=895&amp;quality=100&amp;strip=all&amp;ssl=1 895w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/esp8266-external-wake-up-micropython_bb.png?resize=300%2C190&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/05\/esp8266-external-wake-up-micropython_bb.png?resize=768%2C487&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 895px) 100vw, 895px\" \/><\/figure><\/div>\n\n\n\n<p> If you\u2019re using an&nbsp;<a href=\"https:\/\/makeradvisor.com\/tools\/esp-01-wi-fi-board\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">ESP-01<\/a>, follow the next diagram instead.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"668\" height=\"770\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/esp-01-pushbutton_bb.png?resize=668%2C770&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 ESP-01 External Wake Up Circuit Schematic Diagram\" class=\"wp-image-44610\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/esp-01-pushbutton_bb.png?w=668&amp;quality=100&amp;strip=all&amp;ssl=1 668w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/esp-01-pushbutton_bb.png?resize=260%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 260w\" sizes=\"(max-width: 668px) 100vw, 668px\" \/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">ESP8266 External Wake Up Sketch<\/h3>\n\n\n\n<p>Then, upload the following code to your ESP8266 board.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n * ESP8266 Deep sleep mode example\n * Rui Santos \n * Complete Project Details http:\/\/randomnerdtutorials.com\n *\/\n \nvoid setup() {\n  Serial.begin(115200);\n  Serial.setTimeout(2000);\n\n  \/\/ Wait for serial to initialize.\n  while(!Serial) { }\n  \n  \/\/ 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\n  \/\/Serial.println(&quot;I'm awake, but I'm going into deep sleep mode for 30 seconds&quot;);\n  \/\/ESP.deepSleep(30e6); \n  \n  \/\/ Deep sleep mode until RESET pin is connected to a LOW signal (for example pushbutton or magnetic reed switch)\n  Serial.println(&quot;I'm awake, but I'm going into deep sleep mode until RESET pin is connected to a LOW signal&quot;);\n  ESP.deepSleep(0); \n}\n\nvoid loop() {\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/DeepSleep\/deep_sleep_esp01.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>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 <span class=\"rnthl rntliteral\">deepSleep()<\/span> function:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>ESP.deepSleep(0);<\/code><\/pre>\n\n\n\n<p>The ESP will only wake up when something resets the board. In this case, it&#8217;s the press of a pushbutton that pulls the RST pin to GND.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Measuring current<\/h2>\n\n\n\n<p>When the board is in deep sleep mode, measure the current consumption with a <a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/makeradvisor.com\/best-multimeters-under-50\/\" target=\"_blank\">multimeter <\/a>to see how much power it is draining.<\/p>\n\n\n\n<p>Here\u2019s how you should place your multimeter probes.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"761\" height=\"1021\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/Slide25.png?resize=761%2C1021&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Measure Current in Deep Sleep Mode ESP8266\" class=\"wp-image-44621\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/Slide25.png?w=761&amp;quality=100&amp;strip=all&amp;ssl=1 761w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/Slide25.png?resize=224%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 224w\" sizes=\"(max-width: 761px) 100vw, 761px\" \/><\/figure><\/div>\n\n\n\n<p>When the ESP-01 is in deep sleep mode it\u2019s only using 0.3mA which is approximately 300uA.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"345\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/multimeter.jpg?resize=750%2C345&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Measure Current in Deep Sleep Mode ESP8266\" class=\"wp-image-44623\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/multimeter.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/multimeter.jpg?resize=300%2C138&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>Keep in mind that during normal usage with Wi-Fi the ESP8266 can consume between 50mA and 170mA.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping up<\/h2>\n\n\n\n<p>Now that you know how to use the <span class=\"rnthl rntliteral\">deepSleep()<\/span> function, your battery powered project can last longer.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"342\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/last-i.jpg?resize=800%2C342&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 Deep Sleep and Wake Up Sources\" class=\"wp-image-44625\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/last-i.jpg?w=800&amp;quality=100&amp;strip=all&amp;ssl=1 800w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/last-i.jpg?resize=300%2C128&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/last-i.jpg?resize=768%2C328&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/figure><\/div>\n\n\n\n<p>You may also like other ESP8266 projects:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-wi-fi-button-diy-amazon-dash-button-clone\/\">ESP8266 Wi-Fi Button \u2013 DIY Amazon Dash Button Clone<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-dht-temperature-and-humidity-oled-display\/\">ESP8266: DHT Temperature and Humidity Readings in OLED Display<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/hack-pir-motion-sensor-esp8266-hlk-pm03\/\">Hack a PIR Motion Sensor with an ESP8266<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/how-to-use-a-multimeter\/\">How to Use a Multimeter \u2013 Beginner\u2019s Guide<\/a><\/li><\/ul>\n\n\n\n<p>We have other guides about deep sleep that you might be interested in:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/micropython-esp32-deep-sleep-wake-up-sources\/\"><strong>MicroPython<\/strong>: <strong>ESP32 <\/strong>Deep Sleep and Wake Up Sources<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/micropython-esp8266-deep-sleep-wake-up-sources\/\"><strong>MicroPython<\/strong>: <strong>ESP8266 <\/strong>Deep Sleep and Wake Up Sources<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-deep-sleep-arduino-ide-wake-up-sources\/\"><strong>ESP32 <\/strong>Deep Sleep with <strong>Arduino IDE<\/strong> and Wake Up Sources<\/a><\/li><\/ul>\n\n\n\n<p><em>This is an excerpt<\/em> from my <a href=\"https:\/\/randomnerdtutorials.com\/home-automation-using-esp8266\/\">Home Automation using ESP8266 eBook<\/a>. If you like ESP8266 and you want to learn more about it. I recommend downloading my course: <a href=\"https:\/\/randomnerdtutorials.com\/home-automation-using-esp8266\/\">Home Automation using ESP8266<\/a>.<\/p>\n\n\n\n<p>I hope this guide was useful. Thanks for reading!<\/p>\n\n\n\n<p><em>Updated July 29, 2019<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This guide shows what\u2019s Deep Sleep and how to use it with the ESP8266 in the Arduino IDE. If you use the sleep functions with the ESP8266 it will save you power and ultimately your batteries will last longer. <\/p>\n<p class=\"read-more-container\"><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-deep-sleep-with-arduino-ide\/\" class=\"read-more button\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":1,"featured_media":44653,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[2,245,265,300,269,264],"tags":[],"class_list":["post-44608","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino","category-arduino-ide","category-esp8266-project","category-0-esp8266","category-guide-project","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/Deep-sleep-blog-1280.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/44608","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=44608"}],"version-history":[{"count":3,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/44608\/revisions"}],"predecessor-version":[{"id":107895,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/44608\/revisions\/107895"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/44653"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=44608"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=44608"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=44608"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}