ESP8266 simple GPIO

Simple setup, wiring checked and verified, reading a GPIO pin always returns
a "1" when applying hard ground or 3.3V to input pin. Tried several ESP8266,
never ran into this problem before. Compiles fine in 2.1.0 IDE

Used 1.0 NodeMCU parts.

D3 and D4 wired to LEDs, but I am mainly watching serial monitor. For the time
being I only care about ability to read the pin, D0 in this case.


#include <Wire.h>

int D0_doorval = 0;

void setup(){
  // Serial port for debugging purposes
  Serial.begin(9600);
  Serial.println();
  
  pinMode( D0, INPUT );
  pinMode( D3, OUTPUT );
  pinMode( D4, OUTPUT );

  digitalWrite( D3, LOW);
  digitalWrite( D4, LOW);  
}
 
void loop() {
  
  D0_doorval = digitalRead( D0); 
  if ( D0_doorval = 1 ) {

    digitalWrite( D3, 1 ) ;
    digitalWrite( D4, 0 ) ;
  } else {
    digitalWrite( D3, 0 ) ;
    digitalWrite( D4, 1 ) ;
  }
  Serial.println( D0_doorval );
  delay( 5000 );

}

All help appreciated.

Regards, Dana.

Hello

D0_doorval = 1

This is an assignment, not a comparison

Losing it, thank you so much.

Regards, Dana.

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