0

I have a small board with 8 GPIO's, I previously had 4 buttons connected thus used 4 as inputs and 4 as outputs. I use a 10k pull-down resistor for each button. I don't have a resister pre input to protect against programming mishaps (nothing like living on the edge).

I want to connect 8 buttons now, so instead I plan to switch all 8 GPIO's to inputs and use a switching power supply to run 3v through the switches in place of the GPIO outputs. I've actually already done this and it works fine, but I was reading a tutorial that suggested I needed to protect the GPIO because the power supply could supply up-to 1A in my case and the maximum sink current on the GPIO is 2mA.

Now I didn't think this is how current worked and dismissed it as misguided as I thought something had to draw that current from the PSU, but now it's got me worried as I am a complete amateur with electronics and don't particularly want to fry something.

There is nothing in my circuit other than Board/GPIO, 1A 3vdc PSU, momentary switch and a pull-down resistor. Does my GPIO need current limiting / protection?

chip
  • 143
  • 5

1 Answers1

0

Good news, the solution is simpler than you thought. A GPIO input draws very little current, almost none at all. The voltage source will not determine the current draw -- the MCU GPIO will. You can therefore "power" the buttons from most any voltage source with a voltage level suitable for the MCU. The voltage supply for the MCU is a good choice, as it's already guaranteed to be within specs for the MCU.

Just connect the buttons as per schematics in this post: Smart ways to detect a button (less power consuming)

You can also add a capacitor between each GPIO input and ground for easy debouncing. You can use a RC time constant calculator (Google for it) to determine a suitable capacitance value. You probably want about 20 ms time constant.

Anders Petersson
  • 1,111
  • 6
  • 10