user68473: 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() {
  Serial.begin(115200,SERIAL_8N1,SERIAL_TX_ONLY);
  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("");

  delay(500);
}

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


user61722: 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.

68473: <p>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.</p>
<p>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).</p>
<p><strong>So what I'm supposed to do to read the actual value 0?</strong></p>
<p>Here is the code I'm running:</p>
<pre><code>#define PIN0 0
#define PIN2 2
#define PIN3 3 // Using RX as GPIO

void setup() {
  Serial.begin(115200,SERIAL_8N1,SERIAL_TX_ONLY);
  pinMode(PIN0, INPUT);
  pinMode(PIN2, OUTPUT);
  pinMode(PIN3, INPUT);
  digitalWrite(PIN2, HIGH);
  digitalWrite(PIN0, LOW);
  digitalWrite(PIN3, LOW);
}

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

  delay(500);
}
</code></pre>
<p>Here is the Serial Reading:</p>
<pre><code>PIN0: 1 PIN2: 1 PINRX: 1
PIN0: 1 PIN2: 1 PINRX: 1
PIN0: 1 PIN2: 1 PINRX: 1
PIN0: 1 PIN2: 1 PINRX: 1
</code></pre>
 61722: <p>You are writing <code>0</code> to an input pin. From the <a href="https://www.arduino.cc/reference/en/language/functions/digital-io/digitalwrite/" rel="nofollow noreferrer">Arduino reference</a>:</p>
<p>&quot;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 <code>pinMode()</code> to INPUT_PULLUP to enable the internal pull-up resistor.&quot;</p>
<p>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 <code>1</code>, or it could show <code>0</code>.</p>
<p>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 <code>0</code> when nothing is connected, add an external pull-down resistor.</p>
