ESP32 – Why Is a Floating ESP32 Input Pin with Internal Pull-Up or Pull-Down Not Stable?

esp32

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);
}
```

Best Answer

After checking the Esp32 datasheet, it seems that SW1 (GPIO34) doesn't have internal pull-up/down.

GPIO pins 34-39 are input-only. These pins do not feature an output driver or internal pull- up/pull-down circuitry

The SW1 is, then, floating and will be inherently unstable. So when you enter light sleep the SW1 pin might go High and it will break the sleep

You might not encounter the problem during scope measurements since the probe will generally have a 10 Meg Ohm path to the ground :

enter image description here

It is a weak pulldown, but it might fix it.

Solution

You need to add a hardware pulldown or use another Gpio with internal pulldown.

PS : If you put your finger on the pin the problem might go away. It's a quick way to see if an input pin is floating or not. As long as the signal amplitudes are safe of course ;) (5v/3v3 in your case)

Related Topic