ESP32 GPIO27 internal Pull-Up to Detect GND

I’m using an ESP32 and want to configure GPIO27 so that it is HIGH by default and detects when it is connected to GND (LOW state). I know some MCUs have only internal pull-down resistors, but does the ESP32 support internal pull-ups as well?

From my research, I believe I can use INPUT_PULLUP to achieve this. Here’s the code I’m using:

#define PIN 27

void setup() {
    pinMode(PIN, INPUT_PULLUP);
    Serial.begin(115200);
}

void loop() {
    int state = digitalRead(PIN);
    Serial.println(state ? "HIGH" : "LOW");
    delay(1000);
}

Expected Behavior:

  • Nothing connected → GPIO27 reads HIGH
  • GND connected → GPIO27 reads LOW

Does this approach make sense? Is there a better way to achieve this on the ESP32?

40cm cat5e cable will be used and endstop switch on gpio27 and gnd

Thanks for any advice! :blush:

Why not just try it?

Might be better to use an external pull-up if you are in an electrically noisy environment, relays, motors, actuators, 220VAC etc

Should work, but as @jim-p says, it may be advisable to add more externally.

Hint: The pins are undefined at power up/reset until setup/boot loader programs them. I would recommend a pull up resistor.

1 Like

Yes, but be careful which pins you use. Some of the ESP32 pins don't have any internal pullups. I got bitten by that one before!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.