-->
Page 1 of 1

Help regarding gpio16 pin on esp8266MOD

PostPosted: Mon Jun 04, 2018 9:39 am
by romok
Hello everyone,
I am an absolute beginner in esp8266MOD so i need help regarding the gpio16 pin of the board. I have set the gpio16 as an input pin which receives input from a pushbutton connected to the ground. The D7 pin is used as an output to an external led. The goal is to turn on the led when the button is pressed and turn it off when the button is released. However when the button is pressed the led turns on but after the button is released nothing happens, the led glows on
WhatsApp Image 2018-06-04 at 8.02.49 PM.jpeg
forever. I am not facing this issue with other I/O pins.

Code: Select allvoid setup() {
  // initialize the LED pin as an output:
  pinMode(D7, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(D0, INPUT_PULLUP);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(D0);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(D7, LOW);
  } else {
    // turn LED off:
    digitalWrite(D7, HIGH);
  }
}


This is my first time asking a question ,please pardon any mistakes. Thanks in advance :) !

Re: Help regarding gpio16 pin on esp8266MOD

PostPosted: Sun Jun 10, 2018 6:58 am
by Gert de Vries
D0 has an internal pullup, so it is always high : pinMode(D0, INPUT_PULLUP);
It will go low only if the button is pressed.
With "digitalWrite(D7, LOW);" the LED wil be ON if it is connected between D7 and Vcc. Use a resistor in series with the LED to reduce the current to max 20mA.

Re: Help regarding gpio16 pin on esp8266MOD

PostPosted: Sun Jun 10, 2018 3:52 pm
by btidey
D0 does not have an internal pull up. It is GPIO16 which is different from other pins and you can't use INPUT_PULLUP with it.

It does have a selectable pull down ( INPUT_PULLDOWN_16).

So you have a choice if you want to use a switch with D0 (GPIO16). Either use (INPUT) with an external pull up resistor (e.g. 10K to 3.3V and connect switch from pin to GND, or use (INPUT_PULLDOWN_16) and connect button from 3.3V to pin. The second option will mean 1 means button open.