<h1 class="sectionedit1" id="esp32_deep_sleep_mode" style="padding: 0px; line-height: 1.2; clear: left; margin: 0px 0px 0.444em; color: #333333;">ESP32 Deep Sleep Mode</h1>
<div class="level1" style="margin: 0px; padding: 0px; color: #333333; font-size: 14px;">&nbsp;</div>
<h2 class="sectionedit2" id="about_esp32_deep_sleep" style="padding: 0px; line-height: 1.2; clear: left; margin: 0px 0px 0.666em; color: #333333;">1. About ESP32 Deep Sleep</h2>
<div class="level2" style="margin: 0px; padding: 0px; color: #333333; font-size: 14px;">
   <p style="margin-bottom: 1.4em; padding: 0px;">In this project the ESP32 is idle for more than 95% of the time because it is supposed to take measurements only once an hour, transmit the data and wait again. However, the ESP32 has the possibility to be run in different power modes. Besides the active mode where all peripherals are powered, there are also the modem-sleep mode, light-sleep mode, deep-sleep mode, hibernation mode and power-off mode.</p>
   <p style="margin-bottom: 1.4em; padding: 0px;">As explained in the&nbsp;<a href="https://wiki.eolab.de/doku.php?id=amc2020:group_n:ds3231rtc" class="wikilink1" title="amc2020:group_n:ds3231rtc" data-wiki-id="amc2020:group_n:ds3231rtc" style="outline: none; text-decoration-line: none; color: #008800;" target="_blank">DS3231</a>&nbsp;page, the ESP32 can be put to sleep to save a lot of energy from the battery and only wake up once an hour by an interrupt signal from the DS3231 RTC module. For the ESP32 to wake up from an external interrupt, the real time clock (RTC) peripherals (RTC timer + RTC memory) must remain powered on. The power mode with the lowest energy consumption and RTC peripherals still powered on is the deep sleep mode with only RTC timer and RTC memory powered. In this mode, the module draws only 10&nbsp;<span class="MathJax_Preview" style="color: inherit; display: contents;"></span><span id="MathJax-Element-1-Frame" class="mjx-chtml MathJax_CHTML" tabindex="0" data-mathml="<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>&amp;#x03BC;</mi><mi>A</mi></math>" role="presentation" style="display: inline-block; line-height: 0; font-size: 16.66px; font-size-adjust: none; overflow-wrap: normal; word-spacing: normal; text-wrap: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; margin: 0px; padding: 1px 0px; position: relative;"><span id="MJXc-Node-1" class="mjx-math" aria-hidden="true" style="display: inline-block; border-collapse: separate; border-spacing: 0px;"><span id="MJXc-Node-2" class="mjx-mrow" style="display: inline-block; box-sizing: content-box !important;"><span id="MJXc-Node-3" class="mjx-mi" style="display: inline-block; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-math-I" style="display: block; white-space-collapse: preserve; font-family: MJXc-TeX-math-I, MJXc-TeX-math-Ix, MJXc-TeX-math-Iw; padding-top: 0.243em; padding-bottom: 0.483em; box-sizing: content-box !important;">μ</span></span><span id="MJXc-Node-4" class="mjx-mi" style="display: inline-block; box-sizing: content-box !important;"><span class="mjx-char MJXc-TeX-math-I" style="display: block; white-space-collapse: preserve; font-family: MJXc-TeX-math-I, MJXc-TeX-math-Ix, MJXc-TeX-math-Iw; padding-top: 0.483em; padding-bottom: 0.303em; box-sizing: content-box !important;">A</span></span></span></span><span class="MJX_Assistive_MathML" role="presentation" style="top: 0px; left: 0px; clip: rect(1px, 1px, 1px, 1px); user-select: none; position: absolute !important; padding: 1px 0px 0px !important; border: 0px !important; height: 1px !important; width: 1px !important; overflow: hidden !important; display: block !important;"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>μ</mi><mi>A</mi></math></span></span>&nbsp;of current, which is a several thousand times less than in the active mode (see the&nbsp;<a href="https://wiki.eolab.de/lib/exe/fetch.php?tok=ade601&amp;media=https%3A%2F%2Fwww.espressif.com%2Fsites%2Fdefault%2Ffiles%2Fdocumentation%2Fesp32_datasheet_en.pdf" class="media mediafile mf_pdf" target="_blank" title="https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf" rel="noopener" style="outline: none; background-image: url(&quot;/lib/images/fileicons/svg/pdf.svg&quot;); background-position: 0px center; background-size: 1.2em; background-repeat: no-repeat; background-attachment: initial; background-origin: initial; background-clip: initial; padding: 0px 0px 0px 1.4em; text-decoration-line: none; color: #2b73b7;">ESP32 datasheet</a>&nbsp;pp 23 -24). However, like this it is only possible to use the RTC_GPIO pins (figure 1), not the other GPIOs to read the interrupt signal.</p>
   <div class="table sectionedit3" style="margin: 0px 0px 1.4em; padding: 0px; overflow-x: auto; min-width: 50%;">
      <table class="inline" style="margin: 0px; padding: 0px; empty-cells: show; border-spacing: 0px; border-style: solid; min-width: 50%;">
         <thead>
            <tr class="row0">
               <th class="col0" style="padding: 0.3em 0.5em; margin: 0px; vertical-align: top; border-style: solid; background-color: #eeeeee; text-align: left;"><a href="https://wiki.eolab.de/lib/exe/fetch.php?media=amc2020:group_n:esp_32_devkitc-vb_pinout_wroom_.jpg" class="media" target="_blank" title="amc2020:group_n:esp_32_devkitc-vb_pinout_wroom_.jpg" rel="noopener" style="outline: none; text-decoration-line: none; color: #2b73b7;"><img src="https://wiki.eolab.de/lib/exe/fetch.php?w=800&amp;tok=0a45a9&amp;media=amc2020:group_n:esp_32_devkitc-vb_pinout_wroom_.jpg" class="media" loading="lazy" title="Figure 1" alt="Figure 1" width="800" style="border-width: 0px; vertical-align: middle; color: #666666; background-color: transparent; font-style: italic; object-fit: cover; max-width: 50vw; margin: 0.2em 0px;" /></a></th>
               </tr>
            </thead>
         <tbody>
            <tr class="row1">
               <td class="col0" style="padding: 0.3em 0.5em; margin: 0px; vertical-align: top; border-style: solid;"><strong><em>Figure 1</em></strong>&nbsp;ESP32 DevKit Pinout (Source:&nbsp;<a href="https://live.staticflickr.com/4764/40089095211_ec1fee0087_b.jpg" class="urlextern" target="_blank" title="https://live.staticflickr.com/4764/40089095211_ec1fee0087_b.jpg" rel="ugc nofollow noopener" style="outline: none; text-decoration-line: none; color: #2b73b7; background-size: 1.2em; background-repeat: no-repeat; background-position: 0px center; padding: 0px 0px 0px 1.4em; background-image: url(&quot;/lib/tpl/dokuwiki/../../images/external-link.svg&quot;);">ESP32 DevKit 38 Pins</a>)</td>
               </tr>
            </tbody>
         </table>
      </div>
   </div>
