GOLEM keyboard project

Diodes

Diodes are one important building block of a keyboard as they ensure the proper working of the keyboard matrix and prevent ghosting.

Diodes are the one-way valves of electronics. They let electricity flow in one direction only.

In keyboard building, the main role of diodes used in the keyboard matrix is to prevent ghosting. They ensure multi-key rollover (theoretically NKRO, but mostly 6KRO) when keys are pressed simultaneously.

Diode types

Just like most other electronic components, diodes come in a multitude of types, sizes and footprints.

In keyboard building, for some reason, you can almost exclusively meet 1N4148 diodes.

Through-hole 1N4148 diodes are common in handwired keyboards
Through-hole 1N4148 diodes are common in handwired keyboards

Probably a lot more types would work for keyboards just fine, but 1N4148s are dirt cheap (about $1 for 200 pcs).

Diode direction

Diode direction is crucial. It is usually indicated with a black ring (THM) or a white strip (SMD) on the diode.

All diodes have to point in the same direction for your keyboard to work as intended.

Diode direction marked with the black ring
Diode direction marked with the black ring

On the picture above, electricity can flow from right to left but not in the other direction.

While soldering your matrix or designing a PCB, you can choose either direction until you are consistent since this paremeter can be set in your firmware.

E.g. in QMK you can edit your config.h file:

/* DIODE DIRECTION [COL2ROW or ROW2COL] */
#define DIODE_DIRECTION ROW2COL

Can't you just skip diodes?

You CAN skip diodes in really small boards, when you have less keys than I/O pins on your controller. In this case you can wire up each switch to a dedicated pin of the controller and forget about diodes and ghosting.

The magic number is in the 18-25 range on common controllers based on the Atmega32U4 chip. (Check this little hack to add two more pins to your Pro Micro.)

This means you can wire up a macropad or even a numpad without diodes - until the number of keys doesn't exceed the 18-23 pins.

However, it's unlikely you can get away with skipping diodes on any decent board for typing. Well, except maybe 40% separate splits (without extras), since they feature two controllers, one for each half, thus, have twice the I/O pins.

LEDs

Other than the diodes used in your matrix LEDs used for underglow, backlighting or as status LEDs are diodes too. We just don't exploit their on-way valve characteristic in this case.

More about LEDs in this LED strip underglow guide.