Keyboard PCB design: from layout to a board you can order

Top view of a keyboard PCB with MX switch footprints on a 19.05 mm grid, a diode below each switch, and column and row traces.
MX footprints at the standard 19.05 mm pitch, each switch wired to its column and through a diode to its row. Row traces run on the bottom layer and are drawn faint. Diagram: Gerber3D · Data: Ergogen default units (ergogen)

A keyboard PCB is a switch matrix (a grid of key switches) with one diode per key, a microcontroller and a USB port. The routing is easy. The mistakes that cost a second order are almost always the same few. A hot-swap footprint is mirrored, the diodes face the wrong way for the firmware, or the USB-C port won't power up.

Start with the layout, not the schematic

Decide where every key sits before you open your EDA tool (your PCB design software). For a conventional row-staggered board, keyboard-layout-editor.com (KLE) is the usual tool. Its raw data gives you key sizes and positions, and you can place footprints from them.

For column-staggered and split ergonomic boards, look at Ergogen. It's an MIT-licensed generator that takes a YAML (text file) description of the layout. From that it produces plate and case outlines, plus an unrouted PCB with footprints already placed. Its default units are 19.05 mm for MX spacing and 18 x 17 mm for Choc spacing. Those are good numbers to remember anyway.

Standard MX key pitch (the distance from one key center to the next) is 19.05 mm (0.75 in). Larger keys are multiples of it (2u, 2.25u, 6.25u). Those sizes decide where stabilizers go.

Switch footprints and hot-swap sockets

Pick the switch family first. The footprint, plate and keycaps all follow from it.

Cherry MX styleKailh Choc v1 (PG1350)Kailh Choc v2 (PG1353)
ProfileFull heightLow profileLow profile
Keycap stemCross (MX)Choc-specificCross (MX-style)
Center hole in common footprintsMX-specific3.4 mm, plus side stabilizer holes5.0 mm
Kailh hot-swap socketCPG151101S11CPG135001S30CPG135001S30

Choc v2 takes MX-style stems. But it is usually laid out at Choc spacing, where standard MX keycaps collide. Before you commit, check that keycaps exist for the combination you pick.

Hot-swap sockets (sockets that let you change switches without soldering) go on the bottom of the board. The switch sits on top, its pins pass through, and the socket's two pads are soldered underneath. That's why the footprint matters. Say a socket footprint is drawn for the top side and placed on the bottom without flipping. Then you get mirrored pads that the socket can't reach.

Use a library footprint made for the socket (marbastlib and the Ergogen footprints include them). Look at the bottom side in 3D before ordering.

The matrix, the diodes, and which way they point

A 60-key board doesn't have 60 controller pins. So keys are wired in a grid of rows and columns, and the firmware scans it. Without diodes, there is a problem. Press three keys that form three corners of a rectangle, and current flows backwards through them. The controller then sees the fourth corner as pressed too.

That's ghosting. A diode in series with each switch blocks the reverse path.

The common part is a 1N4148-type small-signal diode in the SOD-123 package (the 1N4148W, for example). SOD-123 is a flat package that's easy to hand-solder. Cylindrical MiniMELF parts are not. Place each diode next to or under its switch.

Direction matters, and it has to match the firmware. In QMK (open source keyboard firmware), DIODE_DIRECTION is set to COL2ROW or ROW2COL. QMK's documentation defines COL2ROW as the diode's black band (the cathode) facing the row. The diode sits between the switch and the row. If your board is wired the other way, set ROW2COL.

A board with every diode backwards still works if the firmware is told. The mistake that causes real trouble is mixing directions on one board.

Two 2 by 2 key matrices with three keys pressed. Without diodes, current sneaks backwards and a fourth key reads as pressed. With COL2ROW diodes, the reverse path is blocked.
Ghosting in a 2 by 2 matrix, and how one diode per key stops it. With QMK's COL2ROW setting, the diode's band (the cathode) faces the row. Diagram: Gerber3D · Data: QMK matrix docs

Write the diode direction on the silkscreen and in your firmware notes on the same day. Six months later, nobody remembers.

Controllers and firmware

You can socket a ready-made controller board. Or you can put the chip on your PCB ("chip-down").

  • Pro Micro footprint: the easiest start. Several RP2040 boards share the footprint (SparkFun Pro Micro RP2040, Adafruit KB2040, Elite-Pi and others). QMK can convert a Pro Micro keyboard to them. For wireless, the nice!nano uses the same footprint with an nRF52840. Check which way up the board mounts. A controller soldered upside down is a common first-build mistake.
  • Chip-down RP2040: cheaper per board and lower profile. But you add an external QSPI flash chip, a crystal, a regulator and USB. You also need assembly or a steady hand.
  • ATmega32U4: the classic keyboard chip with native USB, well supported by QMK. It needs a 16 MHz crystal and two 22 Ω resistors on the USB data lines.

