How to Design a Custom Keyboard PCB
Learning how to make a keyboard PCB combines electrical, mechanical, and firmware planning in a single project. A successful keyboard PCB design starts long before routing traces: designers must define the physical layout, switch type, controller, USB or wireless interface, enclosure dimensions, and firmware platform first.
Those early choices influence the switch matrix, GPIO count, board dimensions, component placement, and routing strategy. Treating the project as an integrated electrical and mechanical system makes it much easier to move from an idea to a manufacturable custom keyboard PCB.
Key Takeaways
- A well-planned keyboard matrix reduces the number of microcontroller GPIO pins required while organizing how every switch is scanned.
- Controller selection should account for USB support, GPIO count, firmware compatibility, clock requirements, and programming or debugging access.
- Mechanical validation is just as important as the schematic: switch spacing, stabilizers, mounting holes, USB placement, and enclosure alignment should all be checked before fabrication.
Plan the Keyboard Before Designing the PCB
Before placing components in the schematic, determine the keyboard’s physical and functional requirements, including switch layout and spacing, enclosure and stabilizer constraints, connectivity, lighting, controller features, and firmware support. These mechanical and electrical requirements should be defined early, since changing them later can require substantial schematic, matrix, and PCB layout rework.
Keyboard Mechanical Requirements
A mechanical keyboard PCB depends heavily on accurate dimensions. Standard MX-style switches, low-profile switches, and other switch families use different footprints and mounting requirements. Standard keyboard spacing is commonly based on a 19.05 mm, or 0.75-inch, key-unit pitch, but the actual placement still depends on the chosen key layout and switch system.
Mechanical planning should also account for the plate, enclosure, mounting holes, stabilizers, and connector clearances. Larger keys such as Spacebar, Enter, Shift, and Backspace may require stabilizer footprints or mounting holes that must align with the plate.
Keyboard Electrical and Firmware Requirements
Electrical features should be decided at the same stage. RGB lighting adds power demand and routing complexity, while rotary encoders, displays, and other controls consume additional GPIO or communication interfaces.
Wired and wireless designs also have different requirements. A wired USB-C keyboard primarily needs the USB interface, ESD protection, and appropriate power circuitry. A wireless design may also require a Bluetooth-capable controller, battery connector, charging and protection circuitry, power switching, and an antenna keepout region.
Firmware planning belongs at the beginning as well. Platforms such as QMK, ZMK, and KMK support different controllers and architectures, so choosing firmware after the hardware is finished can create compatibility problems.
Keyboard PCB Project Requirements
| Design Element | Options to Consider | Impact on PCB Design |
|---|---|---|
| Switch Type | MX, low-profile, tactile | Determines switch footprint and plate clearance |
| Form Factor | 60%, 75%, TKL, full-size, macropad | Determines key count, board size, and matrix dimensions |
| Connectivity | USB-C, Bluetooth | Affects controller, power system, and antenna requirements |
| Additional Features | RGB LEDs, OLED, rotary encoders | Increases GPIO usage, power demand, and routing complexity |
| Firmware Target | QMK, ZMK, KMK | Limits compatible MCU and board architectures |
| Enclosure | Tray mount, gasket, integrated case | Determines mounting holes, board outline, and connector position |
How a Keyboard Matrix Works
A keyboard matrix organizes switches into rows and columns so the microcontroller does not need one dedicated GPIO pin for every key. Without a matrix, a 104-key keyboard could require 104 separate inputs.
A matrix reduces that requirement significantly. For example, a 104-key board organized as 8 rows and 14 columns requires only 22 GPIO connections. Firmware activates or reads the rows and columns in sequence to determine which intersections contain closed switches.
Each physical key occupies one intersection in the matrix. When the switch closes, it electrically connects its assigned row and column, allowing the controller to identify the key position. For example, if the switch at row R2 and column C3 closes, the controller detects the connection between R2 and C3 during its scan and maps that matrix position to the corresponding key.

