I have an RGB LED strip (specifically, this one - 1 meter's worth) and a 12V power supply to go along with it, since the raspberry pi alone can not power the strip. I am going to be using pi-blaster to do some PWM to control the colors. I already have GPIO working, but what component(s) do I need to allow the output of the raspberry pi GPIO to control the 12V power input for the RGB LED strip?

I tried N-channel mosfets, but they seemed to not work (I think the ground of the raspberry pi and the ground of the power supply are not the same - but I can't confirm at this time because I can't find my multimeter).


Whenever you have systems connected together that communicate with each other you must have a common ground! Without this, voltage levels are not referenced to anything and could appear as nearly any voltage to the other device. The only exception to this rule is when you intentionally isolate systems from each other, say for noise reasons. Then you might use an optocoupler for example.

With PWM control you should use your MOSFETs or possibly BJTs. A relay will be too slow to switch using PWMs. To ensure that the two supplies whose grounds you are connecting together are properly grounded, test the voltage difference between the ground terminals before you connect them together. You should see very little voltage. Preferably zero volts. If you see a big voltage here inspect your supplies. If there is a big voltage difference between the grounds, when you connect them together you will have current flowing along the ground plane. This is never a good idea.

Assuming the voltage is negligible, when you connect the grounds together, you then have a common ground against which all voltages in your system can be measured. This should allow you to control the MOSFETS using PWMs generated by the Pi, while they source current from the 12V supply


I forgot to mention that depending on the MOSFETs you are using, you may require a charge pump to achieve the correct gate voltage to switch your MOSFET fully on (if you have them configured as high side switches). There are some MOSFETS that have a built in charge pump so that they can be controlled directly from a micro. I dont know which yours are.

Many manufacturers produce gate driver ICs that create the correct voltages for you. (If you find that you have just regular MOSFETS.)

See this IRF app note for more info on gate drivers. http://www.irf.com/technical-info/appnotes/an-978.pdf

Here's an example of a MOSFET that has a built in charge pump https://www.sparkfun.com/products/10213

  • I just need to find my multimeter, then.. At what point would you say that there's too much voltage (between the two grounds) to connect the grounds? – Syzo Mar 5 '13 at 2:56
  • Thats hard to say. I have done this before with cheap supplies and seen large voltages, but been in a hurry so gone ahead anyway. I took an actual measure of current current flowing between the grounds, which luckily in this situation turned out to be very low despite the voltage difference. If you see more than a volt, try and find another supply. There is no hard and fast rule here. Hopefully you will find your supplies are good and there is nothing more than 0.3V between the grounds. Read more about current in the ground plane here en.wikipedia.org/wiki/Ground_loop_%28electricity%29 – Devin Mar 5 '13 at 3:16

A simple power transistor will do. You will need either a common ground or an opto-isolator.

I used a pn2222 to drive a 12v strip in one of my projects; a TIP120 is also a good choice.



Mosfets should work fine if they are correctly rated. What do you mean by the grounds not being the same? You need to make them the same by connecting them with a piece of wire.

  • Is that safe to do with the raspberry pi? – Syzo Mar 5 '13 at 2:09
  • If your LED supply and Pi supply are from two mains transformers (or switchmodes) just join the grounds. If one or both are from battery; also join grounds. – Christopher Biggs Mar 5 '13 at 20:13

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.