<h2 class="sectionedit4" id="setup_of_the_ds3231_with_the_esp32" style="padding: 0px; line-height: 1.2; clear: left; margin: 0px 0px 0.666em; color: #333333;">2. Setup of the DS3231 with the ESP32</h2>
<div class="level2" style="margin: 0px; padding: 0px; color: #333333; font-size: 14px;">
   <p style="margin-bottom: 1.4em; padding: 0px;">As the DS3231 is an open drain device, the SQW pin connected to one of the RTC_GPIO pins needs to be pulled to high voltage using a pullup resistor. In the case of the Arduino UNO sketch, the Arduino's internal pullup resistor was used. The ESP32 also has internal pullup resistors, but their value strongly fluctuates from module to module and pin to pin and generally lies between 30 - 80 kΩ. Furthermore, it is somewhat complicated to control the pins during deep sleep mode to activate the pullups. Therefore, a 100kΩ external pullup resistor was used to connect the interrupt pin to 3.3V which also results in a lower current being drawn when the interrupt is triggered.</p>
   <p style="margin-bottom: 1.4em; padding: 0px;">The DS3231 was connected the following way:</p>
   <ul style="margin: 0px 0px 1.4em; padding: 0px 0px 0px 1.5em; list-style: outside square;">
      <li class="level1" style="padding: 0px; margin: 0px 0px 0px 1.5em; color: #999999;">
         <div class="li" style="margin: 0px; padding: 0px; color: #333333;">VCC to 3.3 V</div>
         </li>
      <li class="level1" style="padding: 0px; margin: 0px 0px 0px 1.5em; color: #999999;">
         <div class="li" style="margin: 0px; padding: 0px; color: #333333;">GND to GND</div>
         </li>
      <li class="level1" style="padding: 0px; margin: 0px 0px 0px 1.5em; color: #999999;">
         <div class="li" style="margin: 0px; padding: 0px; color: #333333;">SDA to GPIO 21</div>
         </li>
      <li class="level1" style="padding: 0px; margin: 0px 0px 0px 1.5em; color: #999999;">
         <div class="li" style="margin: 0px; padding: 0px; color: #333333;">SCL to GPIO 22</div>
         </li>
      <li class="level1" style="padding: 0px; margin: 0px 0px 0px 1.5em; color: #999999;">
         <div class="li" style="margin: 0px; padding: 0px; color: #333333;">SQW to GPIO 13 (RTC_GPIO14) (and 3.3V through the pullup resistor).</div>
         </li>
      </ul>
   <p style="margin-bottom: 1.4em; padding: 0px;">The connections can also be seen in the diagram in figure 2.</p>
   <div class="table sectionedit5" style="margin: 0px 0px 1.4em; padding: 0px; overflow-x: auto; min-width: 50%;">
      <table class="inline" style="margin: 0px; padding: 0px; empty-cells: show; border-spacing: 0px; border-style: solid; min-width: 50%;">
         <thead>
            <tr class="row0">
               <th class="col0" style="padding: 0.3em 0.5em; margin: 0px; vertical-align: top; border-style: solid; background-color: #eeeeee; text-align: left;"><a href="https://wiki.eolab.de/lib/exe/fetch.php?media=amc2020:group_n:esp32_ds3231.png" class="media" target="_blank" title="amc2020:group_n:esp32_ds3231.png" rel="noopener" style="outline: none; text-decoration-line: none; color: #2b73b7;"><img src="https://wiki.eolab.de/lib/exe/fetch.php?w=800&amp;tok=f891e3&amp;media=amc2020:group_n:esp32_ds3231.png" class="media" loading="lazy" title="Figure 2" alt="Figure 2" width="800" style="border-width: 0px; vertical-align: middle; color: #666666; background-color: transparent; font-style: italic; object-fit: cover; max-width: 50vw; margin: 0.2em 0px;" /></a></th>
               </tr>
            </thead>
         <tbody>
            <tr class="row1">
               <td class="col0" style="padding: 0.3em 0.5em; margin: 0px; vertical-align: top; border-style: solid;"><strong><em>Figure 2</em></strong>&nbsp;Setup of DS3231 and ESP32.</td>
               </tr>
            </tbody>
         </table>
      </div>
   </div>
