Esp8266 2-pin button not working correctly

CesarWissink
Posts: 1
Joined: Sun Feb 11, 2024 10:41 am

Esp8266 2-pin button not working correctly

Postby CesarWissink » Sun Feb 11, 2024 10:42 am

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

bobtidey
Posts: 43
Joined: Mon Jun 18, 2018 2:24 pm

Re: Esp8266 2-pin button not working correctly

Postby bobtidey » Mon Feb 19, 2024 9:25 am

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.

Who is online

Users browsing this forum: No registered users and 77 guests