I'm using DOIT ESP32 DEVKIT V1 with an ESP32 microcontroller, but the behavior is similar to other ESP32 boards.
When a pin is configured as an input with pull-up or pull-down and left floating, its state is not stable. The datasheet lists internal pull-up and pull-down resistance as 45 kΩ. Shouldn't that be enough to keep the input stable?
Here is my test code:
#include <Arduino.h>
#include "esp_sleep.h"
constexpr auto SW1 = GPIO_NUM_34;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
pinMode(SW1, INPUT_PULLUP);
// pinMode(SW1, INPUT_PULLDOWN);
gpio_wakeup_enable(SW1, GPIO_INTR_HIGH_LEVEL);
esp_sleep_enable_gpio_wakeup();
esp_light_sleep_start();
}
void loop() {
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
delay(200);
}
```