Build a Pro Micro ATmega32U4 USB macro keypad with six shortcut keys, two layers and a rotary encoder volume knob. Wiring table, diagram and full Arduino code.
Need it ready-made? Buy Ready Project
This Pro Micro USB macro keypad is a small desk gadget with six buttons and a volume knob that plugs into your computer like a normal keyboard. Each button sends a shortcut such as copy, paste, undo or save, and the rotary encoder turns the system volume up and down. Press the knob to mute.
The Pro Micro uses the ATmega32U4 microcontroller, which has USB built in. That means it can act as a real USB keyboard and media controller without any extra driver or software on the PC. Hold the first button for one second to switch to a second layer with media keys and a text macro.

How It Works
- Native USB HID: the ATmega32U4 talks USB directly, so the computer sees it as a keyboard plus a media (consumer control) device. It works on Windows, Linux and macOS.
- Buttons: each button connects a pin to GND. The internal pull-up keeps the pin HIGH, and a press pulls it LOW. A 25 ms debounce stops one press from being read twice.
- Shortcuts: on release, the sketch presses Ctrl plus a letter and lets go, just as you would by hand. Layer 0 is copy, paste, cut, undo, redo and save.
- Layers: holding KEY1 for one second switches to layer 1 (play/pause, previous, next, reopen tab, type a saved sentence, mic mute). The LED is on when layer 1 is active.
- Volume knob: the encoder gives two pulses (CLK and DT) that are out of step. Comparing them on each falling edge of CLK tells the direction, and the sketch sends Volume Up or Volume Down.
Components Required
- Pro Micro ATmega32U4 5 V / 16 MHz (or Arduino Leonardo / Micro) – 1
- 12 mm tactile push buttons or mechanical key switches with keycaps – 6
- KY-040 rotary encoder module (or bare EC11 encoder with knob) – 1
- 5 mm LED – 1
- 330 Ω resistor – 1
- Micro-USB data cable – 1
- Breadboard or perfboard, jumper wires
- Optional: 3D-printed or acrylic case
Wiring Table
| Component | Pro Micro pin | Notes |
|---|---|---|
| KEY1 | Pin 2 | Other leg to GND; hold 1 s to change layer |
| KEY2 | Pin 3 | Other leg to GND |
| KEY3 | Pin 4 | Other leg to GND |
| KEY4 | Pin 5 | Other leg to GND |
| KEY5 | Pin 6 | Other leg to GND |
| KEY6 | Pin 7 | Other leg to GND |
| Encoder CLK | Pin 8 | |
| Encoder DT | Pin 9 | Swap CLK and DT if the volume goes the wrong way |
| Encoder SW | Pin 10 | Push switch, other side to GND |
| Encoder + | VCC | Only on KY-040 modules |
| Encoder GND | GND | |
| LED anode | Pin 16 | Through 330 Ω |
| LED cathode | GND |
Connection Diagram
The illustration above shows the general layout. The pin-accurate drawing below matches the wiring table exactly, so follow it when you wire the circuit.
Arduino Code
Install HID-Project by NicoHood from the Arduino Library Manager. In the Arduino IDE choose Arduino Leonardo as the board (it uses the same chip and pins as the Pro Micro), pick the right port and upload. The sketch uses about 7.7 KB of flash.
/*
Pro Micro (ATmega32U4) USB Macro Keypad with Rotary Encoder
------------------------------------------------------------
- 6 push buttons send keyboard shortcuts (copy, paste, undo, ...)
- Rotary encoder turns system volume up / down
- Encoder push button toggles mute
- Mode button (hold KEY1 for 1 s) switches between two layers
- Status LED shows the active layer
Board: "Arduino Leonardo" (Pro Micro 5V/16MHz uses the same core)
Library: HID-Project by NicoHood (Library Manager)
*/
#include <HID-Project.h>
// ---------- Pin map ----------
const uint8_t KEY_PINS[6] = {2, 3, 4, 5, 6, 7}; // buttons to GND
const uint8_t ENC_A = 8; // encoder CLK
const uint8_t ENC_B = 9; // encoder DT
const uint8_t ENC_SW = 10; // encoder push switch
const uint8_t LED_PIN = 16; // layer LED (with 330 ohm to GND)
const unsigned long DEBOUNCE_MS = 25;
const unsigned long HOLD_MS = 1000; // hold KEY1 to change layer
bool lastState[6];
unsigned long lastChange[6];
unsigned long pressStart[6];
bool holdUsed[6];
uint8_t layer = 0;
int lastEncA;
bool lastSw = HIGH;
unsigned long lastSwTime = 0;
// Send Ctrl + key (Windows/Linux). Use KEY_LEFT_GUI on macOS.
void ctrlKey(char k) {
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(k);
delay(10);
Keyboard.releaseAll();
}
void ctrlShiftKey(char k) {
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.press(k);
delay(10);
Keyboard.releaseAll();
}
// What each key does in each layer
void runMacro(uint8_t key) {
if (layer == 0) { // Layer 0: editing shortcuts
switch (key) {
case 0: ctrlKey('c'); break; // Copy
case 1: ctrlKey('v'); break; // Paste
case 2: ctrlKey('x'); break; // Cut
case 3: ctrlKey('z'); break; // Undo
case 4: ctrlKey('y'); break; // Redo
case 5: ctrlKey('s'); break; // Save
}
} else { // Layer 1: media + typing
switch (key) {
case 0: Consumer.write(MEDIA_PLAY_PAUSE); break;
case 1: Consumer.write(MEDIA_PREVIOUS); break;
case 2: Consumer.write(MEDIA_NEXT); break;
case 3: ctrlShiftKey('t'); break; // reopen closed tab
case 4: Keyboard.print("Hello from my macro pad!"); break;
case 5: ctrlShiftKey('m'); break; // mute mic in many apps
}
}
}
void setup() {
for (uint8_t i = 0; i < 6; i++) {
pinMode(KEY_PINS[i], INPUT_PULLUP);
lastState[i] = HIGH;
lastChange[i] = 0;
holdUsed[i] = false;
}
pinMode(ENC_A, INPUT_PULLUP);
pinMode(ENC_B, INPUT_PULLUP);
pinMode(ENC_SW, INPUT_PULLUP);
pinMode(LED_PIN, OUTPUT);
lastEncA = digitalRead(ENC_A);
Keyboard.begin();
Consumer.begin();
digitalWrite(LED_PIN, LOW); // LED off = layer 0
}
void readKeys() {
unsigned long now = millis();
for (uint8_t i = 0; i < 6; i++) {
bool s = digitalRead(KEY_PINS[i]);
if (s != lastState[i] && now - lastChange[i] > DEBOUNCE_MS) {
lastChange[i] = now;
lastState[i] = s;
if (s == LOW) { // pressed
pressStart[i] = now;
holdUsed[i] = false;
} else if (!holdUsed[i]) { // released after a short press
runMacro(i);
}
}
// Long press on KEY1 changes the layer
if (i == 0 && lastState[0] == LOW && !holdUsed[0] &&
now - pressStart[0] > HOLD_MS) {
holdUsed[0] = true;
layer = (layer + 1) % 2;
digitalWrite(LED_PIN, layer ? HIGH : LOW);
}
}
}
void readEncoder() {
int a = digitalRead(ENC_A);
if (a != lastEncA && a == LOW) { // falling edge on CLK
if (digitalRead(ENC_B) != a) Consumer.write(MEDIA_VOLUME_UP);
else Consumer.write(MEDIA_VOLUME_DOWN);
}
lastEncA = a;
bool sw = digitalRead(ENC_SW);
if (sw != lastSw && millis() - lastSwTime > 50) {
lastSwTime = millis();
lastSw = sw;
if (sw == LOW) Consumer.write(MEDIA_VOLUME_MUTE);
}
}
void loop() {
readKeys();
readEncoder();
}
Customising the Macros
- Change the letters in
runMacro()to any shortcut you use often, for examplectrlKey('f')for Find. - On a Mac, replace
KEY_LEFT_CTRLwithKEY_LEFT_GUIso the buttons press Command instead of Ctrl. - Change the text inside
Keyboard.print()to your email signature or a phrase you type a lot. - Add more layers by changing
% 2to% 3and adding another block inrunMacro().
Testing
- Plug the keypad in. The computer should detect a new keyboard within a few seconds.
- Open a text editor, type a word, select it and press KEY1 then KEY2. The word should be copied and pasted.
- Turn the knob. The volume on-screen display should go up and down. Press the knob to mute.
- Hold KEY1 for one second. The LED should light, and KEY1 should now play or pause music.
Troubleshooting
| Problem | Fix |
|---|---|
| Upload fails or port disappears | The 32U4 resets into its bootloader for 8 seconds. Double-tap RST to GND just before uploading. |
| Buttons type twice | Increase DEBOUNCE_MS to 40 or 50. |
| Volume goes the wrong way | Swap the CLK and DT wires, or swap ENC_A and ENC_B in the code. |
| Volume skips steps | Some encoders give two pulses per click; ignore every second pulse with a small counter. |
| Nothing happens on the PC | Use a data cable, not a charge-only cable, and check that HID-Project is installed. |
Ideas to Extend
- Use 12 keys in a 3×4 matrix to get more shortcuts from the same pins.
- Add a small OLED to show the active layer name.
- Add WS2812B LEDs under the keys for a backlit keypad.