3D Printed Hand Wired 40% Keyboard

3D Printed, Hand Wired 40% Keyboard

The subject of this blog is a build log, that will cover my build of a 3D printed hand wired 40% keyboard. It will include basic details on 3D printing, hand wiring, general assembly and software programming with QMK along with references to the guides I used.

About a month or so ago I was looking around for a new project (as I frequently do) and I stumbled upon a mechanical keyboard sub-reddit. This ended with me in fairly short order, purchasing the parts to build my first keyboard. Skip forward to today and I have just finished building my third full keyboard and three macro-boards. Clearly this hobby is going to be a money sink!

Required Hardware

The hardware you will require for this project is as follows

The required hardware list is a little more daunting than usual as it will require access to specialist equipment (a 3D printer). You could always buy a case and plate to use instead of printing one and then adjust accordingly.

  1. A 3D printer with a build plate that is at least 220mm x 220mm, or alternatively buying a suitable keyboard plate and case.
  2. 47 x MX type mechanical keyboard switches, I used Gateron Blues.
  3. 48 x 1N4148 diodes for the keyboard matrix.
  4. A EC-11 rotary encoder, for the volume control.
  5. A Pro Micro controller board.
  6. 6 x M3 6-10mm screws to hold the case together (assuming you are using the 3D printed one).
  7. A suitable set of keycaps for a 40% ortholinear keyboard.
  8. A grippy knob…
  9. Suitable wire for building the keyboard matrix, I used a combination of old network cable wire (solid core) and some 26 AWG solid core cable I had from other projects. Any insulated wire will work but solid core is a little easier.
  10. Line wire to go between the microcontroller and the keyboard matrix, you can use whatever wire you like but I highly recommend using ribbon cable as it is flat and easy to work with.
  11. Soldering iron, snips, glue gun etc
3D printer, printing a keyboard case
3D Printed Hand Wired 40% Keyboard – Printing The Case

References To Guides

It is only fair that I reference the guides that helped me make this keyboard. They may be helpful for people reading my guide for use as additional points of reference.

A modern handwiring guide – stronger, cleaner, easier

A Complete Guide To Building a Hand-Wired Keyboard

Printing A Case

I wanted as make where possible all the components for the keyboard, ideally 3D printing where I could. I searched around for different 3D printed cases and was originally going to do a split ortholinear keyboard based on the lets split case. However once it was printed I realised there was not a lot of room to hand wire as it was designed for a PCB. After a bit more hunting I found the Void 40 a 40% keyboard case and plate that was designed for hand wiring. It really is an excellent case design, by Victor Lucachi who rightly deserves credit for releasing it freely for everyone to use and build on.

You will need to print this case or have it printed for you, additional you will need to also print one of these EC-11 to MX switch plate adapters. This will allow you to easily pop a rotary encoder into the top left switch socket (or any other socket should you desire).

Once you have these printed, you can socket all of your switches and the rotary encoder.

3D printed case with mx switches inserted
3D Printed Hand Wired 40% Keyboard – Socketed with Gateron blue switches.

Wiring The Keyboard

Basic principles: Keyboard matrix

To save us from having to wire directly to each switch, which would be laborious and honestly not practical in any way, a keyboard matrix is used instead. This wiring pattern allows us to only need one wire for each row and one wire for each column, dramatically reducing the wiring that needs to go back to a microcontroller.

However there is a trade off, having independently wired switches means that it is easy to know what switches are pressed at the same time without any false positives or unregistered keys (called ghosting). When a keyboard matrix is used we need to add diodes to each key to prevent the black flow of electricity connecting circuits that are not intended. In practice this means a little bit more fiddly soldering but a far more manageable keyboard build. To read more about keyboard matrices and the ghosting effect I have found the following article very easy to understand and clearly written.

Keyboard ghosting
3D Printed Hand Wired 40% Keyboard – Ghosting 🙂

Wiring the diodes