<h2 class="sectionedit6" id="programming" style="padding: 0px; line-height: 1.2; clear: left; margin: 0px 0px 0.666em; color: #333333;">3. Programming</h2>
<div class="level2" style="margin: 0px; padding: 0px; color: #333333; font-size: 14px;">
   <p style="margin-bottom: 1.4em; padding: 0px;">After setting up the module with the ESP32, the programming for the deep sleep is very simple. For the following test, the DS3231 was programmed to trigger an interrupt once a minute, i.e. the setting was changed to&nbsp;<b><font face="Courier New">ALARM_SECONDS_MATCH</font></b>. How to do that is explained in the&nbsp;<a href="https://wiki.eolab.de/doku.php?id=amc2020:group_n:ds3231rtc" class="wikilink1" title="amc2020:group_n:ds3231rtc" data-wiki-id="amc2020:group_n:ds3231rtc" style="outline: none; text-decoration-line: none; color: #008800;" target="_blank">DS3231</a>&nbsp;page.</p>
   </div>
<h3 class="sectionedit7" id="code" style="padding: 0px; line-height: 1.2; clear: left; font-size: 1.125em; margin: 0px 0px 0.888em; color: #333333;">3.1 Code</h3>
<div class="level3" style="margin: 0px; padding: 0px; color: #333333; font-size: 14px;">
   <dl class="file" style="margin: 0px 0px 1.4em; padding: 0px;"><dt style="font-weight: bold; margin: 0px 0px -1px; padding: 0.3em 0.6em 0.1em; background-image: linear-gradient(rgb(238, 238, 238) 0px, rgb(251, 250, 249) 100%); background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; color: inherit; border-width: 1px; border-style: dashed dashed solid; border-color: #cccccc rgb(204, 204, 204) rgb(251, 250, 249); border-image: initial; border-top-left-radius: 0.3em; border-top-right-radius: 0.3em; float: left;"><a href="https://wiki.eolab.de/doku.php?do=export_code&amp;id=amc2020:group_n:deepsleep&amp;codeblock=0" title="Download Snippet" class="mediafile mf_ino" style="outline: none; background-image: url(&quot;/lib/images/fileicons/svg/file.svg&quot;); background-position: 0px center; background-size: 1.2em; background-repeat: no-repeat; background-attachment: initial; background-origin: initial; background-clip: initial; padding: 0px 0px 0px 1.4em; text-decoration-line: none; color: #2b73b7; font-size: 0.875em; font-weight: normal; display: block; min-height: 16px;" target="_blank">ESP32_DS3231_Deep_Sleep_test.ino</a></dt>
      <dd style="padding: 0px; margin: 0px; clear: left;">
         <div class="cp2clipcont desktop" style="margin: 0px 0px 19.6px; padding: 0px; position: relative; border: none; overflow: auto;">
            <pre class="code file c" style="margin-top: 0px; margin-bottom: 0px; padding: 0.7em 1em; font-family: Consolas, &quot;Andale Mono WT&quot;, &quot;Andale Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, &quot;Nimbus Mono L&quot;, Monaco, &quot;Courier New&quot;, monospace; font-size: 1em; direction: ltr; background-color: #fbfaf9; box-shadow: rgb(204, 204, 204) -4px -4px 0.5em -0.3em inset; border-radius: 2px; overflow: auto; overflow-wrap: normal; border: 1px dashed rgb(204, 204, 204);"><span class="co1" style="color: #808080; font-style: italic;">//ESP32 DS3231 Deep Sleep Test</span>
