# Raspbery PI GPIO output failing to control RGBW strip via N-FETs (always on 100%)

I'm trying to build a lighting system that will give me 24 hour control of some RGBW strips using a Raspbery PI Zero.

I'm a software guy, so I'm pretty new to the electronics beyond a bit of work on cars and wiring the odd plug/light fitting. There are a few tutorials for wiring RGB strips with PI and Arduinos and they're all pretty similar, using the GPIO to trigger Mosfets to provide the 12V needed for the strip.

I've been mainly following this tutorial here, but adding an extra Mosfet for the white LED pin.

Here's my schematic (yellow wires => white):

I used 4 IRLB8721PBF 30V, 62A N Channel MOSFETs, 5 meters of 12VDC 5050 rgbw strip (ebay special, not much data). The GPIO is connected to the gate, the RGBW strip channel is connected to the drain, and the 12V- to the source.

I also installed pigpiod on the PI using method 1.

When everything is up and running it lights up:

However, I'm finding it is always seems to be fully lit. When I try change the levels via the GPIO pins using commands like this (turn it off):

pigs p 17 0
pigs p 22 0
pigs p 24 0
pigs p 27 0


or this (make it red):

pigs p 17 255
pigs p 22 0
pigs p 24 0
pigs p 27 0


Basically nothing happens and it stays at 100% output on all channels.

My question: How should I approach debugging this issue? I've only got a cheapo multi-meter.

Also, I'd like to double check my understanding.

At first I thought Mosfets used the gate voltage to 'switch' the larger source/drain voltage. So when the output of the GPIO reaches a threshold, the mosfet switches 'on' and the 12V passes from source to drain.

I can't see how that would convert the (angalog?) raspberry PI signal from the GPIO to anything meaningful other than an ON or OFF 12V.

Is the Mosfet taking the gate voltage and amplifying the 3.5V to 12V proportionally? So 1.75V output (a value of 127) would produce 6V, and thus that channel would be 'half' brightness? (If it worked!)

Edit

I've wired just a single Mosfet up with a single colour on the RBG,

The center pin is to the RGB R channel. The right pin is to 12V- (ground)

The RGB + is 12V+

Now, when I touch the left pin to 12V- (ground) it should turn off right? This is simulating LOW output (excuse the awful paint diagram):

Test 1 (should be off):

Test 2 (should be on):

What I get is a bit of a mess. It's flashing on and off. Sometimes it's consistently off, but often consistently quite-low. Then, suddenly it's ON full, then flickers.

It kind of turns off more often than not when the ground is to source, and on more often than off when ground to +12V (or +3.3/5V output on the PI, not GIPO), but it's all over the place. Often it doesn't go 'off' just consistently very low, but even then its acting as if there's a loose connection or something - even through I've tried soldiering all connections.

I can't think of anything that would cause this but dodgy Mossfet? I could have caused problems soldering the connection on.

• Can you measure V from GPIO thru each stage to LED? Usually brightness is PWM controlled not analog level ( lossy too hot) May 24 '17 at 13:52
• I'll try take some voltage measurements at various locations. You're right, it is PWM controlled (thanks to the other answers), would PWM with 50% duty period come up as half the voltage on a multi-meter?
– Joe
May 24 '17 at 14:02
• If all the colors are on that means the gate is being pulled high all the time. Double check your wiring And mosfet pinout, and ensure that the gpio is output low (for off). May 24 '17 at 18:53
• First question you need to determine is if the LED strip still lights when removed from the pi. If so, your FETs are shorted (at least partially) on or you have a wiring problem. If not, it would seem you do not have control of the pi GPIOs yet, have misidentified the pins, or possibly damaged the pi. May 24 '17 at 19:24
• I removed from the PI and tested (just a single MOSFET & channel). It's very flickery and inconsistent, even after soldering the connections. See edit for test schematic in edit.
– Joe
May 24 '17 at 22:49

I may be somewhat bewildered, but probably because you were bewildered first.

I used 4 IRLB8721PBF 30V, 62A N Channel MOSFETs,

They are not NPN (as in the title). They are MOSFETs :)

How should I approach debugging this issue?

Detach the RPi at all. Try to connect gate of any mosfet to the source. The leds should go off. If connected to +12, they should go on. Unless I misunderstood your schematics.