We need to add a diode to each switch, we will be wiring to the top left of each switch (my pictures show the keyboard rotated 180 degrees as it was easier to work on).

The diode must be wired so the anode ( + ) is closest to the switch and the cathode ( – ) is furthest away, it is easy to work out which is which on a diode as the cathode has black bar on it.

To make life a little easier and as is recommanded in all the guides I read, you should create a small loop at the anode end and then pop this over the switch connector. The loop helps create a strong connection and makes positioning somewhat easier. You will want to point the tail of the cathode so it runs straight up away from the switch so that you can loop it around the joining row wire you will add later. For example;

3D Printed Hand Wired 40% Keyboard – Adding diodes

Once you have looped all your diodes around the switches make sure you solder and check their connections, also make sure you have soldered a diode to the rotary encoder as well, it needs to be added to the two pin side in the same way as the switches.

3D Printed Hand Wired 40% Keyboard - Ghosting :)
3D Printed Hand Wired 40% Keyboard – All diodes soldered to the switches.

Adding the row wires

We now need to add the row wires, these are single wires that will run along each row and be soldered to the end of the diodes we just added.

I used insulated solid core wire for this and lined each wire up marking out where it would be in contact with the diode and cutting out the insulation at with a sharp craft knife.

Once you have your wire prepared you can then start soldering it to the diodes in each row, I recommend wrapping the tail wire of the diode around the row wire then soldering, once done you can trim any excess on each diode with wire cutters.

You should start to build up like this.

Partially wired row wires
3D Printed Hand Wired 40% Keyboard – Partial row wiring.

Once you are done your rows should look like this.

Full row wiring
3D Printed Hand Wired 40% Keyboard – Full row wiring.

Adding the column wires

This is a very similar process to adding the row wiring, we need to run wires down each column joining all second connectors on each switch in that column. For this I used old solid core network cable wires.

Once again measure and trim the insulation at the correct points and to aid with alignment I suggest you create a loop at one end and solder this to the first switch, then run down and solder to the remaining three in each column.

Once done it should look like this.

All rows and column wires added and soldered.
3D Printed Hand Wired 40% Keyboard – Full row and column matrix

Wiring the microcontroller

The major wiring work is now over, all we need to now do is run a wire to each column and each row on the keyboard (plus three to the rotary encoder). These wires will go back to the microcontroller and later be configured in QMK to drive the keyboard.

I used ribbon cable and I highly recommend this, it is flat and easy to run. I did this in strips of four as that fitted nicely in the gaps between rows and columns.

For each row you need to solder a wire to the cathode side (black bar) of the diode (where it joins the row wire) in any one of those rows. For each column you need to solder a wire to any one of the switches (on the non diode connector) in that column. The following picture should make it a little clearer

3D Printed Hand Wired 40% Keyboard – Link wire routing

I ended up with a wiring diagram that links back the following Pro Micro microcontroller pins.

Pro Micro PinRow
C61 – Top row (QWER)
D42 – Second row (ASDF)
D03 – Third row (ZXCV)
D14 – Forth row (Ctl Alt)
3D Printed Hand Wired 40% Keyboard – Row wiring table
Pro Micro PinColumn (Left To Right)
3D Printed Hand Wired 40% Keyboard – Column wiring table
Pro Micro PinRotary Encoder Pin
D2Right most pin of three
GNDCenter pin of three
D3Left most pin of three
3D Printed Hand Wired 40% Keyboard – Rotary encoder wiring table

One you have these all wired up I would recommend you do not fix the microcontroller in place and you do your programming and testing with a bare keyboard. Better to do it this way than assemble it all and then find a problem.

A 3D printed keyboard that has been hand wired with rainbow coloured wires and is open showing the wiring.

Configuring Firmware & Flashing QMK

I am not going to put a detailed guide on how to configure QMK here, you will need a QMK build environment. I suggest you follow this guide.

