Building a Mechanical Keyboard

I was inspired by a colleague of mine to do some experimenting with electronics. After some thought, I decided to build a mechanical keyboard. It is reasonably straight-forward and seemed like a good project to cut my teeth on. This article is a brief overview of how I went about doing it.

A basic keyboard is made up of a micro-controller, switches and some means of communicating with a computer (usually USB). The firmware on the microcontroller, translates the key presses into the appropriate keycodes which are received by the computer.

My goal was to keep things as simple and inexpensive as possible. I chose a minimalistic design and a 40 key footprint. I was also wanted to make as much from scratch as possible. (While it is possible to cast you own key caps, but that was going too far down the rabbit hole for me!) The goal was to build a keyboard that I would use everyday.

Once I understand how it worked 1, I set about designing and sourcing the parts. Here is a brief description of the components I used.

Micro-controller

I used the Pro Micro 5V/16MHz ATMega 32U4 Module 2 as seemed to be the most affordable. Its datasheet can be found here 3. I bought these from Ebay.

Diodes

I used the 1N4148 Diodes, which I purchased from Amazon.

Switches

I decided to go with Gateron Brown Switches from Massdrop. I would have preferred the standard Cherry MX switches, but none were available at the time. These were tactile with an average activation force.

PCB

Initially, I designed my PCB with Eagle 4. It was only later in the design process that I discovered that the size provided in the free version was too small. I switched to KiCAD 5, which looking back I should have used in the first place. Its open source, free and has a large community. Overall a very nice piece of software. I highly recommend it.

PCB Schema

Once designed I had the PCB made in China. While I speak Mandaring, I had a friend who happened to be in China source out a manufacturer and had everything shipped to him. He then brought it to UK for me when he returned from his travels. One thing to note, is that the minimum order in my case was 10 pieces.

PCB

Firmware

One of the decisions that influenced my choice of micro-controller was the keyboard firmware that it supported. The tmk_keyboard firmware 6 is available for the Pro Micro and it has a large community. It has a number for nice feature, including the support of various micro-controllers, a in-built layering system, good documentation and it was still being actively developed. In this case I stood on the shoulders of giants. I relied heavily on the kind folks at deskthority to get the right information to hook everything up correctly 7, 8 and 9.

Keycaps

I used blank Ortholinear DSA PBT keycaps online 10 (ErgoDox base set). While the custom sets are beautiful, I wanted to be able to touch type, so having them blank seemed appropriate. Also, I could not justify the price.

Layout

I used an amazing online keyboard layout tool 11 to design and spec out my layout. I decided to go minimalist and see how far I could go with as little keys as possible. I eventually settled with a 40 key layout, with two additional functional layers.

Case

I came across a Case and Plate building tool 12, which accepts keyboard layouts as inputs and returns SVG schematics for the switch plate and corresponding case. These have to be converted into STL. Thankfully, there is a youtube video 13 that shows how this can be done with FreeCAD 14. I had the case laser cut from Acrylic in China. Like the PCB, the minimum order was 10.

PCB

Screws

I went with a 5mm round head bolt and nut to screw the case together. This was purchased from Amazon.

Tools

Seeing as I had never done this before, I had to get the tools to assemble everything. Here is the bare minimum tools that you would need to get the job done.

  • Soldering iron
  • Solder
  • Solder sucker
  • Flush Flathead craft pliers
  • Flat head screwdriver
  • Multimeter
  • Tweezers
Summary

Here the final complete keyboard:

Keyboard front Keyboard back

Break down of the cost of materials:

  • 10x (Case and PCB) -> £80 (£8 each)
  • 100x diodes -> £1.70 (£0.68 for 40)
  • 120x switches -> £31 (£10 for 40)
  • 120x keycaps -> £62 (£20 for 40)
  • 1x Microcontroller -> £2.5 (£2.5 each)
  • 1x USB cable -> £1.4 (£1.4 each)

So it works out to about £43 per complete keyboard. It is now my main keyboard at work. Performance wise, it’s taking awhile to get used to the multiple keyboard layers and the switches are a bit lighter to the touch than what I’m used to. Also, the I’ve realised that the mini-USB connection on the micro-controller is the weakest point of the build. I’ve already managed to break it once, so constantly removing the cable is not really an option. Thankfully, I can leave it on when I store it.

I have learned a lot about electronics and making for this project. It’s really opened my eyes in terms of what is possible with the Internet and the low price of electronic parts available online. I’ve replaced the resistors of my Samsung TV and fixed the broken switch of my bicycle lights with my new found skills. It’s amazing what one can do with a soldering iron and a multi-meter! Overall, I’m glad I did this project.

For anyone thinking of building their own keyboard, I would highly recommend it and there are a ton of useful resources available here 15 to get you started.