Make an Arduino Leonardo Arcade controller for PC

//Make an Arduino Leonardo Arcade controller for PC

How to make a PC Arcade controller using the Arduino Leonardo


As well as being able to run programs like other Arduino’s, the Leonardo and Micro models can emulate a USB Keyboard or mouse when plugged into a USB port.

In this tutorial we will see how to connect Arcade controllers to a Leonardo, and use them in the popular retro arcade emulator MAME to play all those nostalgic video games.

You could also use the Arduino MICRO which is the same as the Leonardo but much smaller.

We will connect an 8 way joystick and an arcade button to play one of my favorite game: GALAGA!


As you can see in the schematic above, most arcade joystick are nothing more than regular switches that get activated when you move the stick in a specific direction.

The NO (Normally Open) pin of the switches are connected to pin 2, 3 and 4 of the Leonardo.

The COM or ground pins are connected together and then go to the GND pin of the Leonardo.


Before we start we need to know what Keyboard shortcuts the MAME emulator uses.

Depending on the game you play you might need more or less keys, since some of them use more buttons and might be 2 Players.

For our tutorial we only need to know the keys for the Player 1 joystick and fire button.

MAME default keys for the P1 joystick are the Arrow keys and the Left-Ctrl key for fire.

Here are the default keyboard shortcuts in MAME.

This list is simplified since there’s a lot more available.

You can do a Google search to find out more.

Keyboard Key  MAME Command
5 Insert Coin
1,2 Players 1 -2 Start buttons
P Pause game
Esc Exit game
Arrow Keys Player 1 Control
Left Ctrl Fire 1
Left Alt Fire 2
Space Fire 3
R,F,G,D Player 2 Control
A P2 Fire 1
S P2 Fire 2
Q P2 Fire 3

As always please watch our Tutorial video for more information.

#include "Keyboard.h"

void setup() {

//Joystick and button connections
pinMode(2, INPUT_PULLUP); //Joystick Left Switch
pinMode(3, INPUT_PULLUP); //Joystick Right Switch
pinMode(4, INPUT_PULLUP); //Fire Button

void loop() {
// Check the switches:
int buttonState2 = digitalRead(2);
int buttonState3 = digitalRead(3);
int buttonState4 = digitalRead(4);

// Joystick Left = Arrow Left Key
if (buttonState2 == LOW) {;
else {

// Joystick Right = Arrow Right Key
if (buttonState3 == LOW) {;

// Fire Button = Left Ctrl key
if(buttonState4 == LOW) {;

Copy the above Sketch code in your Arduino IDE software to program your Arduino Leonardo or Micro.

The MAME version we used in this tutorial is called MAMEUI32.

You can Download MAMEUI32 from here:  MAMEUI32 Download.

By | 2018-02-23T17:19:34-05:00 March 29th, 2015|Tutorials|


  1. PIerre October 3, 2019 at 4:45 am - Reply

    I would need the same arcade button model on fritzing. Could you please tel me where you found it?
    Thank you

  2. Nicholas February 25, 2019 at 5:13 pm - Reply

    Hi! Thanks for this tutorial – it is very well done! I was wondering, how would you go about removing the ability to hold down the fire button? That is, pressing and holding the buttons should only return one press. Thanks!

Leave A Comment