# How to Design a Custom Keyboard PCB

Learn how to design a custom keyboard PCB, including the switch matrix, diodes, microcontroller, USB interface, PCB layout, and manufacturing checks.

Written by [Gabriel Hacohen](#)

Published Oct 2026 - 12 min read

![How to Design a Custom Keyboard PCB](https://www.flux.ai/p/assets/blogs/how-to-design-a-keyboard-pcb/main.webp)

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](#how-a-keyboard-matrix-works) reduces the number of microcontroller GPIO pins required while organizing how every switch is scanned.
-   [Controller selection](#choose-the-controller-usb-interface-and-supporting-components) should account for USB support, GPIO count, firmware compatibility, clock requirements, and programming or debugging access.
-   [Mechanical validation](#design-and-layout-the-keyboard-pcb) 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.

![Simplified Keyboard System Block Diagram](https://www.flux.ai/p/assets/blogs/how-to-design-a-keyboard-pcb/body-1-main.webp)

Simplified Keyboard System Block Diagram

### 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](https://www.flux.ai/p/blog/what-is-arduino-pro-micro-a-comprehensive-introduction-for-novices) 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](https://www.flux.ai/p/blog/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](https://www.flux.ai/p/blog/automatically-create-photorealistic-pcb-renders) can also help expose incorrect orientations or unexpectedly placed components.

### Keyboard PCB Layout Checklist

Verify switch spacing against the intended physical layout.

Confirm stabilizer positions and mounting-hole clearances.

Verify component footprints and pad numbering.

Confirm USB-C CC resistors are present.

Check USB connector support and enclosure clearance.

Confirm diode orientation matches the matrix direction.

Keep MCU decoupling components close to their power pins.

Verify power routing for RGB or other high-current features.

Label rows, columns, diode polarity, and programming points.

Review the complete PCB against the plate and enclosure in 3D.

## 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](https://www.flux.ai/p/blog/what-is-schematic-design) 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](https://www.flux.ai/p/blog/pcb-design-rule-checking-drc) 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.

1.  **Inspect the board:** Look for damaged copper, malformed holes, solder bridges, or other visible defects.
2.  **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.
3.  **Verify power:** Apply power safely and confirm the expected rail voltages before continuing with the rest of the assembly.
4.  **Install and inspect diodes:** Confirm every diode is oriented consistently with the schematic.
5.  **Flash firmware:** Load compatible firmware with the same row, column, diode-direction, and pin assignments used in the hardware.
6.  **Test the matrix incrementally:** Check one row and column at a time before testing every key.
7.  **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](https://www.flux.ai/p), combining schematic capture, PCB layout, component selection, and collaborative hardware review in one design environment.

## FAQs

### What does a keyboard PCB do?

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.

### How does a keyboard matrix work?

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.

### Do all keyboard switches need diodes?

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.

### Which microcontroller is best for a custom keyboard?

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.

### Can I design a keyboard PCB without coding?

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.

### How many PCB layers does a keyboard need?

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.

### Can a keyboard PCB use USB-C?

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.

## About the author

Gabriel Hacohen

Electronics Engineer at Flux

Gabriel Hacohen is an electrical engineer with deep expertise in analog circuitry, medical devices, high-performance computing, and semiconductors. He holds both Bachelor's and Master's degrees in Electrical Engineering and has written for companies including NVIDIA, Cadence, Synopsys, Netflix, and Autodesk.

Let’s start building

Build your big idea together with Flux. 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.

![Close-up photo of a PCB made with Flux, with an ESP32 module, buttons, and a microSD slot.](https://www.flux.ai/p/assets/blogs/miscellaneous/sidebar-cta-pcb.webp) [Try it Free](https://www.flux.ai/signup)

## More in Step-by-Step Projects & Templates

[

![Two custom macro pads designed using Flux and powered by Raspberry Pi Pico. The pads feature 12 mechanical switches with per-key white keycaps, two rotary encoders for additional control, and a slide potentiometer for precise adjustments. Both boards are displayed with a vibrant purple PCB design, showcasing Flux's PCB editor and its newest AI Auto-Layout, and are compatible with popular manufacturer specifications.](https://www.flux.ai/p/assets/blogs/rpi-macro-2/main.webp)

### Design Your Own Macropad With AI Auto-Layout

8 Min Read](https://www.flux.ai/p/blog/how-to-design-a-custom-macro-pad-with-flux)[

![This image features two main components: On the left is a detailed layout design of an electronic circuit board named "GREEN DOT 2040E5," dated 2023.11.11, and marked as made with Flux.AI. This board includes an RP2040 microcontroller at its heart, surrounded by various electronic components like resistors, capacitors, a switch, and interface connectors for peripherals, labeled with GPIO pins, I2C connections (SDA and SCL), ground (GND), and power supply inputs (3.3V, 5V, 12V). On the right, there's a physical representation of the IoT device, which is an assembled and operational LoRa IoT Sensor Node powered by a battery pack and RP2040 microcontroller. The node is connected to a long, black antenna, indicating its capability to communicate over LoRa (Long Range) wireless networks, commonly used in agriculture for remote monitoring and control. The setup suggests its application in smart agriculture solutions, utilizing IoT technology to collect and transmit data for agricultural purposes.](https://www.flux.ai/p/assets/blogs/green-dot-board-how-to/main.webp)

### How to design and deploy a LoRa IoT sensor node with RP2040

14 Min Read](https://www.flux.ai/p/blog/how-to-design-and-deploy-a-lora-iot-sensor-node-with-rp2040)[

![Using copilot to help design a webcam based on Omnivision's image sensor. Half of the screen is about the schematic and half is about the pcb layout.](https://www.flux.ai/p/assets/blogs/using-ai-to-design-webcam/main.webp)

### Using AI to Design a Webcam: An End-to-End Example

8 Min Read](https://www.flux.ai/p/blog/using-ai-to-design-a-webcam-an-end-to-end-example)[

![40+ open-source hardware projects you can build over the holidays with Flux](https://www.flux.ai/p/assets/blogs/projects-you-can-build-over-the-holidays/main.webp)

### 40+ Hardware Projects You Can Build Over the Holidays

7 Min Read](https://www.flux.ai/p/blog/40-plus-hardware-projects-you-can-build-over-the-holidays)[

![Arduino microcontroller board used in a home automation system project. Do it yourself or hobbyist level PCB board.](https://www.flux.ai/p/assets/blogs/arduino-essential-guides/main.webp)

### Master DIY Electronics: Essential Guides to Arduino Projects

7 Min Read](https://www.flux.ai/p/blog/master-diy-electronics-essential-guides-to-arduino-projects)[

![Two blurred Arduino boards placed at the background and an upcoming Arduino Matter Board at the foreground. Arduino and Silicon Labs team up to make the Matter protocol accessible to all](https://www.flux.ai/p/assets/blogs/arduino-matter/main.webp)

### Revolutionizing IoT Design: Flux Brings Arduino-Based Matter Projects to Life

4 Min Read](https://www.flux.ai/p/blog/revolutionizing-iot-design-flux-brings-arduino-based-matter-projects-to-life)[

![Different reference design PCB boards made with Flux](https://www.flux.ai/p/assets/blogs/harnessing-power-reference-designs/main.webp)

### Harnessing the Power of Flux for Industrial Sensing Applications

8 Min Read](https://www.flux.ai/p/blog/harnessing-the-power-of-flux-for-industrial-sensing-applications)[

![Ryan, an electronics engineer holding an AI pin he created using Flux with the help of Copilot.](https://www.flux.ai/p/assets/blogs/ai-pin-tutorial/main.webp)

### PCB Design Tutorial: AI Pendant

3 Min Read](https://www.flux.ai/p/blog/pcb-design-tutorial-ai-pendant)[

![Top 5 CES 2025 Hardware Projects You Can Build With Flux](https://www.flux.ai/p/assets/blogs/ces2025-projects/main.webp)

### Top 5 CES 2025 Hardware Projects You Can Build With Flux

5 Min Read](https://www.flux.ai/p/blog/top-5-ces-2025-hardware-projects-you-can-build-with-flux)[

![Why you should start designing your PCB from a template](https://www.flux.ai/p/assets/blogs/start-from-a-template/main.webp)

### Why you should start designing your PCB from a template

3 Min Read](https://www.flux.ai/p/blog/why-you-should-start-designing-your-pcb-from-a-template)[

![A user interface featuring a dialog box that appears at the start of each new project, providing a selection of pre-designed templates. This feature allows users to quickly initiate their designs by choosing from an array of pre-existing options tailored to different project types.](https://www.flux.ai/p/assets/blogs/project-launcher/main.webp)

### Never Start from Scratch Again: Introducing the New Project Launcher

3 Min Read](https://www.flux.ai/p/blog/never-start-from-scratch-again-introducing-the-new-project-launcher)[

![Flux app screenshot with raspberry pi pico schematic diagram](https://www.flux.ai/p/assets/blogs/raspberry-pi-pico-in-20mins/main.webp)

### Raspberry Pi Pico Schematic in 20 minutes using Flux Copilot

4 Min Read](https://www.flux.ai/p/blog/raspberry-pi-pico-schematic-in-20-minutes-using-flux-copilot)[

![Agri.iO revolutionizes farming with Flux](https://www.flux.ai/p/assets/blogs/case-study-agri-io/main.webp)

### Agri.iO revolutionizes farming with Flux

4 Min Read](https://www.flux.ai/p/blog/agri-io-revolutionizes-farming-with-flux)[

![Tilt Tracker smart sensor mounted on a door lock, with a phone app showing the door is locked](https://www.flux.ai/p/assets/blogs/case-study-tilt-tracker/main.webp)

### He'd never designed a PCB. Now Tilt Tracker is taking pre-orders.

6 Min Read](https://www.flux.ai/p/blog/building-tilt-tracker-first-pcb-in-flux)[

![Top 10 Popular Microcontrollers for Embedded Systems including STM32F103C8T6, ESP32, ESP8266, ATtiny85, PIC16F877A, ATmega32U4, ATmega328P, and more. Essential MCUs for IoT, DIY projects, and professional PCB designs with key features like Wi-Fi, USB, and Bluetooth support.](https://www.flux.ai/p/assets/blogs/top-10-popular-mcu/main.webp)

### Design Your First PCB: 10 Popular Microcontrollers to Get Started

5 Min Read](https://www.flux.ai/p/blog/design-your-first-pcb-10-popular-microcontrollers-to-get-started)[

![New NextPCB Templates For More Streamlined Manufacturing](https://www.flux.ai/p/assets/blogs/nextpcb-templates/main.webp)

### New NextPCB Templates For More Streamlined Manufacturing

4 Min Read](https://www.flux.ai/p/blog/new-nextpcb-templates-for-more-streamlined-manufacturing)[

![Flux + Seeed: From Template to PCB in Minutes](https://www.flux.ai/p/assets/blogs/flux-to-seeed/main.webp)

### Flux + Seeed: From Template to PCB in Minutes

3 Min Read](https://www.flux.ai/p/blog/flux-seeed-from-template-to-pcb-in-minutes)

See All (17)

## 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.

[Try it Free](https://www.flux.ai/signup)

 ![Close-up of a Flux-designed printed circuit board](https://www.flux.ai/p/assets/homepage-v2/mission-visual.webp)