&nbsp;
<span class="co2" style="color: #339933;">#include &lt;Wire.h&gt;</span><span class="co2" style="color: #339933;">#define DS3231RTC_I2C_ADDRESS 0x68</span><span class="co2" style="color: #339933;">#define I2C_SDA 21                                  //1</span><span class="co2" style="color: #339933;">#define I2C_SCL 22</span>
&nbsp;
<span class="kw4" style="color: #993333;">void</span> clearAlarm1<span class="br0" style="color: #66cc66;">(</span><span class="br0" style="color: #66cc66;">)</span><span class="br0" style="color: #66cc66;">{</span><span class="co1" style="color: #808080; font-style: italic;">//2    </span>
  Wire.<span class="me1" style="color: #006600;">beginTransmission</span><span class="br0" style="color: #66cc66;">(</span>DS3231RTC_I2C_ADDRESS<span class="br0" style="color: #66cc66;">)</span><span class="sy0" style="color: #66cc66;">;</span>
  Wire.<span class="me1" style="color: #006600;">write</span><span class="br0" style="color: #66cc66;">(</span><span class="nu12">0x0F</span><span class="br0" style="color: #66cc66;">)</span><span class="sy0" style="color: #66cc66;">;</span>                               
  Wire.<span class="me1" style="color: #006600;">write</span><span class="br0" style="color: #66cc66;">(</span>B00000000<span class="br0" style="color: #66cc66;">)</span><span class="sy0" style="color: #66cc66;">;</span>                          
  Wire.<span class="me1" style="color: #006600;">endTransmission</span><span class="br0" style="color: #66cc66;">(</span><span class="br0" style="color: #66cc66;">)</span><span class="sy0" style="color: #66cc66;">;</span><span class="br0" style="color: #66cc66;">}</span>
