Introduction ¶
Mechanical keyboards are a popular alternative to the more commonly used and cheaper membrane keyboards. One of the main benefits of using mechanical keyboards is the more tactile and satisfying feel of pressing each invidiual key. I remember, in my senior year of high school, a kid brought a huge mechanical keyboard and plugged it into the Chromebook. I tried typing on it and it felt much more responsive than using a standard membrane keyboard. I’m mostly used to laptop keyboards since I’ve never had a proper PC setup (although I might “invest” in building one this summer).
After researching online through youtube channels such as Voidstar Lab, I’ve learnt that the electrical properties of mechanical keyboards are fairly simple. The keys are simply connected to a microcontroller that registers an input when the switch is closed, or at least that’s what it may seem like on the surface.
One of the most immediate engineering challenges of building a keyboard is the fact that full size computer keyboards have lots of inputs. The standard computer keyboard, including numpad and function keys, contains 101 keys. Using an extremely powerful microcontroller with over 100 IO pins isn’t a practical or good idea for a keyboard. If individual IO is important to you, you can use IO expanders such as the MCP23017. That being said, the majority of both commercial and hobbyist keyboards use a key matrix.
Design and Theory ¶
My keyboard schematic (Yes I know the diodes and keys are labeled weird, EasyEDA generated item numbers strangely when I was copy pasting rows)
There’s a lot of components in this picture, lets look at a smaller version of this circuit to see how it works.
Using an IO pin for each individual switch is extremely wasteful, so instead the switches are organized into a grid. When one switch is pressed the row and column lines connected to that switch become active and the microocontroller interprets that since Row 1 and Column 1 are both active, that must mean that Switch 1 is active.
Since Row 1 and Column 1 are active, that must mean that switch 1 was pressed since it’s the only switch that can trigger both lines
The microcontroller is able to differentiate between switch 1 and switch 2 because switch 2 also triggers the column 2 line
This does become problematic as more switches are pressed at once though.
When switch 4 is pressed, it triggers row 2, however, pressing switch 4 also accidentally triggers switch 5. Since switch 5 shares the same column as switch 2 (which is also being pressed) and the same row as switch 4, it is called to the microcontroller as a false input. In keyboard design, this switch is called a “ghost key”
If only there was a way to block the accidental flow of current to switch 5. Well, it doesn’t have to be this way. Adding a diode in series with one of the pins ensures that only when the switch is pressed that column and row become live.
D5 only allows a flow of current when switch 5 is pressed, and blocks electricity traveling back into the switch
And to make all the switches on this example keyboard protected we would have to add a diode to each switch. The keyboard that I’m designing uses a 6x13 matrix so it uses 78 diodes and 78 switches. I removed one switch since the layout wouldn’t be a perfect rectangle if I had 78 switches, so there is a blank space in the last row of the key matrix.
I will be using this layout for my keyboard.
Designing the board took much more time to complete than making the schematic. Organizing the switches and spacing them was extremely important in this project since putting switches too close to each other would cause key caps to be overlapping. I wrote a simple script to add an ofset to each key for the first row, since the first row contained function and power keys that all had the same keycap size. I could have just added the ofset of 20.325mm 15 times but that would’ve been more tedious than just writing a simple program.
keyset = [12.75]
[keyset.append(round((keyset[i]+20.325),4)) for i in range(0,14)]
print(f'{keyset}, {len(keyset)}')
And after about 6 hours of designing, the board was ready.
I still have not ordered it since I like to order multiple board designs at once to get the best value out of the fairly expensive shipping.