# Esp32-c3 super mini deepsleep doorsensor

**URL:** <https://forum.arduino.cc/t/esp32-c3-super-mini-deepsleep-doorsensor/1401895>\
**Category:** Programming\
**Created:** [August 12, 2025, 6:32pm UTC](https://forum.arduino.cc/t/esp32-c3-super-mini-deepsleep-doorsensor/1401895 "2025-08-12T18:32:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![robban75](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robban75/32/1126393_2.png) [@robban75](https://forum.arduino.cc/u/robban75)\
**Post date:** [August 12, 2025, 6:32pm UTC](https://forum.arduino.cc/t/esp32-c3-super-mini-deepsleep-doorsensor/1401895/1 "2025-08-12T18:32:54Z")

</div>

Hi

I am trying to get the ESP32-c3 super mini to wake up from deepsleep when the door contact is closed and open. But so far i am only able to get it to wake up when the sensor is open.

Is there anyway that you can use like:

esp\_deep\_sleep\_enable\_gpio\_wakeup(1 \<\< 1, ESP\_GPIO\_WAKEUP\_GPIO\_BOTH);

now i only have

esp\_deep\_sleep\_enable\_gpio\_wakeup(1 \<\< 1, ESP\_GPIO\_WAKEUP\_GPIO\_LOW);

i have also tried to use

esp\_deep\_sleep\_enable\_gpio\_wakeup(1 \<\< 1, ESP\_GPIO\_WAKEUP\_GPIO\_LOW);

esp\_deep\_sleep\_enable\_gpio\_wakeup(1 \<\< 1, ESP\_GPIO\_WAKEUP\_GPIO\_HIGH);

but it doesnt work.

Any ideas?

Robert

---

<div class="post-metadata">

**Author:** ![sonofcy](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sonofcy/32/1283617_2.png) [@sonofcy](https://forum.arduino.cc/u/sonofcy)\
**Post date:** [August 12, 2025, 6:54pm UTC](https://forum.arduino.cc/t/esp32-c3-super-mini-deepsleep-doorsensor/1401895/2 "2025-08-12T18:54:21Z")

</div>

Usually there is a CHANGE option. The API doc should tell you what it has like LOW, HIGH, CHANGE, RISING, FALLING etc.

---

<div class="post-metadata">

**Author:** ![kmin](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kmin/32/1147370_2.png) [@kmin](https://forum.arduino.cc/u/kmin)\
**Post date:** [August 12, 2025, 8:41pm UTC](https://forum.arduino.cc/t/esp32-c3-super-mini-deepsleep-doorsensor/1401895/3 "2025-08-12T20:41:46Z")

</div>

> [@robban75](#):
>
> Any ideas?

Very confusing at the best.  
You could try something like this (not tested):  
(Use RTC pin for WAKE\_PIN)

```arduino
  gpio_wakeup_enable(WAKE_PIN, GPIO_INTR_ANYEDGE);
  esp_deep_sleep_enable_gpio_wakeup();

```

If it doesn't work, another approach could be to read the state of the pin before sleep and set the wakeup logic according to that.

---

<div class="post-metadata">

**Author:** ![robban75](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robban75/32/1126393_2.png) [@robban75](https://forum.arduino.cc/u/robban75)\
**Post date:** [August 13, 2025, 6:34pm UTC](https://forum.arduino.cc/t/esp32-c3-super-mini-deepsleep-doorsensor/1401895/4 "2025-08-13T18:34:35Z")

</div>

i have tried this but i get

too few arguments to function ‘esp\_err\_r esp\_deepsleep\_gpio\_wake\_up\_mode\_t)

here´s the program:

```arduino
void setup() {
Serial.begin(115200);
pinMode (1,INPUT_PULLUP);

gpio_wakeup_enable((gpio_num_t)1 , GPIO_INTR_ANYEDGE);

void loop() {
int contact=digitalRead(1);
if (contact==HIGH){
esp_deep_sleep_enable_gpio_wakeup();
Serial.println("OPEN");
client.publish(contacttopic,"ON");
delay(100);}
else{
esp_deep_sleep_enable_gpio_wakeup();
Serial.println("CLOSED");
client.publish(contacttopic,"OFF");
delay(100);
}
Serial.println("Going to sleep")
;esp_deep_sleep_start();
}

```

---

<div class="post-metadata">

**Author:** ![kmin](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kmin/32/1147370_2.png) [@kmin](https://forum.arduino.cc/u/kmin)\
**Post date:** [August 13, 2025, 7:02pm UTC](https://forum.arduino.cc/t/esp32-c3-super-mini-deepsleep-doorsensor/1401895/5 "2025-08-13T19:02:58Z")

</div>

It's a jungle.  
Try if this compiles:  
gpio\_wakeup\_enable(GPIO\_NUM\_1, GPIO\_INTR\_ANYEDGE);

---

<div class="post-metadata">

**Author:** ![robban75](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robban75/32/1126393_2.png) [@robban75](https://forum.arduino.cc/u/robban75)\
**Post date:** [August 14, 2025, 4:06pm UTC](https://forum.arduino.cc/t/esp32-c3-super-mini-deepsleep-doorsensor/1401895/6 "2025-08-14T16:06:29Z")

</div>

> [@kmin](#):
>
> gpio\_wakeup\_enable(GPIO\_NUM\_1, GPIO\_INTR\_ANYEDGE);

That did it. thanks. however it doesn´t seem to wake up when i push the magnet to the sensor.

It seems that once it sleeps it sleeps and doesn´t care about the sensor.

suggestions?

---

<div class="post-metadata">

**Author:** ![horace](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/horace/32/1014299_2.png) [@horace](https://forum.arduino.cc/u/horace)\
**Post date:** [August 14, 2025, 4:33pm UTC](https://forum.arduino.cc/t/esp32-c3-super-mini-deepsleep-doorsensor/1401895/7 "2025-08-14T16:33:27Z")

</div>

> [@kmin](#):
>
> gpio\_wakeup\_enable

seem to remember that function call only works for light-sleep mode - see [GPIO Wakeup (Light-sleep Only)](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/sleep_modes.html#gpio-wakeup-light-sleep-only)

you marked the topic as solved - is it?

---

<div class="post-metadata">

**Author:** ![robban75](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robban75/32/1126393_2.png) [@robban75](https://forum.arduino.cc/u/robban75)\
**Post date:** [August 14, 2025, 4:44pm UTC](https://forum.arduino.cc/t/esp32-c3-super-mini-deepsleep-doorsensor/1401895/8 "2025-08-14T16:44:46Z")

</div>

Opps..my bad. now it isn´t

cant figure it out. here´s the present code.

Have i forgotten something?

```arduino
void setup() {
  Serial.begin(115200);
  pinMode (1,INPUT_PULLUP);

gpio_deep_sleep_wakeup_enable(GPIO_NUM_1, GPIO_INTR_ANYEDGE);
 
}

void loop() {
  int contact=digitalRead(1);
  if (contact==HIGH){
      Serial.println("OPEN");
     client.publish(contacttopic,"ON");
     delay(100);
  }
  else
  {
     
    Serial.println("CLOSED");
   client.publish(contacttopic,"OFF");
   delay(100);
  }
  Serial.println("Going to sleep");
esp_deep_sleep_start();
}

```

---

<div class="post-metadata">

**Author:** ![kmin](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kmin/32/1147370_2.png) [@kmin](https://forum.arduino.cc/u/kmin)\
**Post date:** [August 14, 2025, 5:59pm UTC](https://forum.arduino.cc/t/esp32-c3-super-mini-deepsleep-doorsensor/1401895/9 "2025-08-14T17:59:29Z")

</div>

try with:

```arduino
gpio_wakeup_enable(GPIO_NUM_1, GPIO_INTR_ANYEDGE);
esp_deep_sleep_enable_gpio_wakeup(1ULL << GPIO_NUM_1, ESP_GPIO_WAKEUP_GPIO_ANY);

```

not tested...  
But I'm 100% sure it's doable.

---

<div class="post-metadata">

**Author:** ![horace](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/horace/32/1014299_2.png) [@horace](https://forum.arduino.cc/u/horace)\
**Post date:** [August 15, 2025, 8:59am UTC](https://forum.arduino.cc/t/esp32-c3-super-mini-deepsleep-doorsensor/1401895/10 "2025-08-15T08:59:38Z")

</div>

try the following on an ESP32C3 where wakeup from deep sleep is GPIO3 pulled HIGH or GPIO2 pulled LOW

```cpp
// ESP32-C3 - wakeup from deep sleep GPIO3 pulled HIGH GPIO2 pulled LOW

// adapted from https://forum.arduino.cc/t/esp32c3-not-waking-up-from-deep-sleep-with-gpio-button-press/1358556/4

/*
ESP32 C3 Deep Sleep and wakeup

1. works with RTC pins 2, 3, 4 and 5 but not 0 and 1
   see https://github.com/espressif/arduino-esp32/issues/6656
   and https://github.com/espressif/arduino-esp32/issues/8447 
*/

#include <Arduino.h>
#include "esp_sleep.h"
#include "driver/rtc_io.h"

#define DEBUG 1

#define WAKEUP_PIN 3 // GPIOs taken LOW to HIGH to wakeup
#define WAKEUP_PIN2 2
#define LED_BUILTIN 8

RTC_DATA_ATTR int bootCount; // stored in RTC memory during deep sleep

esp_err_t errRc;

int esp_deep_sleep_enable_gpio_wakeup(uint64_t, int);

// display wakeup reason
void printWakeupReason() {
  esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause();
  switch (wakeup_reason) {
    case ESP_SLEEP_WAKEUP_EXT1:
      if (DEBUG) Serial.println("Wakeup caused by external signal using EXT1");
      break;
    case ESP_SLEEP_WAKEUP_EXT0:
      if (DEBUG) Serial.println("Wakeup caused by external signal using EXT0");
      break;
    case ESP_SLEEP_WAKEUP_TIMER:
      if (DEBUG) Serial.println("Wakeup caused by timer");
      break;
    case ESP_SLEEP_WAKEUP_GPIO:
      if (DEBUG) Serial.println("Wakeup caused by GPIO");
      break;
    default:
      if (DEBUG) Serial.printf("Wakeup not caused by deep sleep: %d\n", wakeup_reason);
      break;
  }
}

void setup() {
  if (DEBUG) Serial.begin(115200);
  delay(1000); // Give time to open the Serial Monitor
  Serial.println();
  pinMode(LED_BUILTIN, OUTPUT); // blink LED
  for (int i = 0; i < 3; i++) {
    digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
    delay(1000);
    digitalWrite(LED_BUILTIN, LOW); // turn the LED on (HIGH is the voltage level)
    delay(1000);
  }
  if (DEBUG) Serial.println("starting. . . ");
  bootCount++; // display bootcount
  if (DEBUG) Serial.printf("Boot number: %d\n", bootCount);

  printWakeupReason(); // display wakeup reason
  Serial.printf("GPIO%d %d GPIO%d %d\n", WAKEUP_PIN, digitalRead(WAKEUP_PIN), WAKEUP_PIN2, digitalRead(WAKEUP_PIN2) );
  if(digitalRead(WAKEUP_PIN)) Serial.printf("Wakeup due to GPIO %d LOW>HIGH\n", WAKEUP_PIN);
  if(!digitalRead(WAKEUP_PIN2)) Serial.printf("Wakeup due to GPIO %d HIGH>LOW\n", WAKEUP_PIN2);

  // enable wakeup from deep sleep on two GPIO pins
  errRc = esp_deep_sleep_enable_gpio_wakeup((1ull << WAKEUP_PIN), ESP_GPIO_WAKEUP_GPIO_HIGH);
  // errRc = esp_deep_sleep_enable_gpio_wakeup((1ull << WAKEUP_PIN), ESP_GPIO_WAKEUP_GPIO_HIGH);  
  //errRc = esp_deep_sleep_enable_gpio_wakeup(1ull | 0b11111, ESP_GPIO_WAKEUP_GPIO_HIGH); // all RTC pins can wake 0 to 5
  if (DEBUG) Serial.printf("errRc (A): %d\n", (int)errRc);
  errRc = esp_deep_sleep_enable_gpio_wakeup((1ull << WAKEUP_PIN2), ESP_GPIO_WAKEUP_GPIO_LOW);
  if (DEBUG) Serial.printf("errRc (A): %d\n", (int)errRc);
  if (DEBUG) Serial.printf("Entering deep sleep in 5 seconds."
           " Press the button (GPIO%d pulled HIGH GPIO%d LOW) to wake up.\n", WAKEUP_PIN, WAKEUP_PIN2);  
  delay(5000);
  if (DEBUG) Serial.println("Entering deep sleep now.");
  esp_deep_sleep_start();
}

void loop() {
}

```

serial monitor output

```arduino
starting. . . 
Boot number: 1
Wakeup not caused by deep sleep: 0
GPIO3 0 GPIO2 1
errRc (A): 0
errRc (A): 0
Entering deep sleep in 5 seconds. Press the button (GPIO3 pulled HIGH GPIO2 LOW) to wake up.

starting. . . 
Boot number: 2
Wakeup caused by GPIO
GPIO3 1 GPIO2 1
Wakeup due to GPIO 3 LOW>HIGH
errRc (A): 0
errRc (A): 0
Entering deep sleep in 5 seconds. Press the button (GPIO3 pulled HIGH GPIO2 LOW) to wake up.

starting. . . 
Boot number: 3
Wakeup caused by GPIO
GPIO3 0 GPIO2 0
Wakeup due to GPIO 2 HIGH>LOW
errRc (A): 0
errRc (A): 0
Entering deep sleep in 5 seconds. Press the button (GPIO3 pulled HIGH GPIO2 LOW) to wake up..

starting. . . 
Boot number: 4
Wakeup caused by GPIO
GPIO3 0 GPIO2 0
Wakeup due to GPIO 2 HIGH>LOW
errRc (A): 0
errRc (A): 0
Entering deep sleep in 5 seconds. Press the button (GPIO3 pulled HIGH GPIO2 LOW) to wake up.

starting. . . 
Boot number: 5
Wakeup caused by GPIO
GPIO3 1 GPIO2 1
Wakeup due to GPIO 3 LOW>HIGH
errRc (A): 0
errRc (A): 0
Entering deep sleep in 5 seconds. Press the button (GPIO3 pulled HIGH GPIO2 LOW) to wake up

```

EDIT: to enable wakeup from deep sleep on two GPIO pins going LOW\>HIGH

```arduino
  errRc = esp_deep_sleep_enable_gpio_wakeup((1ull << WAKEUP_PIN) | (1ull << WAKEUP_PIN2), ESP_GPIO_WAKEUP_GPIO_HIGH);

```

---

<div class="post-metadata">

**Author:** ![robban75](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robban75/32/1126393_2.png) [@robban75](https://forum.arduino.cc/u/robban75)\
**Post date:** [August 16, 2025, 7:36am UTC](https://forum.arduino.cc/t/esp32-c3-super-mini-deepsleep-doorsensor/1401895/11 "2025-08-16T07:36:32Z")

</div>

> [@kmin](#):
>
> `esp_deep_sleep_enable_gpio_wakeup(1ULL << GPIO_NUM_1, ESP_GPIO_WAKEUP_GPIO_ANY);`

Was not declared was not declared in this scope

---

<div class="post-metadata">

**Author:** ![robban75](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robban75/32/1126393_2.png) [@robban75](https://forum.arduino.cc/u/robban75)\
**Post date:** [August 16, 2025, 7:37am UTC](https://forum.arduino.cc/t/esp32-c3-super-mini-deepsleep-doorsensor/1401895/12 "2025-08-16T07:37:58Z")

</div>

Since i am using a magnet contact i only have 2 pins out. so i want the esp32-c3 super mini to wake up on both low and high signals

---

<div class="post-metadata">

**Author:** ![horace](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/horace/32/1014299_2.png) [@horace](https://forum.arduino.cc/u/horace)\
**Post date:** [August 16, 2025, 8:04am UTC](https://forum.arduino.cc/t/esp32-c3-super-mini-deepsleep-doorsensor/1401895/13 "2025-08-16T08:04:36Z")

</div>

the code in post 10 wakes up the ESP32C3 from deep sleep when GPIO3 goes LOW to HIGH or GPIO2 goes HIGH to LOW

---

<div class="post-metadata">

**Author:** ![horace](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/horace/32/1014299_2.png) [@horace](https://forum.arduino.cc/u/horace)\
**Post date:** [August 16, 2025, 8:09am UTC](https://forum.arduino.cc/t/esp32-c3-super-mini-deepsleep-doorsensor/1401895/14 "2025-08-16T08:09:10Z")

</div>

> [@robban75](#):
>
> > [@kmin](#):
> >
> > `esp_deep_sleep_enable_gpio_wakeup(1ULL << GPIO_NUM_1, ESP_GPIO_WAKEUP_GPIO_ANY);`
> 
> Was not declared was not declared in this scope

can you post the full error message? what identifier was not defined?

what Tools\>Board have you selected? I used ESP32C3 Dev Module for code in post 10

---

<div class="post-metadata">

**Author:** ![robban75](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robban75/32/1126393_2.png) [@robban75](https://forum.arduino.cc/u/robban75)\
**Post date:** [August 16, 2025, 8:18am UTC](https://forum.arduino.cc/t/esp32-c3-super-mini-deepsleep-doorsensor/1401895/15 "2025-08-16T08:18:02Z")

</div>

i changed the board to Dev module but i still get this:

```arduino

'ESP_GPIO_WAKEUP_GPIO_ANY' was not declared in this scope; did you mean 'ESP_GPIO_WAKEUP_GPIO_LOW'?

```

---

<div class="post-metadata">

**Author:** ![horace](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/horace/32/1014299_2.png) [@horace](https://forum.arduino.cc/u/horace)\
**Post date:** [August 16, 2025, 8:29am UTC](https://forum.arduino.cc/t/esp32-c3-super-mini-deepsleep-doorsensor/1401895/17 "2025-08-16T08:29:37Z")

</div>

> [@robban75](#):
>
> i changed the board to Dev module but i still get this:
> 
> ```arduino
> 'ESP_GPIO_WAKEUP_GPIO_ANY' was not declared in this scope; did you mean 'ESP_GPIO_WAKEUP_GPIO_LOW'?
> 
> ```

[esp32c3 V5.5 api-reference sleep\_modes](https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/system/sleep_modes.html) specifies two wakeup condition parameters for esp\_deep\_sleep\_enable\_gpio\_wakeup(mask, mode) so  
_mode -- Select logic function used to determine wakeup condition:_

- ESP\_GPIO\_WAKEUP\_GPIO\_LOW: wake up when the gpio turn to low.\*
- ESP\_GPIO\_WAKEUP\_GPIO\_HIGH: wake up when the gpio turn to high.\*

where did you find ESP\_GPIO\_WAKEUP\_GPIO\_ANY?

---

<div class="post-metadata">

**Author:** ![kmin](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kmin/32/1147370_2.png) [@kmin](https://forum.arduino.cc/u/kmin)\
**Post date:** [August 16, 2025, 9:30am UTC](https://forum.arduino.cc/t/esp32-c3-super-mini-deepsleep-doorsensor/1401895/18 "2025-08-16T09:30:42Z")

</div>

That's correct. ANY is not valid here, my mistake.

---

<div class="post-metadata">

**Author:** ![jim-p](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jim-p/32/922840_2.png) [@jim-p](https://forum.arduino.cc/u/jim-p)\
**Post date:** [August 16, 2025, 10:14am UTC](https://forum.arduino.cc/t/esp32-c3-super-mini-deepsleep-doorsensor/1401895/19 "2025-08-16T10:14:37Z")

</div>

Has the code given in post #10 by @horace solved your problem or do you still need help?

---

<div class="post-metadata">

**Author:** ![kmin](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kmin/32/1147370_2.png) [@kmin](https://forum.arduino.cc/u/kmin)\
**Post date:** [August 16, 2025, 10:22am UTC](https://forum.arduino.cc/t/esp32-c3-super-mini-deepsleep-doorsensor/1401895/20 "2025-08-16T10:22:07Z")

</div>

> [@kmin](#):
>
> If it doesn't work, another approach could be to read the state of the pin before sleep and set the wakeup logic according to that.

I just had a look, how esphome handles that:

```arduino
#if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6)
  if (this->sleep_duration_.has_value())
    esp_sleep_enable_timer_wakeup(*this->sleep_duration_);
  if (this->wakeup_pin_ != nullptr) {
    bool level = !this->wakeup_pin_->is_inverted();
    if (this->wakeup_pin_mode_ == WAKEUP_PIN_MODE_INVERT_WAKEUP && this->wakeup_pin_->digital_read()) {
      level = !level;
    }
    esp_deep_sleep_enable_gpio_wakeup(1 << this->wakeup_pin_->get_pin(),
                                      static_cast<esp_deepsleep_gpio_wake_up_mode_t>(level));
  }
#endif
  esp_deep_sleep_start();
}

```

---

<div class="post-metadata">

**Author:** ![horace](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/horace/32/1014299_2.png) [@horace](https://forum.arduino.cc/u/horace)\
**Post date:** [August 16, 2025, 12:32pm UTC](https://forum.arduino.cc/t/esp32-c3-super-mini-deepsleep-doorsensor/1401895/21 "2025-08-16T12:32:24Z")

</div>

following up on idea by @kmin in post 20  
this reads the state of the pin before sleep and sets the wakeup logic to the inverse, e.g. if GPIO is LOW on reset wakeup is for when it goes HIGH

```cpp
// ESP32-C3 - wakeup from deep sleep GPIO3 
// reads the state of the pin before sleep and sets the wakeup logic to the inverse

// adapted from https://forum.arduino.cc/t/esp32c3-not-waking-up-from-deep-sleep-with-gpio-button-press/1358556/4

/*
ESP32 C3 Deep Sleep and wakeup

1. works with RTC pins 2, 3, 4 and 5 but not 0 and 1
   see https://github.com/espressif/arduino-esp32/issues/6656
   and https://github.com/espressif/arduino-esp32/issues/8447 
*/

#include <Arduino.h>
#include "esp_sleep.h"
#include "driver/rtc_io.h"

#define DEBUG 1

#define WAKEUP_PIN 3 // GPIOs taken LOW or HIGH to wakeup
#define LED_BUILTIN 8

RTC_DATA_ATTR int bootCount; // stored in RTC memory during deep sleep

esp_err_t errRc;

int esp_deep_sleep_enable_gpio_wakeup(uint64_t, int);

// display wakeup reason
void printWakeupReason() {
  esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause();
  switch (wakeup_reason) {
    case ESP_SLEEP_WAKEUP_EXT1:
      if (DEBUG) Serial.println("Wakeup caused by external signal using EXT1");
      break;
    case ESP_SLEEP_WAKEUP_EXT0:
      if (DEBUG) Serial.println("Wakeup caused by external signal using EXT0");
      break;
    case ESP_SLEEP_WAKEUP_TIMER:
      if (DEBUG) Serial.println("Wakeup caused by timer");
      break;
    case ESP_SLEEP_WAKEUP_GPIO:
      if (DEBUG) Serial.println("Wakeup caused by GPIO");
      break;
    default:
      if (DEBUG) Serial.printf("Wakeup not caused by deep sleep: %d\n", wakeup_reason);
      break;
  }
}

void setup() {
  if (DEBUG) Serial.begin(115200);
  delay(1000); // Give time to open the Serial Monitor
  Serial.println();
  pinMode(LED_BUILTIN, OUTPUT); // blink LED
  for (int i = 0; i < 3; i++) {
    digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
    delay(1000);
    digitalWrite(LED_BUILTIN, LOW); // turn the LED on (HIGH is the voltage level)
    delay(1000);
  }
  if (DEBUG) Serial.println("starting. . . ");
  bootCount++; // display bootcount
  if (DEBUG) Serial.printf("Boot number: %d\n", bootCount);

  printWakeupReason(); // display wakeup reason
  if (digitalRead(WAKEUP_PIN)) { // if GPIO is HIGH set for HIGH to LOW wakeup
    Serial.printf("GPIO%d is HIGH setting wakeup to GPIO_LOW\n", WAKEUP_PIN);
    errRc = esp_deep_sleep_enable_gpio_wakeup((1ull << WAKEUP_PIN), ESP_GPIO_WAKEUP_GPIO_LOW);
    if (DEBUG) Serial.printf("errRc (A): %d\n", (int)errRc);
    if (DEBUG) Serial.printf("Entering deep sleep in 5 seconds. GPIO%d pulled LOW to wake up\n", WAKEUP_PIN);  
  } else { // if GPIO is LOW set for LOW to HIGH wakeup
    Serial.printf("GPIO%d is LOW setting wakeup to GPIO_HIGH\n", WAKEUP_PIN);
    errRc = esp_deep_sleep_enable_gpio_wakeup((1ull << WAKEUP_PIN), ESP_GPIO_WAKEUP_GPIO_HIGH);
    if (DEBUG) Serial.printf("errRc (A): %d\n", (int)errRc);
    if (DEBUG) Serial.printf("Entering deep sleep in 5 seconds. GPIO%d pulled HIGH to wake up\n", WAKEUP_PIN);  
  }
  delay(5000);
  if (DEBUG) Serial.println("Entering deep sleep now.");
  esp_deep_sleep_start();
}

void loop() {
}

```

serial monitor output

```arduino
starting. . . 
Boot number: 1
Wakeup not caused by deep sleep: 0
GPIO3 is HIGH setting wakeup to GPIO_LOW
errRc (A): 0
Entering deep sleep in 5 seconds. GPIO3 pulled LOW to wake up

starting. . . 
Boot number: 2
Wakeup caused by GPIO
GPIO3 is LOW setting wakeup to GPIO_HIGH
errRc (A): 0
Entering deep sleep in 5 seconds. GPIO3 pulled HIGH to wake up
Entering deep sleep now.

starting. . . 
Boot number: 3
Wakeup caused by GPIO
GPIO3 is HIGH setting wakeup to GPIO_LOW
errRc (A): 0
Entering deep sleep in 5 seconds. GPIO3 pulled LOW to wake up

starting. . . 
Boot number: 4
Wakeup caused by GPIO
GPIO3 is LOW setting wakeup to GPIO_HIGH
errRc (A): 0
Entering deep sleep in 5 seconds. GPIO3 pulled HIGH to wake up

```

[Next page](https://forum.arduino.cc/t/esp32-c3-super-mini-deepsleep-doorsensor/1401895.md?page=2)
