{"id":81663,"date":"2024-10-08T13:52:35","date_gmt":"2024-10-08T13:52:35","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=81663"},"modified":"2025-06-16T14:10:24","modified_gmt":"2025-06-16T14:10:24","slug":"esp32-deep-sleep-arduino-ide-wake-up-sources","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp32-deep-sleep-arduino-ide-wake-up-sources\/","title":{"rendered":"ESP32 Deep Sleep with Arduino IDE and Wake Up Sources"},"content":{"rendered":"\n<p>This article is a complete guide for the ESP32 Deep Sleep mode with Arduino IDE. We&#8217;ll show you how to put the ESP32 into deep sleep and take a look at different modes to wake it up: <strong>timer wake up<\/strong>, <strong>touch wake up<\/strong>, and <strong>external wake up<\/strong>. This guide provides practical examples with code, code explanation, and circuit diagrams.<\/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\/03\/ESP32-Deep-Sleep-and-wake-up-sources.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 Deep Sleep and Wake-Up Sources\" class=\"wp-image-162996\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/03\/ESP32-Deep-Sleep-and-wake-up-sources.jpg?w=1920&amp;quality=100&amp;strip=all&amp;ssl=1 1920w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/03\/ESP32-Deep-Sleep-and-wake-up-sources.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/03\/ESP32-Deep-Sleep-and-wake-up-sources.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/03\/ESP32-Deep-Sleep-and-wake-up-sources.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/03\/ESP32-Deep-Sleep-and-wake-up-sources.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><strong>Related Content:<\/strong> <a href=\"https:\/\/randomnerdtutorials.com\/esp8266-deep-sleep-with-arduino-ide\/\">ESP8266 Deep Sleep with Arduino IDE<\/a><\/p>\n\n\n\n<p>This article is divided into 4 different parts:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><a href=\"#intro-deep-sleep\" title=\"\">Introducing Deep Sleep Mode<\/a><\/li>\n\n\n\n<li><a href=\"#timer-wake-up\" title=\"\">Timer Wake Up<\/a><\/li>\n\n\n\n<li><a href=\"#touch-wake-up\" title=\"\">Touch Wake Up<\/a><\/li>\n\n\n\n<li><a href=\"#external-wake-up\" title=\"\">External Wake Up<\/a><\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"intro-deep-sleep\">Introducing&nbsp;Deep Sleep Mode<\/h2>\n\n\n\n<p>The ESP32 can switch between different power modes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Active mode<\/li>\n\n\n\n<li>Modem Sleep mode<\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-light-sleep-arduino\/\" title=\"\">Light Sleep mode<\/a><\/li>\n\n\n\n<li>Deep Sleep mode<\/li>\n\n\n\n<li>Hibernation mode<\/li>\n<\/ul>\n\n\n\n<p>You can compare the five different modes on the following table from the ESP32 Espressif datasheet.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"667\" height=\"174\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/POWER-MODES.jpg?resize=667%2C174&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"power consumption esp32\" class=\"wp-image-81665\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/POWER-MODES.jpg?w=667&amp;quality=100&amp;strip=all&amp;ssl=1 667w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/POWER-MODES.jpg?resize=300%2C78&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 667px) 100vw, 667px\" \/><\/figure><\/div>\n\n\n<p>The <a href=\"http:\/\/espressif.com\/sites\/default\/files\/documentation\/esp32_datasheet_en.pdf\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">ESP32 Espressif datasheet<\/a> also provides a table comparing the power consumption of the different power modes.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"857\" height=\"344\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/power-consumption-1.png?resize=857%2C344&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"esp32 different sleep modes\" class=\"wp-image-81668\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/power-consumption-1.png?w=857&amp;quality=100&amp;strip=all&amp;ssl=1 857w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/power-consumption-1.png?resize=300%2C120&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/power-consumption-1.png?resize=768%2C308&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/power-consumption-1.png?resize=250%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 250w\" sizes=\"(max-width: 857px) 100vw, 857px\" \/><\/figure><\/div>\n\n\n<p>And here&#8217;s also <strong>Table 10<\/strong> to compare the power consumption in active mode:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"770\" height=\"230\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/table-10-active-mode.jpg?resize=770%2C230&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"esp32 power consumption in active mode\" class=\"wp-image-81669\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/table-10-active-mode.jpg?w=770&amp;quality=100&amp;strip=all&amp;ssl=1 770w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/table-10-active-mode.jpg?resize=300%2C90&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/table-10-active-mode.jpg?resize=768%2C229&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 770px) 100vw, 770px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Why Deep Sleep Mode?<\/h2>\n\n\n\n<p>Having your ESP32 running on active mode with batteries is not ideal since batteries&#8217; power will drain very quickly.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"244\" height=\"122\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/drain-batteries.jpg?resize=244%2C122&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" class=\"wp-image-81670\"\/><\/figure><\/div>\n\n\n<p>If you put your ESP32 in deep sleep mode, it will reduce the power consumption, and your batteries will last longer.<\/p>\n\n\n\n<p>Having your ESP32 in deep sleep mode means cutting with the activities that consume more power while operating but leaving just enough activity to wake up the processor when something interesting happens.<\/p>\n\n\n\n<p>In deep sleep mode, neither CPU nor Wi-Fi activities take place, but the Ultra Low Power (ULP) co-processor can still be powered on.<\/p>\n\n\n\n<p>While the ESP32 is in deep sleep mode, the RTC memory also remains powered on, so we can write a program for the ULP co-processor and store it in the RTC memory to access peripheral devices, internal timers, and internal sensors.<\/p>\n\n\n\n<p>This mode of operation is useful if you need to wake up the main CPU by an external event, timer, or both while maintaining minimal power consumption.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">RTC_GPIO Pins<\/h2>\n\n\n\n<p>During deep sleep, some of the ESP32 pins can be used by the ULP co-processor, namely the RTC_GPIO pins, and the <a href=\"https:\/\/randomnerdtutorials.com\/esp32-touch-pins-arduino-ide\/\" title=\"\">Touch Pins<\/a>. The ESP32 datasheet provides a table identifying the RTC_GPIO pins. You can find that table&nbsp;<a href=\"http:\/\/espressif.com\/sites\/default\/files\/documentation\/esp32_datasheet_en.pdf\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>&nbsp;on page 14.<\/p>\n\n\n\n<p>You can use that table as a reference, or take a look at the following pinout to locate the different RTC_GPIO pins. The RTC_GPIO pins are highlighted with an orange rectangular box.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"538\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/08\/ESP32-DOIT-DEVKIT-V1-Board-Pinout-36-GPIOs-updated.jpg?resize=750%2C538&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" class=\"wp-image-72102\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/08\/ESP32-DOIT-DEVKIT-V1-Board-Pinout-36-GPIOs-updated.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/08\/ESP32-DOIT-DEVKIT-V1-Board-Pinout-36-GPIOs-updated.jpg?resize=300%2C215&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p><strong>You might also like reading:<\/strong> <a href=\"https:\/\/randomnerdtutorials.com\/esp32-pinout-reference-gpios\/\">ESP32 Pinout Reference: Which GPIO pins should you use?<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Wake Up Sources<\/h2>\n\n\n\n<p>After putting the ESP32 into deep sleep mode, there are several ways to wake it up:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>You can use the <strong>timer<\/strong>, waking up your ESP32 using predefined periods of time;<\/li>\n\n\n\n<li> You can use the <strong>touch pins<\/strong>; <\/li>\n\n\n\n<li>You can use <strong>two possibilities of external wake up<\/strong>: you can use either one external wake up, or several different external wake-up sources;<\/li>\n\n\n\n<li>You can use the<strong> ULP co-processor<\/strong> to wake up &#8211; this won&#8217;t be covered in this guide.<\/li>\n<\/ol>\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 configure what will wake up the ESP32. You can use one or combine more than one wake up source.<\/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\" id=\"timer-wake-up\">Timer Wake Up<\/h2>\n\n\n\n<p>The ESP32 can go into deep sleep mode, and then wake up at predefined periods of time. This feature is specially useful if you are running projects that require time stamping or daily tasks, while maintaining low power consumption.<\/p>\n\n\n<div class=\"wp-block-image is-resized\">\n<figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"300\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/timer-wake-up.png?resize=300%2C300&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Timer Wake Up\" class=\"wp-image-81689\" style=\"width:148px;height:auto\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/timer-wake-up.png?w=300&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/timer-wake-up.png?resize=150%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/timer-wake-up.png?resize=80%2C80&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/timer-wake-up.png?resize=220%2C220&amp;quality=100&amp;strip=all&amp;ssl=1 220w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/figure><\/div>\n\n\n<p>The ESP32 RTC controller has a built-in timer you can use to wake up the ESP32 after a predefined amount of time.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Enable Timer Wake Up<\/h3>\n\n\n\n<p>Enabling the ESP32 to wake up after a predefined amount of time is very straightforward. In the Arduino IDE, you just have to specify the sleep time in microseconds in the following function:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>esp_sleep_enable_timer_wakeup(time_in_us)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Code<\/h3>\n\n\n\n<p>To program the ESP32 we\u2019ll 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\u2019t 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>Let\u2019s see how this works using an example from the library. Open your Arduino IDE, and go to <strong>File<\/strong> &gt; <strong>Examples<\/strong> &gt; <strong>ESP32<\/strong> <strong>Deep Sleep<\/strong>, and&nbsp;open the <strong>TimerWakeUp<\/strong> sketch.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/* Simple Deep Sleep with Timer Wake Up\n   ESP32 offers a deep sleep mode for effective power saving as power is an important factor for IoT applications. In this mode CPUs, most of the RAM, and all the digital peripherals which are clocked\n   from APB_CLK are powered off. The only parts of the chip which can still be powered on are: RTC controller, RTC peripherals ,and RTC memories This code displays the most basic deep sleep with a timer to wake it up and how to store data in RTC memory to use it over reboots This code is under Public Domain License.\n   Author: Pranav Cherukupalli &lt;cherukupallip@gmail.com&gt; *\/\n\n#define uS_TO_S_FACTOR 1000000ULL  \/\/ Conversion factor for micro seconds to seconds\n#define TIME_TO_SLEEP  5           \/\/ Time ESP32 will go to sleep (in seconds)\n\nRTC_DATA_ATTR int bootCount = 0;\n\n\/\/ Method to print the reason by which ESP32 has been awaken from sleep\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  {\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  \/\/ First we configure the wake up source We set our ESP32 to wake up every 5 seconds\n  esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);\n  Serial.println(&quot;Setup ESP32 to sleep for every &quot; + String(TIME_TO_SLEEP) +\n  &quot; Seconds&quot;);\n\n  \/*\n  Next we decide what all peripherals to shut down\/keep on\n  By default, ESP32 will automatically power down the peripherals\n  not needed by the wakeup source, but if you want to be a poweruser\n  this is for you. Read in detail at the API docs\n  http:\/\/esp-idf.readthedocs.io\/en\/latest\/api-reference\/system\/deep_sleep.html\n  Left the line commented as an example of how to configure peripherals.\n  The line below turns off all RTC peripherals in deep sleep.\n  *\/\n  \/\/esp_deep_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF);\n  \/\/Serial.println(&quot;Configured all RTC Peripherals to be powered down in sleep&quot;);\n\n  \/\/ Now that we have setup a wake cause and if needed setup the peripherals state in deep sleep, we can now start going to deep sleep.\n  \/\/ In the case that no wake up sources were provided but deep sleep was started, it will sleep forever unless hardware reset occurs.\n  Serial.println(&quot;Going to sleep now&quot;);\n  delay(1000);\n  Serial.flush(); \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\/ESP32-Course\/raw\/master\/code\/DeepSleep\/TimerWakeUp\/TimerWakeUp.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>Let\u2019s take a look at this code. The first comment describes what is powered off during deep sleep with timer wake up.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">In this mode CPUs, most of the RAM,\nand all the digital peripherals which are clocked\nfrom APB_CLK are powered off. The only parts of\nthe chip which can still be powered on are:\nRTC controller, RTC peripherals ,and RTC memories<\/pre>\n\n\n\n<p>When you use timer wake-up, the parts that will be powered on are RTC controller, RTC peripherals, and RTC memories.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Define the Sleep Time<\/h3>\n\n\n\n<p>These first two lines of code define the period of time the ESP32 will be sleeping.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define uS_TO_S_FACTOR 1000000ULL \/* Conversion factor for micro seconds to seconds *\/\n#define TIME_TO_SLEEP  5          \/* Time ESP32 will go to sleep (in seconds) *\/<\/code><\/pre>\n\n\n\n<p>This example uses a conversion factor from microseconds to seconds, so that you can set the sleep time in the <span class=\"rnthl rntliteral\">TIME_TO_SLEEP<\/span> variable in seconds. In this case, the example will put the ESP32 into deep sleep mode for 5 seconds.<\/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 source that caused the wake-up from deep 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\">The setup()<\/h3>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span> is where you should put your code. You need to write all the instructions before calling the <span class=\"rnthl rntliteral\">esp_deep_sleep_start()<\/span> function.<\/p>\n\n\n\n<p>This example starts by initializing the serial communication at a baud rate of 115200.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.begin(115200);<\/code><\/pre>\n\n\n\n<p>Then, the <span class=\"rnthl rntliteral\">bootCount<\/span> variable is increased by one in every reboot, and that number is printed 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>Then, the code calls the <span class=\"rnthl rntliteral\">print_wakeup_reason()<\/span> function, but you can call any function you want to perform a desired task. For example, you may want to wake up your ESP32 once a day to read a value from a sensor.<\/p>\n\n\n\n<p>Next, the code defines the wake-up source by using the following function:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>esp_sleep_enable_timer_wakeup(time_in_us)<\/code><\/pre>\n\n\n\n<p>This function accepts as argument the time to sleep in microseconds as we&#8217;ve seen previously. In our case, we have the following:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);<\/code><\/pre>\n\n\n\n<p>Then, after all the tasks are performed, the ESP32 goes to sleep by calling the following function:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>esp_deep_sleep_start()<\/code><\/pre>\n\n\n\n<p>As soon as you call the <span class=\"rnthl rntliteral\">esp_deep_sleep_start()<\/span> function, the ESP32 will go to sleep and will not run any code written after this function. When it wakes up from deep sleep, it will run the code from the beginning.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">loop()<\/h3>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">loop()<\/span> section is empty because the ESP32 will sleep before reaching this part of the code. So, you need to write all your tasks in the <span class=\"rnthl rntliteral\">setup()<\/span> before calling the <span class=\"rnthl rntliteral\">esp_deep_sleep_start()<\/span> function.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Testing the Timer Wake Up<\/h3>\n\n\n\n<p>Upload the example sketch 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>Every 5 seconds, the ESP32 wakes up, prints a message on the serial monitor, and goes to deep sleep again.<\/p>\n\n\n\n<p>Every time the ESP32 wakes up, the <span class=\"rnthl rntliteral\">bootCount<\/span> variable increases. It also prints the wake-up reason as shown in the figure below.<\/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=\"755\" height=\"612\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/ESP32_timer_wake-up_demonstration.png?resize=755%2C612&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 Timer Wake-Up Demonstration\" class=\"wp-image-162947\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/ESP32_timer_wake-up_demonstration.png?w=755&amp;quality=100&amp;strip=all&amp;ssl=1 755w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/ESP32_timer_wake-up_demonstration.png?resize=300%2C243&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 755px) 100vw, 755px\" \/><\/figure><\/div>\n\n\n<p>However, notice that if you press the EN button on the ESP32 board, it resets the boot count to 1 again.<\/p>\n\n\n\n<p>You can modify the provided example, and instead of printing a message you can make your ESP do any other task. The timer wake up is useful to perform periodic tasks with the ESP32, like daily tasks, without draining much power.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"touch-wake-up\">Touch Wake Up<\/h2>\n\n\n\n<p>You can wake up the ESP32 from deep sleep using the touch pins. This section shows how to do that using the Arduino IDE.<\/p>\n\n\n<div class=\"wp-block-image is-resized\">\n<figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"302\" height=\"303\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/touch-wake-up.png?resize=302%2C303&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Touch Wake Up\" class=\"wp-image-81691\" style=\"width:158px;height:auto\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/touch-wake-up.png?w=302&amp;quality=100&amp;strip=all&amp;ssl=1 302w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/touch-wake-up.png?resize=150%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/touch-wake-up.png?resize=300%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/touch-wake-up.png?resize=80%2C80&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/touch-wake-up.png?resize=220%2C220&amp;quality=100&amp;strip=all&amp;ssl=1 220w\" sizes=\"(max-width: 302px) 100vw, 302px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\">Enable Touch Wake-Up<\/h3>\n\n\n\n<p>Enabling the ESP32 to wake up using a touchpin is simple. In the Arduino IDE, you need to use the following function\u2014pass as argument the touch pin and the touch threshold:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>touchSleepWakeUpEnable(TOUCH_PIN, THRESHOLD);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Code<\/h3>\n\n\n\n<p>Let\u2019s see how this works using an example from the library. Open your Arduino IDE, and go to <strong>File&nbsp;<\/strong>&gt;&nbsp;<strong>Examples&nbsp;<\/strong>&gt;&nbsp;<strong>ESP32&nbsp;Deep Sleep<\/strong>, and open the <strong>TouchWakeUp <\/strong>sketch.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\nDeep Sleep with Touch Wake Up\n=====================================\nThis code displays how to use deep sleep with\na touch as a wake up source and how to store data in\nRTC memory to use it over reboots\n\nESP32 can have multiple touch pads enabled as wakeup source\nESP32-S2 and ESP32-S3 supports only 1 touch pad as wakeup source enabled\n\nThis code is under Public Domain License.\n\nAuthor:\nPranav Cherukupalli &lt;cherukupallip@gmail.com&gt;\n*\/\n\n#if CONFIG_IDF_TARGET_ESP32\n#define THRESHOLD 40   \/* Greater the value, more the sensitivity *\/\n#else                  \/\/ESP32-S2 and ESP32-S3 + default for other chips (to be adjusted) *\/\n#define THRESHOLD 5000 \/* Lower the value, more the sensitivity *\/\n#endif\n\nRTC_DATA_ATTR int bootCount = 0;\ntouch_pad_t touchPin;\n\/*\nMethod to print the reason by which ESP32\nhas 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\n\/*\nMethod to print the touchpad by which ESP32\nhas been awaken from sleep\n*\/\nvoid print_wakeup_touchpad() {\n  touchPin = esp_sleep_get_touchpad_wakeup_status();\n\n#if CONFIG_IDF_TARGET_ESP32\n  switch (touchPin) {\n    case 0:  Serial.println(&quot;Touch detected on GPIO 4&quot;); break;\n    case 1:  Serial.println(&quot;Touch detected on GPIO 0&quot;); break;\n    case 2:  Serial.println(&quot;Touch detected on GPIO 2&quot;); break;\n    case 3:  Serial.println(&quot;Touch detected on GPIO 15&quot;); break;\n    case 4:  Serial.println(&quot;Touch detected on GPIO 13&quot;); break;\n    case 5:  Serial.println(&quot;Touch detected on GPIO 12&quot;); break;\n    case 6:  Serial.println(&quot;Touch detected on GPIO 14&quot;); break;\n    case 7:  Serial.println(&quot;Touch detected on GPIO 27&quot;); break;\n    case 8:  Serial.println(&quot;Touch detected on GPIO 33&quot;); break;\n    case 9:  Serial.println(&quot;Touch detected on GPIO 32&quot;); break;\n    default: Serial.println(&quot;Wakeup not by touchpad&quot;); break;\n  }\n#else\n  if (touchPin &lt; TOUCH_PAD_MAX) {\n    Serial.printf(&quot;Touch detected on GPIO %d\\n&quot;, touchPin);\n  } else {\n    Serial.println(&quot;Wakeup not by touchpad&quot;);\n  }\n#endif\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 and touchpad too\n  print_wakeup_reason();\n  print_wakeup_touchpad();\n\n#if CONFIG_IDF_TARGET_ESP32\n  \/\/Setup sleep wakeup on Touch Pad 3 + 7 (GPIO15 + GPIO 27)\n  touchSleepWakeUpEnable(T3, THRESHOLD);\n  touchSleepWakeUpEnable(T7, THRESHOLD);\n\n#else  \/\/ESP32-S2 + ESP32-S3\n  \/\/Setup sleep wakeup on Touch Pad 3 (GPIO3)\n  touchSleepWakeUpEnable(T3, THRESHOLD);\n\n#endif\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 will never be reached\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_3_touch_wake_up\/4_3_touch_wake_up.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Setting the Threshold<\/h3>\n\n\n\n<p>The first thing you need to do is setting a threshold value for the touch pins.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#define THRESHOLD 40 \/\/ Greater the value, more the sensitivity<\/code><\/pre>\n\n\n\n<p>The values read by a touch pin decrease when you touch it. The threshold value means that the ESP32 will wake up when the value read on the touch pin is below 40. You can adjust that value depending on the desired sensitivity.<\/p>\n\n\n\n<p><strong>Important:<\/strong> however, if you\u2019re using an ESP32-S2 or ESP32-S3 model, things work a little<br>differently. That\u2019s why there\u2019s a different section in the code defining a different threshold for those boards. In this case, the lower the value, the more the sensitivity.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#if CONFIG_IDF_TARGET_ESP32\n#define THRESHOLD 40 \/\/ Greater the value, more the sensitivity\n#else \/\/ ESP32-S2 and ESP32-S3 + default for other chips (to be adjusted)\n#define THRESHOLD 5000 \/\/ Lower the value, more the sensitivity\n#endif<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Setting Touch Pins as a Wake-up Source<\/h3>\n\n\n\n<p>To set a touch pin as a wake-up source, you can use the <span class=\"rnthl rntliteral\">touchSleepWakeUpEnable()<\/span> function that accepts as arguments the touch pin and the threshold value that will wake up the board.<\/p>\n\n\n\n<p>In this example, it sets GPIO 15 (T3) and GPIO 27 (T7) as wake-up sources with the same threshold value.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#if CONFIG_IDF_TARGET_ESP32\n  \/\/ Setup sleep wakeup on Touch Pad 3 + 7 (GPIO15 + GPIO 27)\n  touchSleepWakeUpEnable(T3, THRESHOLD);\n  touchSleepWakeUpEnable(T7, THRESHOLD);<\/code><\/pre>\n\n\n\n<p>If you\u2019re using an ESP32-S2 or S3 model, the example just defines wake-up on GPIO 3 (T3). Note that the touch pin numbering might be different depending on the board model you\u2019re using.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#else \/\/ ESP32-S2 + ESP32-S3\n  \/\/ Setup sleep wakeup on Touch Pad 3 (GPIO3)\n  touchSleepWakeUpEnable(T3, THRESHOLD);<\/code><\/pre>\n\n\n\n<p>Finally, call the <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<p>These were the general instructions to set up touch pins as a wake-up source. Now, let\u2019s take a look at the other sections of the code.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">setup()<\/h3>\n\n\n\n<p>When the ESP32 wakes up from sleep, it will run the code from the start until it finds the <span class=\"rnthl rntliteral\">esp_deep_sleep_start()<\/span> function.<\/p>\n\n\n\n<p>In this particular example, we have a control variable called <span class=\"rnthl rntliteral\">bootCount<\/span> that will be increased between each sleep cycle so that we have an idea of how many times the ESP32 woke up.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Increment boot number and print it every reboot\n++bootCount;\nSerial.println(\"Boot number: \" + String(bootCount));<\/code><\/pre>\n\n\n\n<p>We also call the <span class=\"rnthl rntliteral\">print_wakeup_reason()<\/span> and <span class=\"rnthl rntliteral\">print_wakeup_touchpad()<\/span> functions defined earlier in the code to print the wake-up reason and the pin that caused the wake-up.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Print the wakeup reason for ESP32 and touchpad too\nprint_wakeup_reason();\nprint_wakeup_touchpad();<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Wiring the Circuit<\/h3>\n\n\n\n<p>To test this example, wire a cable to <span class=\"rnthl rntcgreen\">GPIO 15<\/span>, as shown in the schematic below.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"858\" height=\"349\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/Zero_Touch_Wake_Up_bb.png?resize=858%2C349&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Touch wake-up signal Wiring the Circuit\" class=\"wp-image-81674\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/Zero_Touch_Wake_Up_bb.png?w=858&amp;quality=100&amp;strip=all&amp;ssl=1 858w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/Zero_Touch_Wake_Up_bb.png?resize=300%2C122&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/02\/Zero_Touch_Wake_Up_bb.png?resize=768%2C312&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 858px) 100vw, 858px\" \/><\/figure><\/div>\n\n\n<p>If you\u2019re using an ESP32-S2 or <a href=\"https:\/\/randomnerdtutorials.com\/esp32-s3-devkitc-pinout-guide\/\" title=\"\">ESP32-S3 model<\/a>, please check the location of your touch pins.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Testing the Example<\/h3>\n\n\n\n<p>Upload the code to your ESP32, and 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\"><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\"\/><\/figure><\/div>\n\n\n<p>The ESP32 goes into deep sleep mode.<\/p>\n\n\n\n<p>You can wake it up by touching the wire connected to Touch Pin 3.<\/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-Touch-Sensor-Pins-Arduino-IDE.jpg?resize=750%2C421&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 Touch Sensor Pins Arduino IDE\" class=\"wp-image-163125\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/ESP32-Touch-Sensor-Pins-Arduino-IDE.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-Touch-Sensor-Pins-Arduino-IDE.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>When you touch the pin, the ESP32 displays on the Serial Monitor: the boot number, the wake-up cause, and which touch-sensitive GPIO 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=\"694\" height=\"366\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/ESP32_testing_touch_wake_up.png?resize=694%2C366&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Testing ESP32 touch pins as a wake-up source Serial Monitor Demonstration\" class=\"wp-image-162959\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/ESP32_testing_touch_wake_up.png?w=694&amp;quality=100&amp;strip=all&amp;ssl=1 694w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/ESP32_testing_touch_wake_up.png?resize=300%2C158&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 694px) 100vw, 694px\" \/><\/figure><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"external-wake-up\">External Wake Up<\/h2>\n\n\n\n<p>Besides the timer and the touch pins, we can also awake the ESP32 from deep sleep by toggling the value of a signal on a pin, like the press of a button. This is called an external wake up. 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\" loading=\"lazy\" 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:179px;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<h3 class=\"wp-block-heading\">External Wake Up (ext0)<\/h3>\n\n\n\n<p>This wake up source allows you to use a pin to wake up the ESP32.<\/p>\n\n\n\n<p>The ext0 wake up source option uses RTC GPIOs to wake up. So, RTC peripherals will be 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 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 class=\"rntbox rntclgreen\"><strong>Note: <\/strong> with this wake up source, you can only use pins that are RTC GPIOs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">External Wake Up (ext1)<\/h3>\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<h3 class=\"wp-block-heading\">Code<\/h3>\n\n\n\n<p>Let\u2019s explore the example that comes with the ESP32 library. Go to <strong>File<\/strong> &gt; <strong>Examples<\/strong> &gt; <strong>ESP32<\/strong> <strong>Deep Sleep<\/strong> &gt; <strong>ExternalWakeUp<\/strong>:<\/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\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/esp32-pushbutton-33-1.png?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"534\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/esp32-pushbutton-33-1.png?resize=750%2C534&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 pushbutton connected to gpio 333\" class=\"wp-image-162984\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/04\/esp32-pushbutton-33-1.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-1.png?resize=300%2C214&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/a><\/figure><\/div>\n\n\n<p class=\"rntbox rntclgreen\"><strong>Note: <\/strong> only RTC GPIOs can be used as a wake up source. Instead of GPIO 33, you could also 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<\/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 article we&#8217;ve shown you how to use deep sleep with the ESP32 and different ways to wake it up. You can wake up the ESP32 using a timer, the touch pins, or a change on a GPIO state.<\/p>\n\n\n\n<p>Let&#8217;s summarize what you&#8217;ve learned about each wake-up source:<\/p>\n\n\n\n<p><strong><a href=\"https:\/\/randomnerdtutorials.com\/esp32-timer-wake-up-deep-sleep\/\">Timer Wake Up<\/a><\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To enable the timer wake-up, you use the <span class=\"rnthl rntliteral\">esp_sleep_enable_timer_wakeup(time_in_us)<\/span> function;<\/li>\n\n\n\n<li>Use the <span class=\"rnthl rntliteral\">esp_deep_sleep_start()<\/span> function to start deep sleep. <\/li>\n<\/ul>\n\n\n\n<p><strong><a href=\"https:\/\/randomnerdtutorials.com\/esp32-touch-wake-up-deep-sleep\/\">Touch Wake Up<\/a><\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To enable the touch pins as a wake-up source use the <span class=\"rnthl rntliteral\">touchSleepWakeUpEnable()<\/span> function;<\/li>\n\n\n\n<li>Finally, you use the <span class=\"rnthl rntliteral\">esp_deep_sleep_start()<\/span> function to put the ESP32 in deep sleep mode. <\/li>\n<\/ul>\n\n\n\n<p><strong><a href=\"https:\/\/randomnerdtutorials.com\/esp32-external-wake-up-deep-sleep\/\">External Wake Up<\/a><\/strong><\/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 several GPIO pins.<\/li>\n<\/ul>\n\n\n\n<p>We hope you&#8217;ve found this guide useful. If you want to learn more about ESP32, make sure you check all our <a href=\"https:\/\/randomnerdtutorials.com\/projects-esp32\/\">ESP32 projects<\/a> and our <a href=\"https:\/\/randomnerdtutorials.com\/learn-esp32-with-arduino-ide\/\">ESP32 eBook<\/a>.<\/p>\n\n\n\n<p class=\"rntbox rntclgray\">This is an excerpt from our course: <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 is a complete guide for the ESP32 deep sleep mode with Arduino IDE. We&#8217;ll show you how to put the ESP32 into deep sleep and take a look at different modes to wake it up: timer wake up, touch wake up, and external wake up.  <\/p>\n<p class=\"read-more-container\"><a href=\"https:\/\/randomnerdtutorials.com\/esp32-deep-sleep-arduino-ide-wake-up-sources\/\" class=\"read-more button\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":162996,"comment_status":"open","ping_status":"open","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-81663","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\/03\/ESP32-Deep-Sleep-and-wake-up-sources.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\/81663","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=81663"}],"version-history":[{"count":9,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/81663\/revisions"}],"predecessor-version":[{"id":171425,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/81663\/revisions\/171425"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/162996"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=81663"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=81663"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=81663"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}