Once you have an environment together you can download the following files from my github page, these will need to be extracted into the qmk_firmware/keyboard/handwired directory. These files contain a fork of the code used by the Void40 by Victor Lucachi, this keyboard is not currently in the standard QMK base but I have reached out to Victor and it will soon be submitted (once it is live I will update this post to reflect it). The changes from the standard firmware are related to pin assignments and keymaps.

To build the firmware issue the following command

qmk compile -kb handwired/void40/ghostseven -km ghostseven

The resulting hex file should be flashed to the keyboard using QMK Toolbox. You will need to short the pins between RST and GND on the pro micro to put it in firmware update mode.

The keyboard will have the following layout if you used the above command.

QMK Keyboard 40% Layout GhostSeven

Please ensure you test all the keys and make sure they work, if you have changed the wiring to the controller in any way you will need to edit the config.h file in the ghostseven folder and match this to your wiring layout.

#define MATRIX_ROW_PINS { C6, D4, D0, D1 }
#define MATRIX_COL_PINS { E6, D7, B5, B4, F6, F7, F4, F5, B1, B3, B2, B6 }

 * Rotary Encoder Support
#define ENCODERS_PAD_A { D2 }
#define ENCODERS_PAD_B { D3 }

Keycaps & Securing The Case

Once you are happy that your keyboard is working and that the wiring is correct you can clip the pro micro into position on the case bottom. You may require a little hot glue to hold it in place. Once you have the two halves of the case together secure the plate to the case bottom with 4 m3 screws. Once these are in place, flip the case over and use four more m3 screws in the corners to tighten the case up. Be careful to not over tighten and split the plastic.

Finally add your keycaps and get clacking.

NeoPixel LED Controller

NeoPixel LED Controller - Example Candle & Strip Lights

Building a NeoPixel LED Controller with MQTT and HomeKit support. Expanding on my previous project to add LED lighting to my work area, I wanted to investigate a lower voltage and more customisable LED system. I had read about WS2812B or NeoPixel LEDs but had not built anything with them. I have since build a whole raft of lighting projects utilising these and even designed a simple PCB to use in my controllers. In this blog post I aim to go over the basics, take a peek at the software I have written and talk about the various projects I have used them in.

NeoPixel LED Controller – Short Demo – The Candles & Desk Strip Are Powered By This Controller

What Are NeoPixel LEDs?

NeoPixel is Adafruit’s brand name for individually-addressable RGB colour pixels and strips based on the WS2812, WS2811 and SK6812 LED/drivers, but it has become shorthand for any individually addressable LED drivers. The cool part about this is the fact that you can set properties on any LED in a whole strip or matrix, this allows us to play about with effects and fades and makes them a lot more versatile that the standard strips I used in my previous project (Build A HomeKit Enabled WiFi LED Strip). They also run on 5v rather than 12v so building a project with a microcontroller is far easier and need less components.

Required Hardware

The hardware you will require for this project is as follows

  1. An existing MQTT server on your network, this is required for messaging,
  2. If you wish to use HomeKit an existing Homebridge server on your network.
  3. An ESP8266 board, something like a Wemos D1 Mini, you can use other boards but you will have to amend the code.
  4. A length of WS2812B strip, something like this, 5 meters (60 LED) costs about £15.
  5. (Optional) A barrel jack socket, to connect DC power to the board.
  6. A suitably rated 5v power supply, the amperage will vary depending on how long your LED strip is. I used a 5v 4A supply I had already.
  7. A suitable current smoothing capacitor to deal with sudden changes in the LED strip current draw. I used a 1000uF 16v capacitor.
  8. Some perfboard to build the project on (or use my handy dandy Gerber files to have PCBs made, or even better get JLCPCB to fab and send it to you.).
  9. (Optional) A screw terminal to attach the LED strip leads to your board.
  10. Some patch wire to link the components on the board.
  11. A suitable enclosure or access to a 3D printer (STL and OpenSCAD files are provided).
  12. Soldering iron, snips etc.

The Circuit

