{"id":83525,"date":"2024-10-08T13:13:38","date_gmt":"2024-10-08T13:13:38","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=83525"},"modified":"2024-10-12T09:56:06","modified_gmt":"2024-10-12T09:56:06","slug":"esp32-external-wake-up-deep-sleep","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp32-external-wake-up-deep-sleep\/","title":{"rendered":"ESP32 External Wake Up from Deep Sleep"},"content":{"rendered":"\n<p>This article shows how to put the ESP32 in deep sleep mode and wake it up with an external wake-up. An external wake-up source can be the press of a pushbutton, the detection of movement, or other scenarios that involve changing the value of a signal: from HIGH to LOW or LOW to HIGH.<br>You have two possibilities of external wake-up: <strong>ext0<\/strong>, and <strong>ext1<\/strong>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/ESP32-Deep-Sleep-External-Wake-Up-1.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 External Wake Up from Deep Sleep\" class=\"wp-image-162972\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/ESP32-Deep-Sleep-External-Wake-Up-1.jpg?w=1920&amp;quality=100&amp;strip=all&amp;ssl=1 1920w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/ESP32-Deep-Sleep-External-Wake-Up-1.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/ESP32-Deep-Sleep-External-Wake-Up-1.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/ESP32-Deep-Sleep-External-Wake-Up-1.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/ESP32-Deep-Sleep-External-Wake-Up-1.jpg?resize=1536%2C864&amp;quality=100&amp;strip=all&amp;ssl=1 1536w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n<p class=\"rntbox rntclgray\"><em>Updated 8 October 2024.<\/em><\/p>\n\n\n\n<p>Throughout this article we&#8217;ll cover the following subjects:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>how to put the ESP32 in deep sleep mode;<\/li>\n\n\n\n<li>wake up the ESP32 by changing the value of one GPIO (with a pushbutton) using the ext0 method;<\/li>\n\n\n\n<li>wake up the ESP32 using several GPIOs using the ext1 method;<\/li>\n\n\n\n<li>identify which GPIO caused the wake-up.<\/li>\n<\/ul>\n\n\n\n<p>To learn more about deep sleep and other wake-up sources, you can follow the next tutorials:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-deep-sleep-arduino-ide-wake-up-sources\/\"><strong>[Complete Guide]<\/strong> ESP32 Deep Sleep with Arduino IDE and Wake Up Sources<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-touch-wake-up-deep-sleep\/\">ESP32 Touch Wake Up from Deep Sleep<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-timer-wake-up-deep-sleep\/\">ESP32 Timer Wake Up from Deep Sleep<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Writing a Deep Sleep Sketch<\/h2>\n\n\n\n<p>To write a sketch to put your ESP32 into deep sleep mode, and then wake it up, you need to keep in mind that:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>First, you need to configure the wake-up sources. This means configuring what will wake up the ESP32. You can use one or combine more than one wake-up source. In this article, we&#8217;ll show you how to use the external wake-up sources.<\/li>\n\n\n\n<li>You can decide what peripherals to shut down or keep on during deep sleep. However, by default, the ESP32 automatically powers down the peripherals that are not needed with the wake-up source you define.<\/li>\n\n\n\n<li>Finally, you use the <span class=\"rnthl rntliteral\">esp_deep_sleep_start()<\/span> function to put your ESP32 into deep sleep mode.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">External Wake Up<\/h2>\n\n\n\n<p>External wake up is one of the ways to wake up the ESP32 from deep sleep. This means that you can wake up the ESP32 by toggling the value of a signal on a pin, like the press of a button. You have two possibilities of external wake-up: ext0, and ext1.<\/p>\n\n\n<div class=\"wp-block-image is-resized\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"350\" height=\"250\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/external-wake-up.png?resize=350%2C250&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"External Wake Up\" class=\"wp-image-81693\" style=\"width:207px;height:auto\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/external-wake-up.png?w=350&amp;quality=100&amp;strip=all&amp;ssl=1 350w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/external-wake-up.png?resize=300%2C214&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 350px) 100vw, 350px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">External Wake Up (ext0)<\/h2>\n\n\n\n<p>This wake-up source allows you to use a pin to wake up the ESP32. The ext0 wake\u2011up source option uses RTC GPIOs to wake up. So,&nbsp;RTC peripherals are kept on during deep sleep if this wake-up source is requested.<\/p>\n\n\n\n<p>To use this wake-up source, you use the following function:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>esp_sleep_enable_ext0_wakeup(GPIO_NUM_X, level)<\/code><\/pre>\n\n\n\n<p>This function accepts as the first argument the pin you want to use, in this format <span class=\"rnthl rntliteral\">GPIO_NUM_X<\/span>, in which <strong>X<\/strong> represents the GPIO number of that pin.<\/p>\n\n\n\n<p>The second argument, <span class=\"rnthl rntliteral\">level<\/span>, can be either 1 or 0. This represents the state of the GPIO that will trigger wake-up.<\/p>\n\n\n\n<p><strong>Note:<\/strong> you can only use pins that are <strong>RTC GPIOs<\/strong> with this wake-up source. Here\u2019s a list of the RTC GPIOs for different ESP32 chip models:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>ESP32-S3<\/strong>: 0-21;<\/li>\n\n\n\n<li><strong>ESP32<\/strong>: 0, 2, 4, 12-15, 25-27, 32-39;<\/li>\n\n\n\n<li><strong>ESP32-S2<\/strong>: 0-21;<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">External Wake Up (ext1)<\/h2>\n\n\n\n<p>This wake-up source allows you to use multiple RTC GPIOs. This wake-up source is implemented by the RTC controller. So, RTC peripherals and RTC memories can be powered off in this mode.<\/p>\n\n\n\n<p>To use this wake-up source, you use the following function:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>esp_sleep_enable_ext1_wakeup_io(bitmask, mode);<\/code><\/pre>\n\n\n\n<p>This function accepts two arguments:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A bitmask of the GPIO numbers that will cause the wake up;<\/li>\n\n\n\n<li><strong>Mode<\/strong>: the logic to wake up the ESP32. It can be:\n<ul class=\"wp-block-list\">\n<li><span class=\"rnthl rntliteral\">ESP_EXT1_WAKEUP_ALL_LOW<\/span>: wake up when all GPIOs go low;<\/li>\n\n\n\n<li><span class=\"rnthl rntliteral\">ESP_EXT1_WAKEUP_ANY_HIGH<\/span>: wake up if any of the GPIOs go high. <\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>If you\u2019re using an ESP32-S2, ESP32-S3, ESP32-C6 or ESP32-H2, these are the available modes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span class=\"rnthl rntliteral\">ESP_EXT1_WAKEUP_ANY_LOW<\/span>: wake up when any of the selected GPIOs is low<\/li>\n\n\n\n<li><span class=\"rnthl rntliteral\">ESP_EXT1_WAKEUP_ANY_HIGH<\/span>: wake up when any of the selected GPIOs is high<\/li>\n<\/ul>\n\n\n\n<p><strong>Note<\/strong>: you can only use pins that are RTC GPIOs.<\/p>\n\n\n\n<p>For all the details about the ext1 deep sleep wake-up source, take a look at the <a href=\"https:\/\/docs.espressif.com\/projects\/esp-idf\/en\/latest\/esp32\/api-reference\/system\/sleep_modes.html#_CPPv431esp_sleep_enable_ext1_wakeup_io8uint64_t28esp_sleep_ext1_wakeup_mode_t\" target=\"_blank\" rel=\"noopener\" title=\"\">Espressif deep sleep documentation<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Parts Required<\/h2>\n\n\n\n<p>To follow this tutorial, you need the following parts:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/esp32-dev-board-wi-fi-bluetooth\/\" target=\"_blank\" rel=\"noreferrer noopener\">ESP32 DOIT DEVKIT V1 Board<\/a> (read Best <a href=\"https:\/\/makeradvisor.com\/esp32-development-boards-review-comparison\/\" target=\"_blank\" rel=\"noopener\" title=\"\">ESP32 development boards<\/a>)<\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/pushbuttons-kit\/\" target=\"_blank\" rel=\"noreferrer noopener\">2x Pushbuttons<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/resistors-kits\/\" target=\"_blank\" rel=\"noreferrer noopener\">2x 10k Ohm resistor<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\" rel=\"noreferrer noopener\">Breadboard<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\" rel=\"noreferrer noopener\">Jumper wires<\/a> <\/li>\n<\/ul>\n\n\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Code &#8211; External Wake Up Example<\/h2>\n\n\n\n<p>To program the ESP32 we&#8217;ll use Arduino IDE. So, you need to make sure you have the ESP32 Arduino core installed. Follow the next tutorial to install the ESP32 add-on, if you haven&#8217;t already:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/installing-esp32-arduino-ide-2-0\/\">Installing ESP32 Board in Arduino IDE 2 (Windows, Mac OS X, Linux)<\/a><\/li>\n<\/ul>\n\n\n\n<p>The following example demonstrates how to use the external wake-up source. You can find it at <strong>File<\/strong> &gt; <strong>Examples<\/strong> &gt; <strong>ESP32<\/strong> <strong>Deep Sleep<\/strong> &gt; <strong>ExternalWakeUp<\/strong>, or you can copy it from below.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n  Deep Sleep with External Wake Up\n  =====================================\n  This code displays how to use deep sleep with\n  an external trigger as a wake up source and how\n  to store data in RTC memory to use it over reboots\n\n  This code is under Public Domain License.\n\n  Hardware Connections\n  ======================\n  Push Button to GPIO 33 pulled down with a 10K Ohm\n  resistor\n\n  NOTE:\n  ======\n  Only RTC IO can be used as a source for external wake\n  source. They are pins: 0,2,4,12-15,25-27,32-39.\n\n  Author:\n  Pranav Cherukupalli &lt;cherukupallip@gmail.com&gt;\n*\/\n#include &quot;driver\/rtc_io.h&quot;\n\n#define BUTTON_PIN_BITMASK(GPIO) (1ULL &lt;&lt; GPIO)  \/\/ 2 ^ GPIO_NUMBER in hex\n#define USE_EXT0_WAKEUP          1               \/\/ 1 = EXT0 wakeup, 0 = EXT1 wakeup\n#define WAKEUP_GPIO              GPIO_NUM_33     \/\/ Only RTC IO are allowed - ESP32 Pin example\nRTC_DATA_ATTR int bootCount = 0;\n\n\/*\n  Method to print the reason by which ESP32\n  has been awaken from sleep\n*\/\nvoid print_wakeup_reason() {\n  esp_sleep_wakeup_cause_t wakeup_reason;\n\n  wakeup_reason = esp_sleep_get_wakeup_cause();\n\n  switch (wakeup_reason) {\n    case ESP_SLEEP_WAKEUP_EXT0:     Serial.println(&quot;Wakeup caused by external signal using RTC_IO&quot;); break;\n    case ESP_SLEEP_WAKEUP_EXT1:     Serial.println(&quot;Wakeup caused by external signal using RTC_CNTL&quot;); break;\n    case ESP_SLEEP_WAKEUP_TIMER:    Serial.println(&quot;Wakeup caused by timer&quot;); break;\n    case ESP_SLEEP_WAKEUP_TOUCHPAD: Serial.println(&quot;Wakeup caused by touchpad&quot;); break;\n    case ESP_SLEEP_WAKEUP_ULP:      Serial.println(&quot;Wakeup caused by ULP program&quot;); break;\n    default:                        Serial.printf(&quot;Wakeup was not caused by deep sleep: %d\\n&quot;, wakeup_reason); break;\n  }\n}\n\nvoid setup() {\n  Serial.begin(115200);\n  delay(1000);  \/\/Take some time to open up the Serial Monitor\n\n  \/\/Increment boot number and print it every reboot\n  ++bootCount;\n  Serial.println(&quot;Boot number: &quot; + String(bootCount));\n\n  \/\/Print the wakeup reason for ESP32\n  print_wakeup_reason();\n\n  \/*\n    First we configure the wake up source\n    We set our ESP32 to wake up for an external trigger.\n    There are two types for ESP32, ext0 and ext1 .\n    ext0 uses RTC_IO to wakeup thus requires RTC peripherals\n    to be on while ext1 uses RTC Controller so does not need\n    peripherals to be powered on.\n    Note that using internal pullups\/pulldowns also requires\n    RTC peripherals to be turned on.\n  *\/\n#if USE_EXT0_WAKEUP\n  esp_sleep_enable_ext0_wakeup(WAKEUP_GPIO, 1);  \/\/1 = High, 0 = Low\n  \/\/ Configure pullup\/downs via RTCIO to tie wakeup pins to inactive level during deepsleep.\n  \/\/ EXT0 resides in the same power domain (RTC_PERIPH) as the RTC IO pullup\/downs.\n  \/\/ No need to keep that power domain explicitly, unlike EXT1.\n  rtc_gpio_pullup_dis(WAKEUP_GPIO);\n  rtc_gpio_pulldown_en(WAKEUP_GPIO);\n\n#else  \/\/ EXT1 WAKEUP\n  \/\/If you were to use ext1, you would use it like\n  esp_sleep_enable_ext1_wakeup_io(BUTTON_PIN_BITMASK(WAKEUP_GPIO), ESP_EXT1_WAKEUP_ANY_HIGH);\n  \/*\n    If there are no external pull-up\/downs, tie wakeup pins to inactive level with internal pull-up\/downs via RTC IO\n         during deepsleep. However, RTC IO relies on the RTC_PERIPH power domain. Keeping this power domain on will\n         increase some power comsumption. However, if we turn off the RTC_PERIPH domain or if certain chips lack the RTC_PERIPH\n         domain, we will use the HOLD feature to maintain the pull-up and pull-down on the pins during sleep.\n  *\/\n  rtc_gpio_pulldown_en(WAKEUP_GPIO);  \/\/ GPIO33 is tie to GND in order to wake up in HIGH\n  rtc_gpio_pullup_dis(WAKEUP_GPIO);   \/\/ Disable PULL_UP in order to allow it to wakeup on HIGH\n#endif\n  \/\/Go to sleep now\n  Serial.println(&quot;Going to sleep now&quot;);\n  esp_deep_sleep_start();\n  Serial.println(&quot;This will never be printed&quot;);\n}\n\nvoid loop() {\n  \/\/This is not going to be called\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Learn-ESP32-eBook\/raw\/main\/Module_4\/4_4_1_external_wakeup\/4_4_1_external_wakeup.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>This example awakes the ESP32 when you trigger <span class=\"rnthl rntcblue\">GPIO 33<\/span> to high. The code example shows how to use both methods: ext0 and ext1. If you upload the code as it is, you&#8217;ll use ext0. The function to use ext1 is commented. We&#8217;ll show you how both methods work and how to use them.<\/p>\n\n\n\n<p>Let&#8217;s take a quick look at the code. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Save Data on RTC Memories<\/h3>\n\n\n\n<p>With the ESP32, you can save data on the RTC memories. The ESP32 has 8kB SRAM on the RTC part, called RTC fast memory. The data saved here is not erased during deep sleep. However, it is erased when you press the reset button (the button labeled EN on the ESP32 board).<\/p>\n\n\n\n<p> To save data on the RTC memory, you just have to add <span class=\"rnthl rntliteral\">RTC_DATA_ATTR<\/span> before a variable definition. The example saves the <span class=\"rnthl rntliteral\">bootCount <\/span>variable on the RTC memory. This variable will count how many times the ESP32 has woken up from deep sleep. <\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>RTC_DATA_ATTR int bootCount = 0;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Wake Up Reason<\/h3>\n\n\n\n<p>Then, the code defines the <span class=\"rnthl rntliteral\">print_wakeup_reason()<\/span> function, that prints the reason by which the ESP32 has been awakened from sleep.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>void print_wakeup_reason() {\n  esp_sleep_wakeup_cause_t wakeup_reason;\n\n  wakeup_reason = esp_sleep_get_wakeup_cause();\n\n  switch (wakeup_reason) {\n    case ESP_SLEEP_WAKEUP_EXT0:     Serial.println(\"Wakeup caused by external signal using RTC_IO\"); break;\n    case ESP_SLEEP_WAKEUP_EXT1:     Serial.println(\"Wakeup caused by external signal using RTC_CNTL\"); break;\n    case ESP_SLEEP_WAKEUP_TIMER:    Serial.println(\"Wakeup caused by timer\"); break;\n    case ESP_SLEEP_WAKEUP_TOUCHPAD: Serial.println(\"Wakeup caused by touchpad\"); break;\n    case ESP_SLEEP_WAKEUP_ULP:      Serial.println(\"Wakeup caused by ULP program\"); break;\n    default:                        Serial.printf(\"Wakeup was not caused by deep sleep: %d\\n\", wakeup_reason); break;\n  }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">setup()<\/h3>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, you start by initializing the serial communication:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.begin(115200); \ndelay(1000); \/\/Take some time to open up the Serial Monitor<\/code><\/pre>\n\n\n\n<p>Then, you increment one to the <span class=\"rnthl rntliteral\">bootCount<\/span> variable, and print that variable in the Serial Monitor.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>++bootCount;\nSerial.println(\"Boot number: \" + String(bootCount));<\/code><\/pre>\n\n\n\n<p>Next, you print the wake-up reason using the <span class=\"rnthl rntliteral\">print_wakeup_reason()<\/span> function defined earlier.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Print the wakeup reason for ESP32\nprint_wakeup_reason();<\/code><\/pre>\n\n\n\n<p>After this, you need to enable the wake-up sources. We&#8217;ll test each of the wake-up sources, ext0 and ext1, separately.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">ext0<\/h3>\n\n\n\n<p>In this example, the ESP32 wakes up when the <span class=\"rnthl rntcblue\">GPIO 33<\/span> is triggered to high:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>esp_sleep_enable_ext0_wakeup(WAKEUP_GPIO, 1);  \/\/ 1 = High, 0 = Low<\/code><\/pre>\n\n\n\n<p>Instead of GPIO 33, you can use any other RTC GPIO pin. Just define it on the <span class=\"rnthl rntliteral\">WAKEUP_GPIO<\/span> variable at the beginning of the code.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define WAKEUP_GPIO GPIO_NUM_33     \/\/ Only RTC IO are allowed<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Internal Pull-Up and Pull-Down Resistors<\/h3>\n\n\n\n<p>We also call the following two lines:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>rtc_gpio_pullup_dis(WAKEUP_GPIO);\nrtc_gpio_pulldown_en(WAKEUP_GPIO);<\/code><\/pre>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">rtc_gpio_pullup_dis()<\/span> function disables any internal pull-up resistors on the wake-up GPIO\u2014it ensures that the pin is not unintentionally held high. This is important because a pull-up resistor would keep the pin high, potentially causing unintended wakeups.<\/p>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">rtc_gpio_pulldown_en()<\/span> function enables the internal pull-down resistor on the wake-up GPIO\u2014it ensures the pin is held low until a valid wakeup signal (HIGH) is received. By configuring the pin with a pull-down resistor, we guarantee that it remains in a stable low state during deep sleep. This stability ensures that the ESP32 wakes up only when the specified GPIO pin receives an external high signal, matching the wakeup condition set by the <span class=\"rnthl rntliteral\">esp_sleep_enable_ext0_wakeup(WAKEUP_GPIO, 1)<\/span>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Wiring the Circuit<\/h4>\n\n\n\n<p>To test this example, wire a pushbutton to your ESP32 by following the next schematic diagram. The button is connected to <span class=\"rnthl rntcblue\">GPIO 33<\/span> using a pull-down 10k Ohm resistor.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"534\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/esp32-pushbutton-33.png?resize=750%2C534&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 connected to GPIO 33\" class=\"wp-image-162980\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/esp32-pushbutton-33.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/esp32-pushbutton-33.png?resize=300%2C214&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p class=\"rntbox rntclgreen\">Note that only RTC GPIOs can be used as a wake-up source\u2014you can check the pinout of your board to identify the RTC GPIOs. Instead of GPIO 33, you can use any RTC GPIO pins to connect your button.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Testing the Example<\/h4>\n\n\n\n<p>Let&#8217;s test this example. Upload the example code to your ESP32. Make sure you have the right board and COM port selected. Open the Serial Monitor at a baud rate of 115200.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/02\/serial-monitor-logo-arduino-ide-2.png?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"41\" height=\"39\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/02\/serial-monitor-logo-arduino-ide-2.png?resize=41%2C39&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" class=\"wp-image-148549\"\/><\/a><\/figure><\/div>\n\n\n<p>Press the pushbutton to wake up the ESP32.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"421\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/Esp32-deep-sleep-external-wake-up-with-pushbutton.jpg?resize=750%2C421&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 Deep Sleep External Wake Up with Pushbutton\" class=\"wp-image-163126\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/Esp32-deep-sleep-external-wake-up-with-pushbutton.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/Esp32-deep-sleep-external-wake-up-with-pushbutton.jpg?resize=300%2C168&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>Try this several times, and see the boot count increasing with each button press.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"666\" height=\"489\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/testing-external-wake-up-esp32.png?resize=666%2C489&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 testing exterbak wake-up\" class=\"wp-image-162981\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/testing-external-wake-up-esp32.png?w=666&amp;quality=100&amp;strip=all&amp;ssl=1 666w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/testing-external-wake-up-esp32.png?resize=300%2C220&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 666px) 100vw, 666px\" \/><\/figure><\/div>\n\n\n<p>Using this method is useful to wake up your ESP32 using a pushbutton, for example, to execute a particular task. However, with this method, you can only use one GPIO as a wake-up source.<\/p>\n\n\n\n<p>What if you want to have different buttons, all of them wake up the ESP, but do different tasks? For that you need to use the ext1 method.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">ext1<\/h3>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">ext1<\/span> wake-up source allows you to wake up the ESP32 using different GPIOs and perform different tasks depending on the GPIO that caused the wake-up.<\/p>\n\n\n\n<p>Instead of using the <span class=\"rnthl rntliteral\">esp_sleep_enable_ext0_wakeup()<\/span> function, you use the <span class=\"rnthl rntliteral\">esp_sleep_enable_ext1_wakeup_io() <\/span> function.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>esp_sleep_enable_ext1_wakeup_io(BUTTON_PIN_BITMASK(WAKEUP_GPIO), ESP_EXT1_WAKEUP_ANY_HIGH);<\/code><\/pre>\n\n\n\n<p>In this particular example, to run that part of the code, make sure you set the <span class=\"rnthl rntliteral\">USE_EXT0_WAKEUP<\/span> variable to <span class=\"rnthl rntliteral\">0<\/span> at the beginning of the code like so:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define USE_EXT0_WAKEUP  0  \/\/ 1 = EXT0 wakeup, 0 = EXT1 wakeup<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">The esp_sleep_enable_ext1_wakeup_io() function<\/h3>\n\n\n\n<p>The first argument of the <span class=\"rnthl rntliteral\">esp_sleep_enable_ext1_wakeup_io()<\/span> function is a bitmask of the GPIOs you\u2019ll use as a wake-up source, and the second argument defines the logic to wake up the ESP32.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">GPIOs Bitmask<\/h4>\n\n\n\n<p>To define the GPIOs bitmask, we can use the <span class=\"rnthl rntliteral\">BUTTON_PIN_BITMASK()<\/span> macro defined at the beginning of the code.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define BUTTON_PIN_BITMASK(GPIO) (1ULL &lt;&lt; GPIO) &nbsp;\/\/ 2 ^ GPIO_NUMBER in hex<\/code><\/pre>\n\n\n\n<p><span class=\"rnthl rntliteral\">BUTTON_PIN_BITMASK(GPIO)<\/span> is a macro that creates a bitmask for a specific GPIO. It is not a function but behaves somewhat similarly by accepting an argument and returning a value.<\/p>\n\n\n\n<p>So, if you want to return the bitmask for a specific GPIO, you just need to call it like so:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>BUTTON_PIN_BITMASK(WAKEUP_GPIO)<\/code><\/pre>\n\n\n\n<p>So, the <span class=\"rnthl rntliteral\">esp_sleep_enable_ext1_wakeup_io()<\/span> will look like this:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>esp_sleep_enable_ext1_wakeup_io(BUTTON_PIN_BITMASK(WAKEUP_GPIO), ESP_EXT1_WAKEUP_ANY_HIGH);<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Bitmask for Multiple GPIOs<\/h4>\n\n\n\n<p>To create a bitmask for multiple GPIOs using the <span class=\"rnthl rntliteral\">BUTTON_PIN_BITMASK(GPIO)<\/span> macro, you can use bitwise OR (<span class=\"rnthl rntliteral\">|<\/span>) to combine the individual bitmasks for each GPIO pin. Here&#8217;s how you can do it:<\/p>\n\n\n\n<p>Suppose you want to create a bitmask for GPIO pins 2 and 15. You can do this by combining the individual bitmasks for each pin like this:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>uint64_t bitmask = BUTTON_PIN_BITMASK(GPIO_NUM_2) | BUTTON_PIN_BITMASK(GPIO_NUM_15);<\/code><\/pre>\n\n\n\n<p>We\u2019ll see an example using multiple GPIOs as a wake-up source next.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Wake-Up Mode<\/h4>\n\n\n\n<p>The second argument of the <span class=\"rnthl rntliteral\">esp_sleep_enable_ext1_wakeup_io()<\/span> function is the wake-up mode. As we\u2019ve seen previously, these are your options:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span class=\"rnthl rntliteral\">ESP_EXT1_WAKEUP_ALL_LOW<\/span>: wake up when all GPIOs go low;<\/li>\n\n\n\n<li><span class=\"rnthl rntliteral\">ESP_EXT1_WAKEUP_ANY_HIGH<\/span>: wake up when any of the GPIOs go high.<\/li>\n<\/ul>\n\n\n\n<p>If you\u2019re using an ESP32-S2, ESP32-S3, ESP32-C6 or ESP32-H2, these are the available modes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span class=\"rnthl rntliteral\">ESP_EXT1_WAKEUP_ANY_LOW<\/span>: wake up when any of the selected GPIOs is low<\/li>\n\n\n\n<li><span class=\"rnthl rntliteral\">ESP_EXT1_WAKEUP_ANY_HIGH<\/span>: wake up when any of the selected GPIOs is high<\/li>\n<\/ul>\n\n\n\n<p>In our particular example, we\u2019re using <span class=\"rnthl rntliteral\">ESP_EXT1_WAKEUP_ANY_HIGH<\/span>. So, the ESP32 will wake-up when any of the GPIOs from the bitmask are high. <\/p>\n\n\n\n<p>Like with the <span class=\"rnthl rntliteral\">ext0<\/span>, we disable pull-up internal resistors and enable pull-down resistors to ensure stability of the reading of the wake-up GPIO.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">External Wake Up &#8211; Multiple GPIOs<\/h2>\n\n\n\n<p>Now, you should be able to wake up the ESP32 using different buttons, and identify which button caused the wake up. In this example we&#8217;ll use <span class=\"rnthl rntcgreen\">GPIO 2<\/span> and <span class=\"rnthl rntcyellow\">GPIO 15<\/span> as a wake-up source.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Schematic<\/h3>\n\n\n\n<p>Wire two buttons to your ESP32. In this example, we&#8217;re using <span class=\"rnthl rntcgreen\">GPIO 2<\/span> and <span class=\"rnthl rntcyellow\">GPIO 15<\/span>, but you can connect your buttons to any RTC GPIOs.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"720\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/esp32-two-pusbuttons_bb.png?resize=969%2C720&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 two pushbuttons to wake-up from deep sleep\" class=\"wp-image-162983\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/esp32-two-pusbuttons_bb.png?w=969&amp;quality=100&amp;strip=all&amp;ssl=1 969w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/esp32-two-pusbuttons_bb.png?resize=300%2C223&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/esp32-two-pusbuttons_bb.png?resize=768%2C571&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 969px) 100vw, 969px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\">Code Multiple GPIOs &#8211; External Wake-Up<\/h3>\n\n\n\n<p>You need to make some modifications to the example code we&#8217;ve used before:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>create a bitmask to use <span class=\"rnthl rntcyellow\">GPIO 15<\/span> and <span class=\"rnthl rntcgreen\">GPIO 2<\/span>. We&#8217;ve shown you how to do this before;<\/li>\n\n\n\n<li>enable ext1 as a wake-up source;<\/li>\n\n\n\n<li>create a function that identifies the GPIO that caused the wake-up.<\/li>\n<\/ul>\n\n\n\n<p>The next sketch has all those changes implemented.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*  \n  Rui Santos &amp; Sara Santos - Random Nerd Tutorials\n  https:\/\/RandomNerdTutorials.com\/learn-esp32-with-arduino-ide\/\n  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.\n  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n*\/\n\n#include &quot;driver\/rtc_io.h&quot;\n\n#define BUTTON_PIN_BITMASK(GPIO) (1ULL &lt;&lt; GPIO)  \/\/ 2 ^ GPIO_NUMBER in hex\n#define WAKEUP_GPIO_2              GPIO_NUM_2     \/\/ Only RTC IO are allowed - ESP32 Pin example\n#define WAKEUP_GPIO_15              GPIO_NUM_15     \/\/ Only RTC IO are allowed - ESP32 Pin example\n\n\/\/ Define bitmask for multiple GPIOs\nuint64_t bitmask = BUTTON_PIN_BITMASK(WAKEUP_GPIO_2) | BUTTON_PIN_BITMASK(WAKEUP_GPIO_15);\n\nRTC_DATA_ATTR int bootCount = 0;\n\n\/*\nMethod to print the GPIO that triggered the wakeup\n*\/\nvoid print_GPIO_wake_up(){\n  int GPIO_reason = esp_sleep_get_ext1_wakeup_status();\n  Serial.print(&quot;GPIO that triggered the wake up: GPIO &quot;);\n  Serial.println((log(GPIO_reason))\/log(2), 0);\n}\n\n\/*\n  Method to print the reason by which ESP32 has been awaken from sleep\n*\/\nvoid print_wakeup_reason() {\n  esp_sleep_wakeup_cause_t wakeup_reason;\n\n  wakeup_reason = esp_sleep_get_wakeup_cause();\n\n  switch (wakeup_reason) {\n    case ESP_SLEEP_WAKEUP_EXT0:     \n      Serial.println(&quot;Wakeup caused by external signal using RTC_IO&quot;);\n      break;\n    case ESP_SLEEP_WAKEUP_EXT1:\n      Serial.println(&quot;Wakeup caused by external signal using RTC_CNTL&quot;);\n      print_GPIO_wake_up();\n      break;\n    case ESP_SLEEP_WAKEUP_TIMER:\n      Serial.println(&quot;Wakeup caused by timer&quot;);\n      break;\n    case ESP_SLEEP_WAKEUP_TOUCHPAD:\n      Serial.println(&quot;Wakeup caused by touchpad&quot;);\n      break;\n    case ESP_SLEEP_WAKEUP_ULP:\n      Serial.println(&quot;Wakeup caused by ULP program&quot;);\n      break;\n    default:\n      Serial.printf(&quot;Wakeup was not caused by deep sleep: %d\\n&quot;, wakeup_reason);\n      break;\n  }\n}\n\nvoid setup() {\n  Serial.begin(115200);\n  delay(1000);  \/\/Take some time to open up the Serial Monitor\n\n  \/\/Increment boot number and print it every reboot\n  ++bootCount;\n  Serial.println(&quot;Boot number: &quot; + String(bootCount));\n\n  \/\/Print the wakeup reason for ESP32\n  print_wakeup_reason();\n\n  \/\/Use ext1 as a wake-up source\n  esp_sleep_enable_ext1_wakeup_io(bitmask, ESP_EXT1_WAKEUP_ANY_HIGH);\n  \/\/ enable pull-down resistors and disable pull-up resistors\n  rtc_gpio_pulldown_en(WAKEUP_GPIO_2);\n  rtc_gpio_pullup_dis(WAKEUP_GPIO_2);\n  rtc_gpio_pulldown_en(WAKEUP_GPIO_15);\n  rtc_gpio_pullup_dis(WAKEUP_GPIO_15);\n\n  \/\/Go to sleep now\n  Serial.println(&quot;Going to sleep now&quot;);\n  esp_deep_sleep_start();\n  Serial.println(&quot;This will never be printed&quot;);\n}\n\nvoid loop() {\n  \/\/This is not going to be called\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Learn-ESP32-eBook\/raw\/main\/Module_4\/4_4_2_external_wake_up_multiple_gpios\/4_4_2_external_wake_up_multiple_gpios.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How Does the Code Work?<\/h3>\n\n\n\n<p>Let\u2019s take a quick look at how the code works.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">GPIOs Bitmask<\/h4>\n\n\n\n<p>You define the GPIOs bitmask at the beginning of the code:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define BUTTON_PIN_BITMASK(GPIO) (1ULL &lt;&lt; GPIO)  \/\/ 2 ^ GPIO_NUMBER in hex\n#define WAKEUP_GPIO_2           GPIO_NUM_2       \/\/ Only RTC IO are allowed - \n#define WAKEUP_GPIO_15          GPIO_NUM_15      \/\/ Only RTC IO are allowed \n\n\/\/ Define bitmask for multiple GPIOs\nuint64_t bitmask = BUTTON_PIN_BITMASK(WAKEUP_GPIO_2) | BUTTON_PIN_BITMASK(WAKEUP_GPIO_15);<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Identify the GPIO that Caused the Wake-up<\/h4>\n\n\n\n<p>We create a function called <span class=\"rnthl rntliteral\">print_GPIO_wake_up()<\/span> that prints the GPIO that caused the wake-up:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>void print_GPIO_wake_up(){\n  int GPIO_reason = esp_sleep_get_ext1_wakeup_status();\n  Serial.print(\"GPIO that triggered the wake up: GPIO \");\n  Serial.println((log(GPIO_reason))\/log(2), 0);\n}<\/code><\/pre>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">esp_sleep_get_ext1_wakeup_status()<\/span> function returns a bitmask with the GPIO that caused the wake-up. We can get the GPIO number as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>log(GPIO_reason))\/log(2)<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Print the Wake-Up Reason<\/h4>\n\n\n\n<p>We modified the <span class=\"rnthl rntliteral\">print_wakeup_reason()<\/span> function to print the GPIO that caused the wake-up when the wake-up source is <span class=\"rnthl rntliteral\">ext1<\/span>:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>case ESP_SLEEP_WAKEUP_EXT1:\n  Serial.println(\"Wakeup caused by external signal using RTC_CNTL\");\n  print_GPIO_wake_up();\n  break;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Enable ext1 as a Wake-Up Source<\/h4>\n\n\n\n<p>Enable <span class=\"rnthl rntliteral\">ext1<\/span> as a wake-up source by passing the GPIOs bitmask and wake-up mode.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>esp_sleep_enable_ext1_wakeup_io(bitmask, ESP_EXT1_WAKEUP_ANY_HIGH);<\/code><\/pre>\n\n\n\n<p>Don\u2019t forget to disable any internal pull-up resistors and enable pull-down resistors on the GPIOs used as a wake-up source.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>rtc_gpio_pulldown_en(WAKEUP_GPIO_2);\nrtc_gpio_pullup_dis(WAKEUP_GPIO_2);\nrtc_gpio_pulldown_en(WAKEUP_GPIO_15);\nrtc_gpio_pullup_dis(WAKEUP_GPIO_15);<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Enable Deep Sleep<\/h4>\n\n\n\n<p>Finally, call <span class=\"rnthl rntliteral\">esp_deep_sleep_start()<\/span> to put the ESP32 in deep sleep mode.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>esp_deep_sleep_start();<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Testing the Sketch<\/h3>\n\n\n\n<p>After uploading the code to the board, the ESP32 will be in deep sleep mode. You can wake it up by pressing the pushbuttons.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"419\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/ESP32-external-wake-uo-multiple-gpios.png?resize=750%2C419&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 external wake-up multiple GPIOs\" class=\"wp-image-162985\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/ESP32-external-wake-uo-multiple-gpios.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/ESP32-external-wake-uo-multiple-gpios.png?resize=300%2C168&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>Open the Serial Monitor at a baud rate of 115200. Press the pushbuttons to wake up the ESP32. On the Serial Monitor, you should get the wake-up reason and the GPIO that caused the wake-up.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"715\" height=\"614\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/ESP32_external_wake_up_multiple_GPIOs.png?resize=715%2C614&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 External Wake-up Multiple GPIOs\" class=\"wp-image-162986\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/ESP32_external_wake_up_multiple_GPIOs.png?w=715&amp;quality=100&amp;strip=all&amp;ssl=1 715w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/ESP32_external_wake_up_multiple_GPIOs.png?resize=300%2C258&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 715px) 100vw, 715px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In this tutorial, you learned to wake up the ESP32 using an external wake-up. This means that you can wake up the ESP32 by changing the state of a GPIO pin.<\/p>\n\n\n\n<p>In summary:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You can only use RTC GPIOs as an external wake-up;<\/li>\n\n\n\n<li>You can use two different methods: ext0 and ext1;<\/li>\n\n\n\n<li>ext0 allows you to wake up the ESP32 using one single GPIO pin;<\/li>\n\n\n\n<li>ext1 allows you to wake up the ESP32 using multiple GPIO pins.<\/li>\n<\/ul>\n\n\n\n<p>To learn more about deep sleep with the ESP32, take a look at our complete guide: <a rel=\"noreferrer noopener\" aria-label=\"ESP32 Deep Sleep with Arduino IDE and Wake Up Sources (opens in a new tab)\" href=\"https:\/\/randomnerdtutorials.com\/esp32-deep-sleep-arduino-ide-wake-up-sources\/\" target=\"_blank\">ESP32 Deep Sleep with Arduino IDE and Wake Up Sources<\/a>. <\/p>\n\n\n\n<p>If you like ESP32, you may also like the following resources:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><a href=\"https:\/\/randomnerdtutorials.com\/learn-esp32-with-arduino-ide\/\">Learn ESP32 with Arduino IDE (eBook)<\/a><\/strong><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-web-server-with-bme280-mini-weather-station\/\">ESP32 Web Server with BME280 \u2013 Mini Weather Station<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-web-server-arduino-ide\/\">ESP32 Web Server with Arduino IDE &#8211; control outputs<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-dht11-dht22-temperature-humidity-web-server-arduino-ide\/\">ESP32 DHT11\/DHT22 Temperature Web Server<\/a><\/li>\n\n\n\n<li><strong><a href=\"https:\/\/randomnerdtutorials.com\/projects-esp32\/\">&gt;&gt; More Free ESP32 Tutorials and Guides &lt;&lt;<\/a><\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"rntbox rntclgray\">This is an excerpt from our course:&nbsp;<a href=\"https:\/\/randomnerdtutorials.com\/learn-esp32-with-arduino-ide\/\">Learn ESP32 with Arduino IDE<\/a>. If you like ESP32 and you want to learn more, we recommend enrolling in&nbsp;<a href=\"https:\/\/randomnerdtutorials.com\/learn-esp32-with-arduino-ide\/\">Learn ESP32 with Arduino IDE course<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article shows how to put the ESP32 in deep sleep mode and wake it with an external wake up like a button press. We&#8217;ll cover how to use ext0 and ext1 methods. <\/p>\n<p class=\"read-more-container\"><a href=\"https:\/\/randomnerdtutorials.com\/esp32-external-wake-up-deep-sleep\/\" class=\"read-more button\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":162972,"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":[281,276,277,299,264],"tags":[],"class_list":["post-83525","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp32-project","category-esp32","category-esp32-arduino-ide","category-0-esp32","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/ESP32-Deep-Sleep-External-Wake-Up-1.jpg?fit=1920%2C1080&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/83525","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\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=83525"}],"version-history":[{"count":5,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/83525\/revisions"}],"predecessor-version":[{"id":163132,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/83525\/revisions\/163132"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/162972"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=83525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=83525"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=83525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}