Posts: 1
Joined: Wed Feb 07, 2018 7:10 am

GPIO pin and button

Wed Feb 07, 2018 7:25 am

Hi. I am not as knowledgeable about electricity as I would like,to that end I have a question.

I have a KY-004 key switch module attached to my pi.

It is rated for 12 Volt and 40ma.

My question is about shortcircuit.

The power pin is connected to pin #17 a 3.3v power pin, the ground is connected to the pin #20 and and the input pin is connected to pin #19 or BCM 10.

I have written a java program that works perfectly with it.

Technically the button switches whether to output the 3.3v to ground or the input pin.
My question is to do with short circuit. Is the ~ 40 ma safe to send accross either ground or the input pin?

Posts: 8315
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: GPIO pin and button

Wed Feb 07, 2018 11:38 am


The rating (12 Volt and 40ma) is a maximum for the switch used not what will actually flow.

To find out the actual current flowing you could measure the resistance of the on board resistor and use ohms law to calculated the current, disconnect the switch module from the pi before measuring the resistor.

voltage / resistance = current

3.3 / measured resistance = current
We want information… information… information no help
The use of crystal balls & mind reading are not supported

User avatar
Posts: 376
Joined: Tue May 08, 2012 9:11 am
Location: UK
Contact: Website

Re: GPIO pin and button

Thu Feb 08, 2018 5:05 pm

The GPIO pins operate differently depending upon whether they are configured as an input or an output.

When using the GPIO pin as an output then they can provide a reasonable current (enough to light an LED with appropriate resistor), but when they are configured as an input they will not provide anywhere near that amount of current.

From what I can find about KY-004 it is just a basic switch with a pull-up resistor, although you shouldn't need to use a pull-up resistor (or in fact the +v pin on the KY-004 at all) as the Pi can be configured with a pull-up resistor itself. But assuming you do then as long as it's connected through the 3.3V pin on the Pi GPIO (and not the 5v supply) then it should work fine.

Basically what happens is that when the button is open then a small current can flow through the pull-up resistor on the module into the pin on the Pi. This is enough to take the pin high. When the button is closed it instead connects both the GPIO pin and the bottom end of the pull-up resistor to ground. This allows a small amount of current to flow through the pull-up resistor down to 0v and from the GPIO pin down to ground. Typically the pull-up resistor is in the order of tens of kilo-ohms, as a result the current flowing through the pull-up resistor will be in the order of micro-amps.

It would be a different case if you had a short circuit down to ground if the pin was configured as an output and was in the on state. You could protect against that using an additional resistor between switch and 0v, but it's not really necessary as long as the pin is configured correctly.

Return to “General discussion”