arduinoesp8266arduino-idearduino-esp8266

D1 mini ESP8266 pulldown button always HIGH


I am trying to connect a button to my d1 mini ESP8266. The button is connected with a pulldown resistor (10kOhm) to GND. And on the same side of the button to the D4 Pin. on the other side the button is connected to 3.3V.

I used this description for arduino on how to connect push button

Here is how I connected it:

enter image description here

Here is my code:

#define BUTTON_PIN 4

void setup() {
  Serial.begin(9600);
  pinMode(BUTTON_PIN, INPUT);
}

void loop() {
  Serial.println(digitalRead(BUTTON_PIN));
  delay(10);
}

I also tried without the pulldown resistor. The button connected to GND on one side and to D4 on the other side. Then updated the code so it uses

pinMode(BUTTON_PIN, INPUT_PULLUP);

But on the Serial Plotter and in the Serial Monitor the button is always HIGH (1) and there is no change when I press the button. (button was tested with a continuity tester and works ok)

I dont get it, what am I doing wrong here.


Solution

  • On most ESP8266 boards (D1-mini included) the pins are labeled as D1, D2...etc but those numbers don't correspond to the Arduino GPIO pin numbers (the ones you are using in the code :-)

    It's always best to find the pinout diagram for the board you want to use, simply google the "board name pinout" and look for images.

    Here is the pinout for the D1 Mini

    You have basically in your code specified that the button is connected to the pin D2 on the Mini

    If you are using D4 (i.e. Arduino pin 2) that one is also wired to the built in led so it may work bit funky, I tend to stick on the Mini to the D5 to D8

    Here's a picture of the D1-Mini pinout

    enter image description here

    Hope this helps