I'm trying to use one of ESP-01 GPIOs as an input, however, I'm always reading 1 and nothing attached to these pins.

Basically, I'm trying to detect high voltage from another sensor like a touch sensor or infrared to do some stuff (initial state will be low, so boot won't be affected).

So what I'm supposed to do to read the actual value 0?

Here is the code I'm running:

#define PIN0 0
#define PIN2 2
#define PIN3 3 // Using RX as GPIO

void setup() {
  pinMode(PIN0, INPUT);
  pinMode(PIN2, OUTPUT);
  pinMode(PIN3, INPUT);
  digitalWrite(PIN2, HIGH);
  digitalWrite(PIN0, LOW);
  digitalWrite(PIN3, LOW);

void loop() {
  Serial.print("PIN0: ");  Serial.print(digitalRead(PIN0));  Serial.print("\t");
  Serial.print("PIN2: ");  Serial.print(digitalRead(PIN2));  Serial.print("\t");
  Serial.print("PINRX: ");  Serial.print(digitalRead(PIN3));  Serial.println("");


Here is the Serial Reading:

PIN0: 1 PIN2: 1 PINRX: 1
PIN0: 1 PIN2: 1 PINRX: 1
PIN0: 1 PIN2: 1 PINRX: 1
PIN0: 1 PIN2: 1 PINRX: 1
  • esp-01S has pull-up on io 0
    – Juraj
    Commented Nov 27, 2021 at 6:55

1 Answer 1


You are writing 0 to an input pin. From the Arduino reference:

"If the pin is configured as an INPUT, digitalWrite() will enable (HIGH) or disable (LOW) the internal pullup on the input pin. It is recommended to set the pinMode() to INPUT_PULLUP to enable the internal pull-up resistor."

Also, when you leave an input pin floating, ie. don't connect anything to it, and also don't enable (or explicitly disable) the internal pull-up or connect an external pull-up, the input pin can show 1, or it could show 0.

TL;DR: You shouldn't leave the input pins floating; floating pins are susceptible to electrical noise and can show anything or even fluctuate. If you want them to show 0 when nothing is connected, add an external pull-down resistor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.