# Arduino with multiple buttons - will power be an issue?

I have a spare Arduino Uno lying around, which I figured I could attempt to turn into a game controller. First clear issue, that immediately popped up, was that there are not enough digital input pins on the board, but I think I can get around that by using analog pins with appropriate external resistors (is that actually a possibility?).

Another one, more severe, is that I'm not sure how I would need to go around wiring microswitch buttons with the board. Assuming they short the circuit when pushed (SPST), I could simply wire one contact to an input pin, set to INPUT_PULLUP mode, and connect the other to ground. However, since I know little about how such circuits work, I'm immediately in doubt about two things. Considering the board would be used as a controller, an external power source is out of question and I'd only want to rely on the USB power. Since I want to use plenty of buttons (up to fifteen), out of caution I'm worried that shorting this many input pins to the ground at once could overload the... regulator I think?

So my question is this: is it safe to use multiple, potentially simultaneously pressed, buttons connected to input pins on an Arduino Uno board, powered solely from a USB port? Additionally, just to be clear, is it normal to connect them all to a common ground on the board?

• Is the game an Arduino game, or are you planning to control something else, like a PlayStation? Jan 14 '16 at 21:55
• @Nick, I'd like it to be a "universal" USB controller. I found the UnoJoy project that ought to cover the basics of USB communication in my case; I'll figure out if I can further modify it once I get it running. Also, thanks for moving the question over, I wasn't initially sure which domain it's considered to be specific to. Jan 14 '16 at 22:13
• In which case I endorse Ignacio's suggestion that you consider another Arduino, for example the Leonardo. I am using one to convert button presses into boilerplate for forums, described here. Jan 14 '16 at 22:23
• You can use V-USB (Virtual USB) instead, try searching for that. Jan 14 '16 at 22:25
• @Nick, ah right, Leonardo does have native USB support and more digital input pins available! Since I already have an Uno to spare, I'll proceed with this one for the time being, but will certainly consider buying a Leo for future projects of similar kind. Thanks! Jan 14 '16 at 22:43

Most of your idea is sensible. Let's go over the sensible part first, and then we'll cover the bits that need work.

Using an internal pullup and shorting the input to ground is the correct way to approach this. Note that the pins will read HIGH when off and LOW when triggered this way.

Each pullup on an AVR is between 20kohm and 50kohm. This means that the current consumption if all 15 buttons are pressed is at most about \$15 \cdot {5 \text{V} \over 20\text{k}\Omega} = 3.75\text{mA}\$. This isn't enough for the USB connection to care about.

As for using the analog connections, A0 through A5 also have digital GPIO capability, which means that you would treat them exactly the same as you would the digital pins (A6 and A7 don't have digital GPIO unless you're running a ATmegaXX8PB with a special core).

And now the bad news.

The Arduino Uno is based on the ATmega328P, which does not have native USB capability. It communicates with the host through a serial connection via a USB-UART bridge. If you're using a real (or real-enough) Uno then that bridge is a ATmega16U2 which is a MCU that does have native USB capability, so it can be reprogrammed to interpret the serial stream from the '328P and talk USB to the host.

But if you aren't then you will either need to run a piece of software on the host that translates the serial stream to HID actions, or you will have to run a software USB stack on the '328P such as V-USB which will allow you to use Low-Speed USB 1.1 directly.

My recommendation is to see if you can get an Arduino or other AVR-based board that has an ATmegaXXU4 so that you can use Mouse and Keyboard directly instead of having to faff around with HID profiles and software USB. Unless that's your thing, of course.

• Ignacio, it looks like this SE doesn't support maths symbols, unfortunately. Jan 14 '16 at 21:53
• Aye, my board is supposed to be Uno R3-compatible and apparently does have an ATmega16U2 controller on-board to handle USB communication. If I understand you right, this means that I can program it, or find suitable firmware elsewhere, to have it present itself as a common HID device, instead of writing custom firmware for it, correct? Jan 14 '16 at 22:09
• @yakcyll: Correct, although the buttons will still need to be handled by the '328P. Jan 14 '16 at 22:12
• @NickGammon: Nor does it support CircuitLab. Some days I wonder how we even manage to get anything done :P Jan 14 '16 at 22:14
• I wish those that migrate would take that into consideration. I have created schematics in the EE question editor and cut'n'pasted the markup in here and it works. I don't know if the schematics get purged if there's no record of them being used in EE though. Anyone know? Jan 14 '16 at 22:32

Yes, it is safe to connect multiple buttons to ground. The pull-up resistors have a fairly high value - about 10 kΩ and we know from Ohm's Law that

I = V / R = 5 V / 10k = 0.5 mA


per button. Your USB power is good for about 500 mA.

Welcome to StackExchange.

• Transistor, it looks like this SE doesn't support maths symbols, unfortunately. ;) Jan 14 '16 at 22:19