The following shows how to connect the various components, there really is not a lot to it and you could go without any perfboard at all and simply solder the parts together.

NeoPixel LED Controller – Fritzing Circuit Diagram

I have used this circuit so frequently in projects that I have now designed a PCB so I can standardise the layout and case design. The Gerber files are freely available and if you wish you can visit my EasyEDA project page and get JCLPCB to manufacture batches of the board.

NeoPixel LED Controller – Naked Circuit Board
NeoPixel LED Controller – Circuit Board

The Microcontroller Code

The code has been written using the Ardunio platform, although I prefer to to use PlatformIO inside Visual Studio Code rather than the Arduino editor.

All of the code files, fritizing diagram, Gerber and 3d printer files for the NeoPixel LED Controller can be found on my github.

The controller code is similar to my previous project (Build A HomeKit Enabled WiFi LED Strip) in so far as being able to send HSV values to set colours, but it also now allows you to run effects on the connected LEDs. You can even specify a favourite effect so you can easily toggle it via HomeKit. Some of the effects will use the currently selected colour as their base (with a default colour if none is selected) and other effects will run though pre-configured colours.

LED Effects

The current list of effects is as follows, they are taken from a great article on FastLED / NeoPixel LED effects by Tweaking4All.com. I have taken a selection I wished to use and adapted them for my purposes.

IDEffectDescriptionVideo Link
1RGB LoopFades colour in and out from red to green to blue.Link
2Running LightsChase light effect from red to white to blue.Link
3Colour WipeWipe effect using the colour you have selectedLink
4Rainbow CycleRainbow cycle of colours, default effect on stripLink
5Theatre ChaseLEDs chase each other, like an old theatre, uses whatever colour you have selectedLink
6Theatre Chase RainbowRainbow effect version of theatre chaseLink
7FireBurning fire effectLink
8Meteor RainMeteor shooting across the skyLink
9CylonBy your command..Link
10TwinkleTwinkle effect using selected colourLink
11Tinkle RandomTwinkle effect using random coloursLink
12SparkleVariation of twinkle, white sparkle effectLink
13Snow SparkleSnow effect with occasional sparkleLink
14BreathingBreath in out effect with selected colour.
NeoPixel LED Controller – Effects List

Configuring The Code