Ghosting, Masking, and Diodes
Without isolation, multiple simultaneous keypresses can create unintended current paths through the matrix. For example, ghosting occurs when the controller detects a key that was never pressed because current finds an alternate path through other closed switches.
Masking is a related condition in which one keypress can prevent another pressed key from being detected correctly. Both problems become more likely as multiple switches close at the same time.
Adding a diode in series with each switch restricts current to one direction and prevents many of the unwanted paths that produce ghosting and masking. The common 1N4148 switching diode is widely used for keyboard matrices.
Diode orientation must match the matrix-scanning direction defined in the firmware. For example, in a COL2ROW configuration, the marked cathode generally faces the row side. A ROW2COL configuration uses the opposite orientation, so the schematic and firmware settings must agree.
Per-switch diodes support reliable multi-key detection, but they do not alone guarantee full N-key rollover. NKRO also depends on firmware behavior and how the keyboard reports multiple simultaneous keys to the host.
Choose the Controller, USB Interface, and Supporting Components
Once the matrix size is known, choose a microcontroller with enough GPIO pins for the rows, columns, and any additional controls.
The Arduino Pro Micro and ATmega32U4 remain common choices because the ATmega32U4 provides native USB support and broad keyboard firmware compatibility. The RP2040 is another popular option with more processing power, memory, and GPIO flexibility.
No single controller is best for every keyboard. The choice depends on matrix size, firmware platform, lighting, displays, wireless requirements, available board space, and desired development workflow.
Designers can either mount a development board or place a bare MCU directly on the keyboard PCB. Development boards simplify a first design because voltage regulation, USB support, and programming circuitry may already be included. A bare MCU produces a more integrated board but requires more attention to supporting circuitry.
USB-C Interface
For a USB 2.0 device using a USB-C receptacle, the CC1 and CC2 pins normally require separate 5.1 kΩ pull-down resistors. These resistors identify the keyboard as a USB sink (upstream-facing port) and allow the source to detect the connection.
USB D+ and D- should be routed carefully from the connector to the controller or USB transceiver. Keep the route short, avoid unnecessary vias, and follow the selected controller's reference design rather than improvising the USB interface.
The connector itself also needs mechanical support. Choose a footprint with appropriate shell or mounting tabs and position the connector so repeated cable insertion does not place excessive stress on surface-mount pads.
Supporting Components
A reliable design also requires the supporting circuitry specified for the selected MCU:
- Electrostatic discharge (ESD) protection: Place a suitable transient-voltage-suppression (TVS) or ESD protection device near the Universal Serial Bus (USB) connector.
- Decoupling capacitors: Position small ceramic capacitors close to MCU power pins.
- Clock circuitry: Some controllers require an external crystal or oscillator, while others provide suitable internal USB clocking. Follow the MCU reference design.
- Reset and boot controls: Provide access to any pins or buttons required to enter the bootloader.
- Programming and debugging: Expose the required interface, such as in-system programming (ISP) for some AVR devices or Serial Wire Debug (SWD) for ARM-based controllers.
- Power regulation: Add the regulator, filtering, and power-path circuitry required by the selected USB or battery architecture.
Design and Layout the Keyboard PCB
The PCB layout must match the physical keyboard precisely. Electrical correctness alone will not help if switches, stabilizers, mounting holes, or connectors fail to line up with the plate and enclosure.
Import and Verify the Key Layout
Many designers begin with a keyboard layout tool and transfer the resulting coordinates into the PCB design. Switch positions should be placed according to the intended key-unit spacing and layout.
Before placement, verify every switch, stabilizer, MCU, diode, connector, and optional-control footprint against the manufacturer documentation. Confirm mechanical dimensions, pad spacing, mounting-hole locations, connector orientation, pin numbering, and any polarity or orientation markers before routing begins.
Larger keys require extra attention. Stabilizer mounting holes and cutouts must align with both the PCB and the plate, while mounting holes should clear traces, copper pours, and nearby components.
Place the Controller and USB Connector
Position the controller where it can route cleanly to the switch matrix while keeping USB traces manageable. The USB connector usually sits along a board edge where the enclosure can provide a matching opening.
Check the connector body, cable plug, case wall, and mounting tabs in the mechanical design. A connector can fit electrically while still colliding with an enclosure or plate.
Route the Matrix and Power
Using good PCB routing techniques, route the row and column nets so the matrix remains easy to inspect and troubleshoot. On a two-layer board, designers often route rows primarily in one direction and columns in the other, using vias only where needed.
Keep diode placement consistent across the keyboard so polarity is easy to inspect during assembly. Clear row and column silkscreen labels can also make firmware setup and later debugging easier.
Ground pours can provide a low-impedance reference for the controller and supporting electronics. Power traces should also be sized for the expected load, especially when the board includes per-key RGB LEDs, displays, or wireless circuitry.
Review the Mechanical Fit
Use the PCB design software’s 3D viewer before fabrication to confirm the relationship between the PCB, switches, stabilizers, USB connector, enclosure, and other mechanical parts. A photorealistic PCB rendering can also help expose incorrect orientations or unexpectedly placed components.
Keyboard PCB Layout Checklist
Validate, Manufacture, and Bring Up the Keyboard
Before fabrication, verify both the electrical schematic and the physical PCB. A structured schematic and PCB layout workflow reduces the chance of discovering a simple connectivity or footprint mistake after manufacturing.
Run Electrical and Layout Checks
Run ERC on the schematic to identify unconnected pins, conflicting pin types, missing power connections, and other electrical issues. After routing, run PCB design rule checking to find unrouted nets, clearance violations, copper errors, and other layout problems.
Perform a final manual review as well. Check the board outline, mounting-hole coordinates, USB connector position, footprint pin mapping, diode orientation, and matrix connections against the schematic and mechanical design.
Once the design passes review, generate the required manufacturing files, including Gerber or equivalent copper and mask data, drill files, and any assembly files required by the fabricator.
Assembly and Bring-Up
When the boards arrive, bring them up gradually rather than assembling everything before the first test.
- Inspect the board: Look for damaged copper, malformed holes, solder bridges, or other visible defects.
- Check the power rails: Before installing a socketed controller or applying full power, measure resistance between the main supply rails and ground to look for an unexpected short.
- Verify power: Apply power safely and confirm the expected rail voltages before continuing with the rest of the assembly.
- Install and inspect diodes: Confirm every diode is oriented consistently with the schematic.
- Flash firmware: Load compatible firmware with the same row, column, diode-direction, and pin assignments used in the hardware.
- Test the matrix incrementally: Check one row and column at a time before testing every key.
- Diagnose failures by pattern: One dead key often indicates a switch, diode, or solder-joint problem. An entire dead row or column usually points to a shared trace, GPIO pin, or firmware configuration issue.
If a key registers but produces the wrong character, compare its physical switch position with the matrix row and column assignments in the firmware. Incorrect mapping often comes from a mismatch between the physical matrix and the logical keymap rather than an electrical failure.
A keyboard project is a useful end-to-end PCB design exercise because the schematic, physical layout, mechanical fit, firmware assumptions, and manufacturing constraints are tightly connected. Flux provides a shared environment where teams can work through component selection, schematic capture, PCB layout, review, and design-rule checking while iterating on a custom keyboard PCB. Plan, review, and iterate on your next keyboard PCB in Flux, combining schematic capture, PCB layout, component selection, and collaborative hardware review in one design environment.
FAQs
A keyboard PCB connects the switches, controller, USB or wireless interface, and supporting electronics. The controller scans the switch matrix and converts physical keypresses into digital input events for the host device.
A keyboard matrix arranges switches into rows and columns so the controller can identify keys using fewer GPIO pins. Firmware scans the matrix repeatedly to determine which row-column intersections contain pressed switches.
Not necessarily. Per-switch diodes are normally used in row-and-column matrices when reliable multi-key detection is required. Direct-pin designs and some simple matrices can operate without them, although rollover behavior may be more limited.
There is no universal best controller. The ATmega32U4 is widely supported for traditional wired keyboards, while the RP2040 provides more processing power and GPIO flexibility. Wireless designs may favor controllers supported by platforms such as ZMK.
Yes. The PCB can be designed without writing firmware from scratch, but the hardware still needs to be compatible with a firmware platform. Existing QMK, ZMK, KMK, and configuration tools can reduce the amount of manual coding required.
Many standard keyboards can be built on two-layer PCBs. More complex designs with dense controllers, RGB lighting, wireless circuitry, or stricter power and signal-routing requirements may benefit from four layers.
Yes. A USB-C receptacle can be used for a wired keyboard, but the connector, CC resistors, USB data routing, ESD protection, and mechanical mounting should follow the selected USB and MCU reference designs.
More in Step-by-Step Projects & Templates
Let’s start building.
Let’s build your idea together. All you need to do is describe what you want to make, or what problem you want to solve. Flux will work with you to make it a reality.