I am trying to take input from twelve different buttons with my Raspberry Pi Zero W.

I have enough GPIO Pins for this, but not enough GND pins, so I decided to make some of the pins pulled low by default so that I could also make use of the 3v3 pins.

Even so, I fell two pins short. How could I use twelve buttons?

I considered using an always on GPIO pin as a 3v3 pin. Would this be safe? I read that using a GPIO pin that's off as GND is unsafe, that's why I am asking. If not, is there some HAT or something else I could do?

2 Answers 2


You can connect all the grounds to one pin. There is no need to have a separate ground for each GPIO.

  • Oh, lol, silly me.
    – Xbox One
    Apr 8, 2023 at 20:21
  • Wait, so in what scenario may I need more than one GND? I ask because I am wondering why RPi even built in eight GNDs when you only need one.
    – Xbox One
    Apr 9, 2023 at 21:31
  • They provided the grounds for convenience. It might have been more convenient to provide more 5V and 3V3 power pins instead.
    – joan
    Apr 9, 2023 at 21:52
  • 1
    @XboxOne Convenience mainly, but a little bit also for signal isolation. For low speed GPIO it doesn't matter at all. But when you use IO ports like SPIO, serial or I2C you usually want to dedicate one GND solely for each, so their high speed switching doesn't interfere with the ground returns of other signals and vice versa. It is not strictly necessary, but generally a good idea because it increases reliability. But the grounds are all ultimately connected together on the RPi PCB.
    – tylisirn
    Apr 9, 2023 at 21:54

Key question: Do the buttons have to operate totally independently? Or are they all for input by one user or in some other way reasonably certain that only one will be pressed at a time?

If you only need one at a time (think: computer keyboard, telephone keypad) then the general solution to this problem, going back to the first 8-bit computers in the 1970s, is to use a keyboard matrix. For 12 buttons, that is a matrix of 3x4, so 7 GPIO pins instead of 12. 8 GPIO pins gets you 4x4 = 16 buttons, etc.

A quick search found an example of this here.

  • 1
    Oh this is cool, yes only one will be pressed at a time. A keyboard matrix will help me reduce the number of wires I will need, but now that I know that I only need one GND, it doesn't relate to that issue. +1
    – Xbox One
    Apr 9, 2023 at 21:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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