How to Build a Custom Mechanical Keyboard from Scratch: Hand-Wiring and QMK Firmware
Introduction
Building a custom mechanical keyboard is one of the most satisfying electronics projects you can undertake. You choose every component — the switch type, layout, case material, keycaps, and even program your own firmware. The result is a keyboard perfectly tailored to your hands, workflow, and aesthetic. This guide covers hand-wiring a keyboard matrix (no PCB required), soldering switches, connecting a microcontroller (Pro Micro or Raspberry Pi Pico), and flashing QMK/VIA firmware. Whether you want a compact 40%, a split ergonomic board, or a full-size custom, the principles are the same.
What You Need
- Mechanical switches (Cherry MX, Gateron, Kailh — your choice, 40-110 depending on layout)
- Keycaps matching your switch stem and layout
- Microcontroller: Pro Micro (ATmega32U4), Elite-C, or Raspberry Pi Pico (RP2040)
- Diodes: 1N4148 through-hole (one per switch)
- Wire: 22-24 AWG solid core for rows/columns, 28-30 AWG for jumpers
- Case/plate: 3D printed, laser-cut acrylic, or purchased aluminum plate
- Soldering iron, solder, flush cutters, tweezers
- USB cable
Step 1: Choose Your Layout
Popular layouts include:
- 40% (44-48 keys): Minimal, layer-heavy, portable
- 60% (61 keys): No numpad or F-row — most popular custom size
- 75% (82-84 keys): Compact with F-row and arrows
- Split (Lily58, Corne, Ergodox): Ergonomic, reduces strain
- Numpad/macropad: Simple starter project (17-22 switches)
Use Keyboard Layout Editor (keyboard-layout-editor.com) to design your layout, then export to Plate & Case Builder for files.
Step 2: Understand the Keyboard Matrix
A keyboard matrix organizes switches into a grid of rows and columns. Instead of using one GPIO pin per switch (expensive), a matrix uses R rows + C columns = R×C switches with R+C pins.
For a 60% keyboard: 5 rows × 14 columns = 70 possible positions using only 19 GPIO pins.
How it works: The microcontroller drives one row HIGH at a time and reads all columns. If a switch is pressed, its column reads HIGH, and the controller knows which key is pressed by the active row and active column.
Step 3: Install Switches in the Plate
- Place switches into the plate/case in your desired layout
- Ensure they click in securely (plate-mount switches have top and bottom clips)
- Check alignment — all switch stems should face the same direction
- Verify stabilizers are installed on larger keys (spacebar, shift, enter) if using a plate that supports them
Step 4: Solder Diodes
Diodes prevent ghosting (phantom keypresses) by ensuring current flows in one direction only.
- Bend one leg of each 1N4148 diode into a loop or U-shape
- The banded/cathode end (black stripe) connects to the switch pin
- Solder the diode leg to one switch pin (typically the pin farthest from you)
- The other diode leg points toward the next switch in the row
- Repeat for every switch — all diodes should point the same direction
Step 5: Wire the Rows
- Cut strips of wire to connect all diodes in each row
- Solder the free diode legs together in a chain — this is your row wire
- Leave one end with extra wire to connect to the microcontroller later
- Insulate with heat shrink or electrical tape where wires cross columns
Step 6: Wire the Columns
- Cut wires to connect the second pin of each switch in a column
- Solder column wires vertically through the switch grid
- Each column wire connects to every switch in that vertical column
- Label each row and column wire with tape and a marker
Step 7: Connect to the Microcontroller
Pro Micro Pinout (common connections)
- Rows: D0, D1, D2, D3, D4 (Arduino pins)
- Columns: F4, F5, F6, F7, B1, B3, B2, B6, B5, B4, E6, D7, C6, D4
Connection Steps
- Strip and tin the row/column wires and microcontroller pins
- Solder each row wire to a separate GPIO pin on the Pro Micro
- Solder each column wire to separate GPIO pins
- Connect VCC and GND from Pro Micro to a convenient location (for optional LEDs)
- Double-check every connection with a multimeter (continuity test)
Step 8: Flash QMK Firmware
Set Up QMK Environment
- Install QMK MSYS (Windows) or qmk_cli (Mac/Linux)
- Run: qmk setup
- Fork the qmk_firmware repository on GitHub
Create Your Keyboard Definition
- Navigate to keyboards/ directory
- Create a new folder: mkdir keyboards/handwired/yourkbname
- Create config.h with matrix dimensions:
Define Your Keymap
- Create keymaps/default/keymap.c
- Use QMK keycodes to define each layer:
Compile and Flash
qmk compile -kb handwired/yourkbname -km default- Put Pro Micro in bootloader mode (short RST to GND twice quickly)
- Flash: qmk flash -kb handwired/yourkbname -km default
Step 9: Test and Debug
- Open a text editor
- Press every key — each should output the correct character
- Use QMK's test matrix mode if keys are wrong — it shows raw matrix positions
- Fix any wiring errors (swapped rows/columns are the most common issue)
Step 10: Enable VIA (Optional but Recommended)
VIA lets you remap keys in real-time through a web app without recompiling firmware.
- Add VIA_ENABLE = yes to rules.mk
- Generate a unique vendor/product ID in config.h
- Compile and flash
- Go to usevia.app — your keyboard appears automatically
- Click any key in the layout and assign a new function
Pro Tips
- Start with a numpad or macropad (17-22 keys) before tackling a full keyboard
- Use a multimeter to test every diode direction before soldering
- Take photos of your wiring before closing the case — future you will thank present you
- Use color-coded wire: one color for rows, another for columns, another for controller connections
- Add reset button pins accessible from outside the case (RST-GND short)
- Lube your switches before soldering for smoother feel
- Use QMK's keymap layers — a 40% keyboard becomes fully functional with 3-4 layers
Conclusion
A hand-wired custom keyboard is a project that combines electronics, programming, and ergonomics into a tool you use every day. The QMK firmware ecosystem gives you unlimited customization — from custom keymaps and macros to RGB lighting and rotary encoders. Start small with a numpad, learn the matrix and wiring fundamentals, then scale up to your dream layout. The keyboard you build will be uniquely yours in every way.
Related Guides
- How to Do Reflow Soldering with a Hot Plate: SMD Assembly for Makers
- How to Design and Etch a PCB at Home: From KiCad to Soldered Board
- Soldering Basics: Tools, Technique, and Common Mistakes
- Soldering Basics for Beginners: Technique, Equipment, and Fixing Common Mistakes
- How to Design Snap-Fit Joints and Living Hinges for 3D Printed Parts
- How to Salvage Electronic Components from E-Waste: Desoldering, Testing, and Reuse
- How to Install Klipper on Any 3D Printer: Complete Setup Guide
- How to Order PCBs from JLCPCB: From KiCad Upload to Delivery