&nbsp;
<span class="kw4" style="color: #993333;">void</span> setup<span class="br0" style="color: #66cc66;">(</span><span class="br0" style="color: #66cc66;">)</span><span class="br0" style="color: #66cc66;">{</span>
  Wire.<span class="me1" style="color: #006600;">begin</span><span class="br0" style="color: #66cc66;">(</span>I2C_SDA<span class="sy0" style="color: #66cc66;">,</span> I2C_SCL<span class="br0" style="color: #66cc66;">)</span><span class="sy0" style="color: #66cc66;">;</span><span class="co1" style="color: #808080; font-style: italic;">//3</span>
  clearAlarm1<span class="br0" style="color: #66cc66;">(</span><span class="br0" style="color: #66cc66;">)</span><span class="sy0" style="color: #66cc66;">;</span><span class="co1" style="color: #808080; font-style: italic;">//4</span>
  Serial.<span class="me1" style="color: #006600;">begin</span><span class="br0" style="color: #66cc66;">(</span><span class="nu0" style="color: #cc66cc;">115200</span><span class="br0" style="color: #66cc66;">)</span><span class="sy0" style="color: #66cc66;">;</span><span class="co1" style="color: #808080; font-style: italic;">//5</span>
  delay<span class="br0" style="color: #66cc66;">(</span><span class="nu0" style="color: #cc66cc;">1000</span><span class="br0" style="color: #66cc66;">)</span><span class="sy0" style="color: #66cc66;">;</span>
  Serial.<span class="me1" style="color: #006600;">println</span><span class="br0" style="color: #66cc66;">(</span><span class="st0" style="color: #ff0000;">"ESP32 woke up from deep sleep."</span><span class="br0" style="color: #66cc66;">)</span><span class="sy0" style="color: #66cc66;">;</span><span class="kw1" style="color: #b1b100;">for</span><span class="br0" style="color: #66cc66;">(</span><span class="kw4" style="color: #993333;">int</span> i<span class="sy0" style="color: #66cc66;">=</span><span class="nu0" style="color: #cc66cc;">3</span><span class="sy0" style="color: #66cc66;">;</span>i<span class="sy0" style="color: #66cc66;">&gt;=</span><span class="nu0" style="color: #cc66cc;">0</span><span class="sy0" style="color: #66cc66;">;</span>i<span class="sy0" style="color: #66cc66;">--</span><span class="br0" style="color: #66cc66;">)</span><span class="br0" style="color: #66cc66;">{</span>
    Serial.<span class="me1" style="color: #006600;">print</span><span class="br0" style="color: #66cc66;">(</span><span class="st0" style="color: #ff0000;">"Going back to sleep in "</span><span class="br0" style="color: #66cc66;">)</span><span class="sy0" style="color: #66cc66;">;</span>
    Serial.<span class="me1" style="color: #006600;">println</span><span class="br0" style="color: #66cc66;">(</span>i<span class="br0" style="color: #66cc66;">)</span><span class="sy0" style="color: #66cc66;">;</span>
    delay<span class="br0" style="color: #66cc66;">(</span><span class="nu0" style="color: #cc66cc;">1000</span><span class="br0" style="color: #66cc66;">)</span><span class="sy0" style="color: #66cc66;">;</span><span class="br0" style="color: #66cc66;">}</span>
  esp_sleep_enable_ext0_wakeup<span class="br0" style="color: #66cc66;">(</span>GPIO_NUM_13<span class="sy0" style="color: #66cc66;">,</span><span class="nu0" style="color: #cc66cc;">0</span><span class="br0" style="color: #66cc66;">)</span><span class="sy0" style="color: #66cc66;">;</span><span class="co1" style="color: #808080; font-style: italic;">//6</span>
  esp_deep_sleep_start<span class="br0" style="color: #66cc66;">(</span><span class="br0" style="color: #66cc66;">)</span><span class="sy0" style="color: #66cc66;">;</span><span class="co1" style="color: #808080; font-style: italic;">//7</span>
  Serial.<span class="me1" style="color: #006600;">println</span><span class="br0" style="color: #66cc66;">(</span><span class="st0" style="color: #ff0000;">"This will never be printed."</span><span class="br0" style="color: #66cc66;">)</span><span class="sy0" style="color: #66cc66;">;</span><span class="co1" style="color: #808080; font-style: italic;">//8</span><span class="br0" style="color: #66cc66;">}</span>
&nbsp;
<span class="kw4" style="color: #993333;">void</span> loop<span class="br0" style="color: #66cc66;">(</span><span class="br0" style="color: #66cc66;">)</span><span class="br0" style="color: #66cc66;">{</span><span class="co1" style="color: #808080; font-style: italic;">//This is not going to be called.</span><span class="br0" style="color: #66cc66;">}</span></pre>
            <button title="Copy to clipboard" style="font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: inherit; font-family: inherit; font-optical-sizing: inherit; font-size-adjust: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; font-weight: normal; color: #333333; background: url(&quot;/lib/plugins/copy2clipboard/clipmini.svg&quot;) 0px 0px / 12px no-repeat rgb(187, 187, 187); margin: 0px; vertical-align: middle; border-width: 1px; border-style: solid; border-color: #cccccc; border-radius: 2px; padding: 0.1em 0.5em; cursor: pointer; position: absolute; top: 0px; right: 0px; width: 13px; height: 18px; visibility: hidden;"></button></div>
         </dd>
      </dl>
   </div>
<h3 class="sectionedit8" id="the_code_explained" style="padding: 0px; line-height: 1.2; clear: left; font-size: 1.125em; margin: 0px 0px 0.888em; color: #333333;">3.2 The Code Explained</h3>
<div class="level3" style="margin: 0px; padding: 0px; color: #333333; font-size: 14px;">
   <p style="margin-bottom: 1.4em; padding: 0px;">&nbsp;</p>
   <ol style="margin: 0px 0px 1.4em; padding: 0px 0px 0px 1.5em; list-style-position: outside; list-style-image: initial;">
      <li style="padding: 0px; margin: 0px 0px 0px 1.5em; color: #666666;">After including the&nbsp;<b><font face="Courier New"><font style="color: #cd5307;">Wire</font>.h</font>&nbsp;</b>library for I2C communication and defining the DS3231 I2C address as&nbsp;<b><font face="Courier New">0x68</font></b>, the I2C pins of the ESP32 need to be defined. By default SCL is GPIO 22 and SDA is GPIO 21, but it is possible to use almost all pins for I2C communication if done correctly. Here just the default pins are used.</li>
      <li style="padding: 0px; margin: 0px 0px 0px 1.5em; color: #666666;">The function&nbsp;<b><font face="Courier New">clearAlarm1()</font></b>&nbsp;is the only one, that must be copied into the new sketch.</li>
      <br />
      <li style="padding: 0px; margin: 0px 0px 0px 1.5em; color: #666666;">When using the&nbsp;<b><font face="Courier New"><font style="color: #cd5307;">Wire</font>.<font style="color: #cd5307;">begin</font>()</font></b>&nbsp;method to start the I2C bus, the I2C pins previously defined need to be given as argument.</li>
      <li style="padding: 0px; margin: 0px 0px 0px 1.5em; color: #666666;">After waking up, the alarm flag 1 of the DS3231's status register needs to be reset, otherwise the interrupt is fired continuously and the ESP32 would immediately wake up again after going into sleep mode. Therefore,&nbsp;<b><font face="Courier New">clearAlarm1()</font></b>&nbsp;is used to reset the alarm in the beginning.</li>
      <li style="padding: 0px; margin: 0px 0px 0px 1.5em; color: #666666;">The serial connection is started to test whether the sketch is working. After waking up, the ESP32 prints some data to the monitor. Then a counter is counting down from 3 to 0 and the ESP32 goes back into deep sleep.</li>
      <li style="padding: 0px; margin: 0px 0px 0px 1.5em; color: #666666;">The function&nbsp;<b><font face="Courier New">esp_sleep_enable_ext0_wakeup()</font></b>&nbsp;defines the method for waking the ESP32 up from deep sleep. The&nbsp;<b><font face="Courier New">ext0</font></b>&nbsp;means that the the wake up source is external and can only be triggered by a single pin. The number of the pin is given in the argument as&nbsp;<b><font face="Courier New">GPIO_NUM_X</font></b>&nbsp;where X represents the GPIO number of that pin. The second argument (level) defines which state the pin needs to be in to wake the ESP32 up. A&nbsp;<b><font face="Courier New">1</font></b>&nbsp;means that it will wake up, when the voltage is 3.3V. A&nbsp;<b><font face="Courier New">0</font></b>&nbsp;means it wakes up when it is 0V. As the DS3231 pulls the pin to GND when the alarm is activated, the level needs to be&nbsp;<b><font face="Courier New">0</font></b>.</li>
      <li style="padding: 0px; margin: 0px 0px 0px 1.5em; color: #666666;">The function&nbsp;<b><font face="Courier New">esp_deep_sleep_start()</font></b>&nbsp;changes the power mode of the ESP32 to deep sleep.</li>
      <li style="padding: 0px; margin: 0px 0px 0px 1.5em; color: #666666;">When the deep sleep is activated, the rest of the program code is just not executed. After resetting, the ESP32 starts again with the&nbsp;<b><font face="Courier New"><font style="color: #5a6b0f;">setup</font>()</font></b>. Therefore, this line should never be printed to the serial monitor; otherwise there is an error. The program also never reaches the main&nbsp;<b><font face="Courier New"><font style="color: #5a6b0f;">loop</font>()</font></b>.</li>
      </ol>
   <p style="margin-bottom: 1.4em; padding: 0px;">&nbsp;</p>
   </div>
<h3 class="sectionedit9" id="results" style="padding: 0px; line-height: 1.2; clear: left; font-size: 1.125em; margin: 0px 0px 0.888em; color: #333333;">3.3 Results</h3>
<div class="level3" style="margin: 0px; padding: 0px; color: #333333; font-size: 14px;">
   <p style="margin-bottom: 1.4em; padding: 0px;">Apart from the timestamps on the left, the result in the serial monitor should look like this. In the data that the ESP32 prints by itself, it can be seen that the reset occured due to waking up from deep sleep (1). Furthermore, the last serial print command was not executed because deep sleep was activated before that could happen.</p>
   <p style="margin-bottom: 1.4em; padding: 0px;">When comparing the time stamps (1, 3 and 4) it becomes visible that the wake up from deep sleep occurred always 1 minute after the last wake up. However, the milliseconds are always varying a little bit. This might be due to the temperature compensation of the DS3231 through which the capacitance and therefore the frequency of the oscillator are changed. So, there might be very small inaccuracies, but they are constantly compensated for by the module, such that the total drift stays very low.</p>
   </div>