Firstly you must adjust and renamed the config file, I (now) use LittleFS uploaded config files for most of my projects as it makes my configuration easier for WiFi. MQTT and OTA. On the github page there is an example file that once checked out will need to be renamed to config,json (from config.EXAMPLE.json) and edited to fill in the SSID and password of your WiFI network. You will also need to complete your MQTT server details, I would pay special attention to the device_id and base_topic as they will end up setting the full topic for your MQTT commands, please set then to something sensible.

    "name": "Desk LED Strip",
    "device_id": "desk-led-strip",
    "wifi": {
      "ssid": "WIFI_SSID",
      "password": "WIFI_PASSWORD"
    "mqtt": {
      "host": "xxx.xxx.xxx.xxx",
      "port": 1883,
      "base_topic": "basement/light/",
      "username": "MQTT_USERNAME",
      "password": "MQTT_PASSWORD",
      "retained": true
      "effect_index": 4,
      "effect_seconds": 0

You can also see there is a section called effect_sw, this is designed to set the parameters for the effect you would like to be able to toggle on and off via HomeKit. The effect_index is a number from the above effects table, the effect_seconds is how long it should run with 0 being forever (this is best for a toggle switch, change if you configure a momentary one). By default it runs the Rainbow Cycle effect.

You will need to configure some settings in the main code, you will need to edit led.h. From here you can edit the pin that will send the control signals to the LED strip, by default it is D5 (LED_PIN). You will also need to set how many LEDs you have in your strip, otherwise they will not behave as expected (NUM_LEDS). Optionally you can set the voltage and amperage limits on the strip, thus limiting the power you will use (LED_STRIP_VOLTAGE, LED_STRIP_MILLIAMPS). I suggest leaving the voltage at 5v and adjusting the amperage to suit.

#define NUM_LEDS 73
#define LED_PIN D5

Over The Air Updates

The code is configured to allow over the air updates, the thought behind this is that once you have a light in place it may not be easy or practical to connect the device back to a computer to upgrade the firmware. The mDNS name will be in the form of <device_id>.local, for example, using the example config it would have a name of desk-led-strip.local. If you are using PlatformIO (which I highly recommend over the Arduino IDE) you simply need to change the upload_port in the ini file to the name of your mDNS entry.

I will not go through all the code files here as they are available on my github page. You will need to update and upload the config file before compiling and flashing the code to the device of your choice.


Once you have the circuit built and the code flashed to your device, it is best to test that it can receive MQTT commands before you try and configure it to work on HomeKit.

For testing MQTT I use MQTT.fx on the Mac, and as it runs on Java this should work on all platforms. I am assuming you have not changed the base_topic and device_id, if you have you can update the tests to reflect this.

Basic Light

You can subscribe to “basement/light/desk-led-strip/hsv” and this will post back a comma delimited string with the HSV value that the light has been set to (for example 0,0,100). It will also retain messages so after a power loss the state is known.

If you send a message to “basement/light/desk-led-strip/hsv/set” with the payload of a comma delimited HSV value such as 0,0,100 it will set the strip to that colour and intensity, it will also then post back to “basement/light/desk-led-strip/hsv” with the HSV change.


You can set an effect and the duration for the effect should run for by sending a JSON payload to “basement/light/desk-led-strip/effect”. The payload should look like the following.

{effect_index:9, effect_seconds:20}

The above payload would run the Cylon effect for 20 seconds, it mirrors the parameters seen in config file for the effect_sw.

Effect Switch

If you wished to have a toggle-able effect mode without having to send a complex JSON payload (for example in HomeKit) you can define a switch effect in the config file. To turn the effect on or off you can simply send a “true” or “false” payload to “basement/light/desk-led-strip/effect_sw/set”. It will mirror back the state that has been set to “basement/light/desk-led-strip/effect_sw”.

Apple HomeKit via Homebridge

If you have a working Homebridge server you can easily add this device to it and be up and running in no time. You need to install the MQTTthing plugin if you do not have it already and then add the following to your config file, adjusting as required for your MQTT setup.

            "accessory": "mqttthing",
            "type": "lightbulb",
            "name": "Desk LED",
            "url": "mqtt://localhost",
            "username": "USERNAME",
            "password": "PASSWORD",
            "topics": {
                "getHSV": "basement/light/desk-led-strip/hsv",
                "setHSV": "basement/light/desk-led-strip/hsv/set"

If you wanted to add an additional switch for turning on or off a the pre-configured effect mode then add the following to your config file, adjusting as required.

            "accessory": "mqttthing",
            "type": "switch",
            "name": "Desk LED Effect",
            "url": "mqtt://localhost",
            "username": "USERNAME",
            "password": "PASSWORD",
            "topics": {
                "setOn": "basement/light/desk-led-strip/effectsw/set",
                "getOn": "basement/light/desk-led-strip/effectsw"

Once you have restarted Homebridge you will see a new light on your Home app.

3D Printed Case

I have produced a 3D printed case that fits my PCB, this will probably work for a custom build without the PCB but you will have to play around. I am not sure how well it will snap together without the PCB. The STL and OpenSCAD files are on my github under the folder 3d-printed-case.

NeoPixel LED Controller – OpenSCAD

NeoPixel LED Controller – 3D Printed Case

I hope you have found this guide useful, if you have any problems with the NeoPixel LED Controller or any suggestions, feel free to leave a comment or post on my github page.

Lighting Projects Using This Controller

Here are some photos of the lighting projects I have created using this controller, they are used extensively around my house; a display fireplace, a 3D printer running light, multiple desk lights and stair rail lights.