Transistors instead of diodes for more efficient matrix

So here’s that more detailed post.

I’m new to this and fascinated by keyboards like nibble and Discipline that show off their through-hole diodes so I can admire them while contemplating matrix scanning algorithms. While thinking about the diodes, I came up with an idea about using transistors instead. Of course you can build anything with enough transistors, but maybe soldering one transistor per switch is not that much more of a burden than diodes?

Here’s a sketch of how it could work with 2×2×2 I/O pins controlling 8 switches:

The idea is that a transistor is inactive unless its base is pulled high and its emitter is driven low through the switch. You select one set of transistors by activating the corresponding base and emitter I/O lines (sort of highlighted yellow in the diagram). Then any pressed keys in that set will let current flow, driving the collector lines (labeled A/B above) low - these are the outputs that you read to determine which keys are pressed.

That example isn’t too impressive, since 6 I/O lines can already drive 9 switches with a diode matrix. But you can do a full-size keyboard with 15 I/O lines split up as something like 6×5×4 = 120. That would let you use a smaller controller like a Pro Micro with a few lines to spare. Normally 15 would only get you to something like 5×10 = 50 keys.

So I built a tiny test of the concept with 2N3904 transistors:

And it seems to be working:

Is this possibly useful? Pointless? Already done before? At least amusing?


It is interesting, but there is a cost problem: a transistor cost significantly more than a diode and you have one transistor per switch.

So while it seems to work and is an ingenious way to solve limited number of IO pins in an MCU, many people will select other more conventional techniques: use an IO expander/multiplexer, use the duplex matrix technique … or use an MCU with higher IO pins count (the RP2040 is 1$ MCU that allow to manage a full size 104/105 keys keyboard, with duplex trick it can go even higher).

Transistors are 5 or 6 cents on Amazon so that seemed pretty minor to me compared to the other parts. Maybe it’s different if you’re making a full product vs. a custom kit that you’ll be spending hours on anyway?

I do like RP2040, but was kind of thinking of designing for SparkFun’s Pro Micro RP2040 board. Do you have any other recommended breakout boards for that microcontroller? Pico is kind of large and doesn’t have the USB-C connector.


You can find diodes for about 1 cent each, but I do agree that price point of transistors are not that terrible.
Also agree that on a custom product this may not be a great deal price wise.

The RP2040 has plenty of IOs, see no need to use it with this technique applied.
Why not use MCUs with lower IO pin count like Atmegas 32/16/8 U2 ?
Some ESP32 devices also look to be good candidates, you’d have bluetooth on top of that (I think you can use ZMK as a keyboard firmware).

Dev boards are often quite large, to have something compact it may be better to have the MCU directly integrated into your PCB.

1 Like

Phased array antennas are a matrix of antennas that allow for active beam shaping. To a certain extent, switching these antennas poses a similar engineering challenge as multiplexing a keyboard input. Phased array design engineers also ended up using diodes, but of a special kind; namely PIN diodes. However, these are of no added value to keyboards.

phased array antenna


Didn’t know about this kind of diodes!
Thanks for sharing this information, I feel less of an idiot now :slight_smile: