1

I'm connecting a button to ESP8266. Connection goes like this: 3v to one side of button, other side connected with GND and pin number 2 (no resistor).

Every time I connect the ESP both built in LED's stay on until I press the button, they turn off until I let go (even though code states otherwise). Plus, When I monitor the serial, gibberish runs while ignoring my print commands, until I press the button then the serial stops outputting altogether.

When I run the serial without the button, everything works fine. Am I connecting it wrong, or is the button damaged, or any other problem source? Thanks in advance.

EDIT: I added the pinMode(BTN_PIN, INPUT_PULLUP) to take the resistor role; to the code, still not helping.

bumped to the homepage by Community yesterday

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

  • You definitely need a resistor. Currently you are shorting your power supply. This will turn off your esp and eventually kill your power supply or the esp (depending on how you have everything connected – chrisl Apr 23 at 13:14
  • Thought so. Are you 100% sure I need a resistor? I think I have everything connected right as I described above. – Santino Apr 23 at 13:17
  • You need a resistor somewhere. You can decide if you want to use an external one or the internal one that you activate with the INPUT_PULLUP statement – chrisl Apr 23 at 13:54
  • I added the statement to the input pin. But is there a work around for the GND pin resistor? or do I have to insert an actual physical one? – Santino Apr 23 at 13:56
  • Got it to work eventually, apparently if I use the PULLUP command, I should remove the GND connection. Thanks for the help! – Santino Apr 23 at 14:41
0

When pin 2 is connected to ground as you have done it puts the chip into an invalid boot mode. It will be spewing out messages at 74880 baud complaining about the boot mode being invalid.

You must not connect pin 2 to ground. It must, at boot time, be connected to 3.3V through a resistor (which is should be provided by the board for you if you use a development board not a bare module).

By connecting the button between 3.3V and GND you are causing a short circuit that removes the power from the module and risks damaging the power supply on your board.

The proper way of wiring a button is to use:

pinMode(2, INPUT_PULLUP);

and then connect the GPIO pin to ground through the button.

The INPUT_PULLUP acts like the required pullup resistor keeping the input HIGH while "idle", and the button connects the input to GND when you want to "activate" it, making it LOW.

Those are the only connections you should make. If you want to use an external resistor instead of the internal one with INPUT_PULLUP, then that goes between the input pin and 3.3V.

Never ever cause 3.3V to be directly connected to GND.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.