I’m building a custom keyboard and have 60 WS2812Bs as part of the backlighting system. I’m worried about the signal integrity as I’m using an STM32 and the max current on that pin is 25mA. Do I need to add a MOSFET to boost the signal or is connecting a 330 ohm resistor enough?

  • \$\begingroup\$ How do you plan to add 330 ohms? And how do you plan to profit from it? \$\endgroup\$
    – asdfex
    Feb 17 at 16:17
  • \$\begingroup\$ @asdfex 330 ohms would be placed in front of the first WS2812B to remove ringing if any. It’s recommended to place one but I’ve seen people say it doesn’t make a difference. \$\endgroup\$ Feb 17 at 16:19
  • 2
    \$\begingroup\$ WS2812Bs are chained in series. The STM32 only has to send a signal to the first LED. Then the first LED sends a signal to the second LED, and so on. The STM32 doesn't send a signal to all the LEDs at once. \$\endgroup\$
    – user253751
    Feb 17 at 16:45
  • \$\begingroup\$ WS2812Bs draw mere microamps from the data pin, why would you need a fet? \$\endgroup\$
    – dandavis
    Feb 17 at 17:01
  • \$\begingroup\$ Your MCU only needs to drive the first LED. The signal will be regenerated by the first LED and every LED that comes after it. \$\endgroup\$
    – StarCat
    Feb 17 at 18:45

You are confusing the data input and the power supply to the WS2812.

The WS2812 (single or a chain) draws its power from the 5V connection. At full brightness a single WS2812 can draw 60 mA IIRC, so that is 1A for every 16 WS2812's! Hence it is a good idea to bypass power (and ground) of a WS2812 (or similar) LED strip with a thick wire that jumps let's say 10 LEDs.

The data input takes very little current, an STM32 or any other micro-controller can supply that with ease. As Tony mentioned, a small resistor might be good for signal integrity.

In my experience you can drive a WS2812 directly from a 3.3V CMOS output, but especially if you have a long line from your uC to the WS2812 it might be an idea to put a 3.3 V -> 5 V level shifter close to the uC (and the series resistor after the level shifter).

  • \$\begingroup\$ Data sheet shows data input can no be ≤Vcc-0.6V. 60 mA chip consumes in full brightness, At minimum approximately 1mA. \$\endgroup\$
    – user263983
    Feb 17 at 19:21
  • \$\begingroup\$ The level shifter would be in series with the GPIO pin? Also, I wouldn’t be powering the LEDs with the microcontroller, I would be taking it straight off the 5v supply. \$\endgroup\$ Feb 18 at 5:12
  • \$\begingroup\$ Yes, in series; preferrably directly, and do note the maximum current you will need! \$\endgroup\$ Feb 18 at 17:00
  • \$\begingroup\$ Or just use a 5V MCU. Most modern MCUs can handle 3 - 5V. \$\endgroup\$
    – Lundin
    Feb 19 at 8:59
  • \$\begingroup\$ ? Most modern MCU's I see are 3.3V. Which are 3-5V? \$\endgroup\$ Feb 19 at 16:50

If STM32 has Vdd max = 3.6 and WS2812 is CMOS input rated for 3.5 to 5.3 with Vih max >= 0.7 * V+ then you need a level shifter to extend past < 30% & > 70%.

Due to mismatched impedance of interconnecting cable some ringing occurs so a series R <= cable impedance improves damping of ringing to Input. Twisted pairs might be 240 Ohms and driver might be 50 +/- 30%(?) so 180 to 220 might be ideal and 330 ohms should also work for these low(ish) clock rates.

  • \$\begingroup\$ Would I have to include a MOSFET driver? If so, how would I go about it? I plan on making a PCB so there wouldn’t be any wires.. \$\endgroup\$ Feb 17 at 16:40
  • \$\begingroup\$ So what supply voltages are available? For a non inverting CMOS level shifter IC? Or a transistor common base ....3.3? And 5V? Then no series R’s is needed \$\endgroup\$ Feb 17 at 16:44
  • \$\begingroup\$ I would have 3.3v as well as 5v. \$\endgroup\$ Feb 18 at 5:10

Data can be boosted to 5V with something like an SN74HCT125 (this is a quad channel, so you could use four different pins from the SMT32 to drive 15 LEDs each).

As mentioned a resistor in the line is also considered best practice. I've found 33 to 120 ohm work best for me.

Also a good idea to put some sort of reverse current protection in as WS2812B do not like you shoving power up the ground line.

You could also use a stand alone board like a QuinLED-Dig-Uno (you can buy PCBs and the components to make yourself) to get all this, plus fuse protection from here: https://quinled.info/2018/09/15/quinled-dig-uno/

FYI: I have NO affiliation to the above. Just used them myself and also found Quin to be a good guy helping me out when I butchered my first go at wilding a soldering iron making up one of his boards.

  • \$\begingroup\$ The reverse current protection would be a diode at the beginning of the LED strip, right? \$\endgroup\$ Feb 18 at 5:17
  • \$\begingroup\$ Yes, but instead of suffering the voltage drop being inline I put a Schotkey diode in reverse bias across the 5V and Ground, so if hooked up correctly no current flows across it but if hooked up reverse it goes across the diode rather than through the strip. This will only work if you have a fuse in line as well otherwise the diode will just burn up. \$\endgroup\$
    – Kosh42EFG
    Feb 19 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.