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! ![]()