Button on ESP8266 - Opposite behaviour than expected

Hi all,

I have a button problem with plugged on ESP8266.

I followed the instructions of the arduino site

The resistor I use is 10k.

Problem is that when I press the button led is off and when button released led is on.

I measured Voltage on the digital pin when button is pressed and is 3.3v as expected.

What am I doing wrong???

Thx all

My Code is

const int buttonPin = 5;     // the number of the pushbutton pin
const int ledPin =  16;      // the number of the LED pin

int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT);
}

void loop() {
  buttonState = digitalRead(buttonPin);

  if (buttonState == HIGH) {
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW);
  }
}


That tutorial is not how you wire up a push button.
Wire it between the input and ground. Then enable the internal pull up resistor on the pin you are using for input.

The diagram shows an Arduino, the picture a NodeMcu.

As far as I remember, the LEDs on the NodeMcu are active LOW.

1 Like

So if he wired his push button correctly then that would be fine.

thank U - Whandall

thank U - Grumpy_Mike

As far as I remember, the LEDs on the NodeMcu are active LOW.
That must be it.

I just connected an external led and the behaviour is as expected - so ... "Onboard LED on NodeMcu are active LOW"

Thank U all

Andreas

I think the reason behind that is, that the ESP can better drain current than supply it.

You should not be switching 5V into the input of a ESP8266 like you are suggesting you are doing.

Just had a minor argument over this at an Amateur Radio meet yesterday, but for this (different levels) and general safety (or "fail safe") reasons, it is bad design to connect signal buttons to the supply rail. Both the Arduino and the ESP8266 provide internal pull-up facilities so that buttons can simply be wired from an input to ground.