Making USB Push Buttons

Using a microcontroller/USB HID you can easily create physical push buttons for your project that, when pressed, will appear as key strokes in your application. This is a really flexible approach to adding physical buttons to an array of different web, desktop or even mobile applications. This post will show you how to do it.

2025 Update

After 10 years of making these USB push buttons for clients, I've updated this post with some of the things I've learned along - in particular how to make sturdy buttons that stand up to abuse at live events installations where they might be pulled, dropped and kicked. Want your own? Get in touch.

I regularly work with experiential marketing agencies making digital brand activations for live events.

A common request is to make large arcade push buttons that can be used as part of an event installation.

Some examples of how these have been used in the past:

  • Multi-choice quiz where a user has to pick the correct answer using 4 A/B/C/D buttons.
  • Head-to-head "first to buzz" where a player has to hit their button before their friend in order to answer a question.
  • Spin-the-wheel where the user hits the button to stop an on-screen wheel spinning
  • Fruit machine game where the user hits the button to try and get 3 matching symbols.
An arcade button to stop a digital fruit machine spinning. The game is a desktop Electron.js app that listens for keyboard input

The easiest approach for making these buttons is to use a microcontroller that supports native USB HID, allowing you to connect the button & controller to a laptop/NUC and have the button presses appear as keyboard input.

Completed USB push buttons

Essentially, when the button is pressed, a 1 keystroke is sent to the connected laptop/device, which the app can treat as regular keyboard input and react.

Buttons

There are a variety of buttons you can use. There seems to be a common manufacturer of generic "arcade buttons" that come in 60mm or 100mm sizes.

Picture of arcade buttons60mm on left, 100mm on right

There are also usually "flat" versions and "rounded" versions.

Rounded and flat arcade buttonsRounded on left, flat on right

The usually come with the physical button as well as a small switch. The two parts screw together.

These buttons contain an LED that can be optionally wired up

The versions I'm using here are generic, but there are a number of trusted manufacturers of arcade buttons you can also use, like Sanwa, Hayabusa & Seimitsu.

Controller

When choosing a controller, the one thing you need to ensure is that it's got native USB HID (“human interface device”) support.

There are a few chips that support this, primarily AtMega16u2 or AtMega32u4.

Here are a few I've used in the past:

  • Teensy 2/3/4: These are great as they're very small yet reliable. They are relatively expensive and sometimes hard to get.
  • Arduino Micro: Like the Teensy, these are small and reliable albeit a little bit more expensive.
  • Arduino Leonardo: These are ideal when you need a rugged set of buttons as they are bigger and also have dedicated 5V power which is useful when wiring multiple buttons to a single board.
  • Pro Micro: These are an Arduino clone that you can get for cheaper on AliExpress. These are fine for simple single-button setups.

Note that the Arduino Uno/Duo/Nano don't have native USB - a mistake I've made a number of times. This is a great site to keep track of the available controllers you can use for USB HID.

Pro Micro USB-C controllerA Pro Micro (Arduino knock-off) with USB-C

The wiring is very simple for these boards. You solder one strand to an available GPIO pin (in the photo below I'm using pin 3) and the other to the GND ground pin. These controllers have built-in pull-up resistors on their GPIO pins, so you don't need to add any more circuitry.

Pro Micro USB-C controllerFor a single button, you only need two pins: a GPIO (3) and a GND

Wiring Cabling

It's important to use decent quality strong cable for the button wiring. For simple projects I usually use standard 2-core 0.75mm2 (~AWG 18) electrical cable which comes in a 50m drum.

2-core cable for USB push buttons

Make sure to always give enough length to run the buttons to the location of the laptop/NUC. Generally 5 meters is a safe bet.

Using Shielded Cable

When using these buttons in an environment that has a lot of other AV components close by, it's worth using shielded cable to avoid interference. This is more expensive and chunkier cable, but avoids weird bugs.

Crimp Connectors

You can also use spade crimp connectors to connect to the button's switch. This makes it much easier to extend the cable length if necessary and also allows you to easily switch to a different button if needs be.

Mounting Board

When making these buttons for use at live events, it helps to ensure they are sturdy as they are constantly getting stepped on, dropped and yanked.

In order to make sure the board fits snuggly and doesn't move around, I 3D print a mounting board that controller can sit into. This slides into the enclosure (see below) and keeps everything snug.

This isn't essential but it makes these buttons last a lot longer.

The x4 slots are for cable ties to secure the board without using glue

This is the model file for the controller bed

This is a slighly different layout that lets you fix cables to either side

Enclosure

If you're using buttons in a space that has heavy traffic, the board needs to be in an aluminium enclosure. This helps keep it safe from being stepped on or banged around, but it also helps avoid any electrical interference (which can be an issue at events with lots of other AV happening).

Tieing the cables down to the mounting board via cable-tie stop them being accidentally pulled out if yanked

I'm using a Hammond enclosure here. These come with two plastic screw-in caps that you can drill holes in with a step-bit. This makes it easy to fit the USB cable and button wiring.

With everything assembled, the controller can handle being bashed around

Software

With everything wired you, you just need to program the controller to act like a keyboard and output a 1 when the button is pressed.

First download Arduino IDE. Depending on the controller you are using, you'll need to download the right package in the "board manager":

You'll also need to the keyboard library is installed in the "library manager":

Then connect your button and select the board from the dropdown:

Add the following code:

#include <Keyboard.h>
#include <Bounce2.h>
 
#define BUTTON_PIN 3
 
/**
 * Single Arcade USB Push Button
 *
 * Intended to work with a Pro Micro or Arduino Micro device. A single USB button
 * should be configured with pin 2 and pin GND
 */
 
int ledState = LOW;
 
Bounce2::Button button = Bounce2::Button();
 
void setup() {
  // Set buttons
  button.attach(BUTTON_PIN, INPUT_PULLUP);
  button.interval(5);
  button.setPressedState(LOW);
 
  // Set LEDs
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, ledState);
 
  // HID Keyboard
  Keyboard.begin();
}
 
void loop() {
  button.update();
  if (button.pressed()) {
    ledState = !ledState;
    digitalWrite(LED_BUILTIN, ledState);
    Keyboard.print("1");
  }
}

Verify and upload the code to the controller and you're ready to go! If you're

Want your own buttons?

If you need some USB buttons for your own project, I can make them for you and ship them anywhere in the world. There are lots of possible configurations so get in touch with me to discuss your requirements more detail.