I'm trying to use one of ESP-01 GPIO's 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 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