Programmable macro keyboard

In this post, I would like to introduce you to the keyboard that I developed with colleagues from the design office. It is a so-called „macro keyboard“, which can be programmed – it can set commands, functions, etc … The real use will be in easier work in CAD programs, but it will also find use in streaming video games. Under the individual buttons you can set the sequence of keys that the keyboard sends to the PC via the USB port. The pictures below show a keyboard that has been programmed to run each program.

usb macro keyboard

Circuit description:

The connection is very simple, it is only an Arduino Micro module (ATmega32u4 with built-in USB). This module has the advantage that it does not contain a USB-serial converter and therefore it looks like a separate HID device in the PC, so it can be used, for example, as a keyboard. 8 buttons are connected to this module, which switch against GND supply when closed. A 100nF ceramic capacitor is connected in parallel to each button, which filters out vibrations when the button is closed and opened. Inside the microprocessor, there are software-activated pull-up resistors, which in the open state supply the input with current and thus logic 1. In this example circuit, 8 switches are used and inputs D2 to D9 are occupied. The printed circuit board with switches is connected to the Arduino Micro by a 9-conductor ribbon cable. The buttons I used Omron B3F-4055 (12×12) with a fingerboard that can be disassembled with a piece of paper inserted into it with a picture. We then connect to the module itself using a Micro USB cable.

tact switch keyboard

The module contains a total of 14 digital and 4 analog inputs, so it is possible to easily connect up to 18 buttons, or use a matrix connection to increase the number. The connection via analog inputs is often used, when in many resistors the switches act as taps, which change the value in the resistor divider.

For this purpose, a box made on a 3D printer was created, which gives the whole connection a „professional look“. The box consists of 2 pieces. The lower part, in which the Arduino Micro is mounted, and the upper frame, which holds the printed circuit board with switches.

Placement plan and printed circuit board:
macro keyboard pcbmacro keyboard pcb

Placement plan and PCB are at 1:1 600 dpi (How to print a PCB design can be found in the post How to print PCB design). Real size PCB is 61,0 x 32,7 mm.

3D printed case:

The box was designed for 8 pieces of buttons and the Arduino Micro. The lid of the box has a very small clearance, thanks to which it „clicks“ and serves as a locking of the printed circuit board with switches. The files can be downloaded at the following link, they are freely available on the Thingiverse website:

macro keyboard case

Arduino code:

The code for this construction is freely available, I will describe the most frequently used macros below and give examples of real use. The complete code for this design is available here:


if ((buttonState1 != previousButtonState1)
    && (buttonState1 == LOW)) {
     Keyboard.write(KEY_LEFT_GUI); //WINDOWS
     Keyboard.write(KEY_RETURN); //ENTER
previousButtonState1 = buttonState1;


This shows part of the code that starts Microsoft Word. Lines 1 and 2 is the IF condition that evaluates the button press. The first part of the condition evaluates a long press of the button (makes sure that the command is not repeated) and the second part of the press itself. Line 3 sends a Windows keystroke (opens the Start menu). Line 5 prints the text „word“, which finds the application on the PC. Line number 7 sends the Enter key. After each command, it is necessary to „pause“ the program using the delay function, the computer would not be able to correctly evaluate the incoming data via USB. On line 10, we write in the variable the current state of the button, which is used in the first part of the condition.

Buďte první, kdo vloží komentář

Přidejte odpověď

Vaše e-mailová adresa nebude zveřejněna.