Page 1 of 1

Esp8266 2-pin button not working correctly

Posted: Sun Feb 11, 2024 10:42 am
by CesarWissink
Hi guys i have one of those 2 pin buttons and im trying to connect it to my nodemcu 8266, using this code:

Code: Select all

//in setup:
pinMode(16, INPUT_PULLUP);
// in update:
  int but1 = digitalRead(16);
  if(but1 == HIGH){ }else{
    Serial.print("BUTTON Low");
  }
when i press the button once it goes from HIGH to LOW and stays on LOW forever unless i restart or replugg the 8266, any ideas?

one pin is connected to ground and the other to GPIO 16 on the esp8266

Re: Esp8266 2-pin button not working correctly

Posted: Mon Feb 19, 2024 9:25 am
by bobtidey
GPIO16 is different from the other GPIO pins. It doesn't have a pullup. Instead it has an optional pull down.

Either use a different pin or use pulldown and wire the switch between 3.3V and GPIO16.