For firmware, QMK is the default for wired boards. ZMK is the usual choice for wireless. It is built on the Zephyr RTOS and MIT-licensed. It supports Nordic nRF52, RP2040/RP2350, many STM32 and SAMD21 parts. It doesn't support AVR chips like the ATmega32U4.

KMK runs in CircuitPython and is easy to edit. But its repository now says it's on "limited life support", with issues and pull requests not being addressed. So treat it as a hobby option.

USB-C without surprises

Three details catch people:

  1. CC pull-downs. Put a 5.1 kΩ resistor from CC1 to ground and another from CC2 to ground. One resistor per pin, never shared. Without them, a USB-C to USB-C cable gives the board no power. A USB-A to C cable still works, which makes the fault confusing.
  2. ESD protection. A keyboard's USB port gets plugged in constantly. Put a small TVS array (a static-discharge protection chip) on D+ and D- right at the connector. Parts such as the PRTR5V0U2X or USBLC6-2SC6 are cheap insurance.
  3. D+ and D- as a pair. USB 2.0 specifies 90 Ω differential impedance (±10%). Route the two lines together as a differential pair (two traces side by side carrying one signal). Keep them short and match their lengths. Keep a ground plane under them without splits. At full speed (12 Mbit/s) on a short run, a 2-layer board is forgiving. But don't snake the pair across the board.

On a 1.6 mm two-layer board, 90 Ω takes wider traces than you might expect. Work it out for your stack-up (your board's layer thicknesses) with the trace impedance calculator.

Plate, stabilizers and mounting

The plate holds the switches flat and takes the load off the solder joints. It's a separate design with its own files. That's a DXF for laser-cut aluminum or steel, or a Gerber set if you order it as an FR4 board with no copper. Ergogen and most plate generators output it from the same layout, so the holes line up.

Keys 2u and wider need stabilizers. PCB-mount stabilizers need their holes in the PCB footprint (most MX libraries have 2u, 6.25u and other variants). Plate-mount stabilizers need the cutout in the plate. Decide which you're using before you route. The stabilizer holes sit right where you'd like to run traces.

Mounting style changes the PCB too. A tray mount screws the PCB straight to standoffs in the case. So you need holes with keep-out zones, in places that don't collide with switches or stabilizers. Gasket mounts hold the plate between soft gaskets and leave the PCB mostly free of screw holes. Decide on the case before you finalize the outline.

Before you order

  1. Board thickness 1.6 mm. Switch clips, PCB-mount stabilizers and hot-swap sockets assume it.
  2. Print the top and bottom copper 1:1 on paper and push a real switch and socket through it.
  3. Check every diode's direction against your firmware setting.
  4. Check the controller footprint orientation and that pin 1 matches the board you bought.
  5. Decide what gets assembled. Diodes, USB-C, ESD and resistors are worth having placed. Say they sit on top and the hot-swap sockets sit on the bottom. That's double-sided assembly, which costs more (at JLCPCB it needs the Standard tier). Many people hand-solder the sockets.
  6. Look at both sides in 3D. Load the Gerbers in the Gerber3D 3D viewer with your placement file. Check that sockets, diodes and the USB connector land on the side you meant.

If you're ordering assembly from a KiCad design, KiCad to JLCPCB covers the BOM and placement files. Get one prototype built and typed on before you order a batch.

Questions

Does every key on a keyboard PCB need a diode?

Yes, if you want reliable multi-key presses. A diode in series with each switch stops current flowing backwards through other pressed keys, which is what causes ghost keypresses in a matrix. A 1N4148-type small-signal diode in SOD-123 is the usual choice.

Which side do hot-swap sockets go on?

On the bottom of the PCB. The switch sits on top with its pins through the board, and the socket is soldered to the underside so the pins land in it. Use the socket footprint for the side you place it on, or the pads will be mirrored.

Should I use QMK or ZMK for my keyboard?

QMK is the usual choice for wired boards and supports ATmega32U4, RP2040 and STM32 controllers. ZMK is built for wireless keyboards on chips like the nRF52840 and doesn't support AVR controllers such as the ATmega32U4.

What resistor do I need on the USB-C CC pins of a keyboard?

A 5.1 kΩ pull-down to ground on each of CC1 and CC2, one resistor per pin. Without them, a USB-C to USB-C cable won't supply power to the board.

What thickness should a keyboard PCB be?

1.6 mm is the standard. Switch clips, PCB-mount stabilizers and hot-swap sockets are designed around it, so don't change it unless you have a reason.

Sources

  1. How a Keyboard Matrix Works (QMK documentation)
  2. Configuration options, DIODE_DIRECTION (QMK documentation)
  3. Supported hardware (ZMK documentation)
  4. Ergogen keyboard generator and default units (ergogen)
  5. marbastlib KiCad footprint library for keyboards (ebastler)
  6. Designing a keyboard from scratch, part 1 and part 3 (Brice Figureau)
  7. Pro Micro replacement controllers (QMK converters documentation)
  8. KMK firmware repository (KMK)