Information on adding support for in-switch LEDs to a PCB?


My current keyboard project is the Ergo87. So far I’ve designed the case and the first revision of the circuit board. In the next revision I would like to improve the PCB and add support for RGB underglow and (Non-RGB) switch LEDs.

If I’m not mistaken, the underglow should be pretty easy. I believe all that takes is wiring a PWM pin, 5V, and GND to a strip of RGB LEDs. So, I would just find/create a footprint for the WS2812 (Specifically this part) and add a handful of them to the backside of the PCB.

Supporting switch LEDs is something I am less familiar with and I’ve been unable to find an open source PCB that does it. I know that I’ll need to modify the footprint for each switch to add holes for the LED legs as well as a spot for a resistor. Where I have no idea what I’m doing is how to connect that all together and to the microcontroller.

Can anyone point me to some resources where I can learn more about this? Or to an example PCB that supports switch LEDs?


Do you want to be able to control each individual LED or controlling all at the same time is enough? That choice will drive your design.

The underglow RGB LEDs should be addressable but having a single brightness control for all of the switch LEDs is sufficient.

In that case you can do a simple hack, the same one I’ve used when designing the S60-X RGB: using the scan of the switch matrix to activate the LEDs.

On the S60-X RGB I’ve separated all the LEDs in 5 rows of approximately 14 LEDs each, give or take, that’ll be activated one at a time fast enough to take advantage of the Persistence of View phenomena. That was made this way to avoid drawing too much current from the USB port.

For that purpose I’ve used the scanning signal sent by the pins assigned for the switch rows to activate the LEDs. That works as a poor man multiplexer because, at any given moment, only one row will be active at a time. This signal is digital LOW, for reasons best explained here.

But that only turns the LEDs ‘on’, so to speak. The circuit, as described, doesn’t allow any control of brightness. That’s where comes the PWM control (QMK make this easy to the point of being trivial), so I add it to the circuit, allowing the user to turn the LEDs on, off, or something in between.

The simplified circuit is this:

, where /ENABLE is the signal that comes from the switch row, and PWM_CONTROL is as the name says. I’ve used a pair of n-channel/p-channel MOSFETs for power loss efficiency and on the actual PCB this pair is a single SMD component. All pairs of LED/resistor are connected in parallel between both MOSFETs.

I hope that’ll help you. :slight_smile:

Thanks a ton for that explanation! :grinning: There are a few things in there I’m not sure I understand yet but I’ll follow up if I can’t figure it out.

Don’t be afraid to ask about the bits you didn’t understand! It isn’t that complicated, but maybe the way I wrote it is kinda confusing.

I think I understand everything until the last paragraph, mostly because I’m not familiar with MOSFETs. I built an iris and remember having to solder a 3 pin SMD MOSFET on each half but admittedly didn’t understand why.

What I’ll probably do is mock up a 2x2 PCB with LEDs and post it in here to make sure I’m able to understand what I’m doing before expanding to 87 keys! Hopefully that will be useful for others as well.

MOSFETs are transistors and are used as digital switches. The main difference between them and BJTs is that the latter are controlled by the current at the base, while the former are controlled by the voltage at the gate.