Then repeat the same feeding simple HIGH / LOW level from the RPi (not PWM). This will help understanding whether your pins are controlling the leds via mosfets.

Don't forget to switch off pull-ups on pins if you have them.

• Oops, I got "N Channel" mixed up with NPN in the title... corrected. Could I ask what you mean by "switch off pull-ups on pins if you have them."? I'm not sure if I have them!
– Joe
May 24 '17 at 13:18
• Ah, sorry - I'm wrong here, pull-ups do not matter if your pins are properly configured for output. It would be good to test connecting small led + 1kOhm resistor between pin and ground. (instead of the band with transistor) May 24 '17 at 13:31
• I tried detatching and connecting the gate to the source/ground. It went off... sometimes. It seems wildly inconsistent, flickering on and off and on. It kind of turns off more often than not when the ground is to source, and on more often than off when ground to +12V (or +3.3/5V output on the PI, not GIPO), but it's all over the place. Often it doesn't go 'off' just consistently very low, but even then its acting as if there's a loose connection or something - even through I've tried soldiering all connections.
– Joe
May 24 '17 at 22:52
• That flickering is rather suspicious :) If you are sure in connections, then perhaps it's time to check the 12 V power supply? E.g. connect other band (say, blue) in parallel, directly to it and see whether they flicker both simultaneously or only red one... May 25 '17 at 8:53
• Good idea, I did not think to test the power supply (and strip) by just connecting the 12V directly.
– Joe
May 25 '17 at 9:51

At first I thought Mosfets used the gate voltage to 'switch' the larger source/drain voltage. So when the output of the GPIO reaches a threshold, the mosfet switches 'on' and the 12V passes from source to drain.

TRUE. (Actually the voltage does not pass, it is the current which passes.)

Is the Mosfet taking the gate voltage and amplifying the 3.5V to 12V proportionally? So 1.75V output (a value of 127) would produce 6V, and thus that channel would be 'half' brightness? (If it worked!)

FALSE.

pigs p command controls a PWM output. You should check if your outputs are properly configured as PWM (I'm not familiar with Raspberries). When you control the PWM duty cycle changing it from 0 to 255 (== 0% to 100%) you control the time your color channel should be lit. If your PWM frequency is 50kHz (period of 20us) and your duty cylce is 64 (about 25%) the channel should be lit for 25%*20us = 5us and OFF for the rest 15us. This way a LED strip is dimmed. So far - so good.

The other thing to consider is driving your MOSFET. I think there is your problem. On high frequency PWM a high current gate driver should be used to drive the MOSFET properly. It's because of its input capacitance (and reverse transfer cap. as well).

First try to set up the Raspeberry for a lower PWM frequency. Anything over 100Hz is OK for eye visible light flickering and over 18-20kHz will not produce a sound that human can hear. Then you could get some MOSFET current drivers for at least 1.5A and connect them between the Pi and each MOSFET's gate.

An oscilloscope would be in a great help here. ;)

• Ah, I had a thought it might be a digital signal of varying frequency rather than an analog signal of varying amplitude (hence the question mark after "angalog?"). That does make it a pain to debug without access to an oscilloscope. Shouldn't setting the PWM output to 0 should turn it all off regardless of the configuration though?
– Joe
May 24 '17 at 13:15
• Yes, if PWM is properly configured setting 0 you should read 0V on this Raspberry pin. Detach the MOSFET while measuring this to be sure if the problem is with the pin output or MOSFET connection. May 24 '17 at 13:19
• One thing I did notice, the breadboard wires are very thin (and I had some issues with bad connections). Given the RBG array is something like 72W, is it possible the breadboard is causing issues with higher currents? I'm hesitant to start soldering things together though, given it doesn't work!
– Joe
May 24 '17 at 14:36
• Before soldering, first check your Rasp. configuration, connect a low power LED with ressitor directly to Rasp. as @RodionGorkovenko suggested, make it DIM with PWM value of pigs p and when you got it all working then you can go soldering. May 24 '17 at 14:56
• I managed to get a LED and resistor working. I also removed the PI and tested a single MOSFET & channel. It's very flickery and inconsistent, even after soldering the connections. See edit for test schematic.
– Joe
May 24 '17 at 22:50