Driving RGB LED Strips Off an Arduino

86K23021

Intro: Driving RGB LED Strips Off an Arduino

Christmas is coming and you may be wondering how to make it colorful and bright with an Arduino and an RGB LED strip. At least, that was exactly what I did a year ago and wasn’t able to find any clear and simple instruction anywhere. With this instructable I will try to correct that sad omission.

At this point you should have an Arduino board and 5 meters of an RGB LED strip with its power supply on your hands. As the Arduino has 6 PWM outputs let’s assume that you intend to use them fully, so have cut the strip into two 2.5 meter pieces.

Depending on which way you chose, you’ll need some additional hardware, as described in the steps below. Onward!

STEP 1: Power Supply

Before we start connecting the Arduino to a LED strip, let’s deal with the power source. LED strip is usually run off 12 volts, Arduino works on 5 volts. Most Arduinos have a Vin pin that can be connected to bigger voltages, with 9 volts recommended and 12 volts a safe maximum that, according to some, should be generally avoided. Considering that a LED strip power supply usually provides a bit more than nominal 12 volts (something like 12.3 in fact), you may be tempted to avoid connecting it to Arduino.

However, if you check the specs of a voltage regulator onboard your Arduino (it’s a variation of a 1117 5v regulator) you’ll see that it is perfectly capable of dealing with 12 volts. Its power rating usually states 20 volts as a maximum (such as the MC33269 from ON Semiconductor that is installed on most genuine Arduinos), some models have a 15 volts restriction (such as the AMS1117 5.0 found on most Nano clones), but almost never less (one exception I found is Torex XB1117 that has a rating of 10 volts, but you won’t see it on a Duino board, genuine or not). In any case, if in doubt, you may check this instructable to find out more about the voltage regulator. On a Nano it sits on the back, but is easily recognizable.

So, it’s perfectly safe to connect everything to one 12v supply: the LED strip directly, the Arduino via its Vin pin (don’t use the power jack; the strips +12V line MUST be connected directly to the power supply). There’s one thing however that you should be aware of: the heat. Voltage regulators tend to heat a lot and their heatsink has a rather small footprint, so it’s better to check its temperature after some working time, to be on the safe side.

You may also connect the Arduino to 5v and the power line of the LED strip to 12 volts. It will also work, juts don’t forget to connect the grounds from both sources together.

It is a good idea to add a master MOSFET to the 12v circuit to be able to disconnect the LED strip without disconnecting the power (say, with an IR remote).

STEP 2: N-Channel MOSFETs

The most obvious way of connecting LED strips to an Arduino is using N-Channel MOSFETs. There are tons of tutorial on their use, like this one. The N-Channel MOSFET is ideal for our purpose, because it sinks current, is placed after the load, so the connection is extremely simple: Source to Ground, Gate to Arduino pin, Drain to a color channel of the LED strip (usually a colored wire). A resistor of 220 Ohm is recommended between the Arduino pin and Gate, but is not strictly necessary. Now you can control the LED strip the same way you blinked a LED on a breadboard.

Which MOSFET to use? As we’re dealing with to220 package here, they’re all pretty powerful. However, some are made to handle high voltages (1000V and more) and some are good with high currents (200A and up). You won’t need high voltages, so aim at one that works with at least 20 Volts and 6 Amps. In fact, you’ll probably end up with something like 55V/41A, as these are common and could be useful in your other projects.

This method is quick and easy, but has a downside: you’ll need 6 MOSFETs for 2 pieces of LED strip, and they are bulky, sometimes costly and basically a bit of overdrive, as their power rating usually is way more than you need (like 55V/41A). You may also find this too obvious and want to make something more interesting. Ok, on to the next step.

STEP 3: Darlington Transistor Arrays

An excellent alternative to MOSFET is a cheap Darlington transistor array like ULN2003. In short, this chip is a bunch of transistors stacked together in one convenient package (DIP included, so it’s easy to use them on a breadboard). Each transistor pair on a Darlington has a power rating of 500mA, but they can be paralleled for bigger currents.

Darlington arrays usually come in two packages: 7-pair and 8-pair. The second is obviously better for our projects (and costs the same). For two 2.5 meter strips, we’ll need at least three such 8-pair arrays as we’ll want to parallel 4 pairs on one color channel of the LED strip, achieving a power rating of 2A. Why so much, if, according to the LED strip datasheet, it should consume 3A in total for a 2.5-meter piece?

UPDATE: I fell for the common mistake here, that is, considering Amps a constant and not relying on Ohms Law. The LED power consumption of 20mA is correct for its nominal voltage, around 3V. If we're powering it with a 12V power supply we can effectively divide this power consumption by 4 (or by 3 if using a 9V supply). So, just to be on the safe side, we can assume that each LED consumes 6mA from a 12V supply, which means 1.8A per color on a 5m strip; it's 2.4A for a 9V supply. So it is possible to get away with only 2 pairs per color in parallel for a 2.5 meters and 4 pairs for a full strip. Still, you can't go wrong with excess safety, and Darlingtons are cheap, so there's no need to actually reduce their numbers unless you're short of space.

Because a power rating of a RGB LED strip deals with its overall consumption. RGB LED strips are intended for decoration, not illumination; it is not intended to be turned fully on, producing bright white light (in fact, a LED strip is supposed to be connected to a controller that restricts its power usage). However, individual colors, say, green, can be turned fully on. Considering that we have 60 LEDs per meter of the strip, and each LED is consuming around 20mA, it’s easy to see that a full-on single color will need 1.2A per meter, or 6A for a 5m strip.

Why, then, only 4 pairs and not 6 (that will fully cover 3A)? Because we are essentially building a LED strip controller on an Arduino and can restrict the current by not turning any single color to full brightness for a long time (short bursts are ok). However, you may want to use all 6 pairs to be on the safe side. That’s the reason for ‘at least’ up there.

The wiring of a Darlington array is extremely simple and obvious, as an input pin and a control pin are facing each other (see the picture above). And yes, it needs only ground connection, no voltage.

This covers the basics and is enough to get your Christmas lights running.

STEP 4: The RGB Amplifier

Essentials over, story mode on. My wife presented me with an Arduino (I think she regrets it now) last autumn. I blinked and I buzzed and then decided to return the favor in form of a Christmas decoration. As I was totally inexperienced then, knew absolutely nothing about electric stuff, I went to Instructables and found this (WARNING: read the WARNING there!). A year ago there was no WARNING in the article, so I ordered a bunch of RGB amplifiers and actually made this stuff as described there. And it worked, and the wife was happy, and we had cool illuminated holidays. Yes, there were glitches and yes, I fried one pin on an Arduino, but that last bit came later when I was experimenting.

I suspected something is not exactly right with this solution, but I was inexperienced, in a hurry, and actually ordered a bunch of cheap Chinese Nano clones with the amplifiers, so please don’t judge me harshly.

Also don’t discard the amplifiers: properly cooked, they are pretty useful, as you’ll see.

Gone Christmas I decided to dig a bit deeper into the amplifiers theme. Most notably, I didn’t like the aforementioned glitches: the contraption sometimes went into an infinite reboot loop, and I was pretty sure it was hardware problem, not software. Not only did I fry a pin, I also dissected an amplifier to learn how it worked. And everything became clear.

See the picture above. On the output end of an amplifier there are three N-channel MOSFETs, as described in step 2 of this instructable. Next to them sits a logic-inverting chip that provides voltage to the gate of the mosfet when there’s nothing on its respective input and vice versa. The amplifier works pretty simply: it tries to sink voltage (without any load) via each input channel. If it sinks (the respective channel is grounded, meaning the LEDs are on), nothing goes to the inverting chip, so it provides voltage to the MOSFET gate, which in turn opens the output channel. If not, the voltage goes to the invertor, closing the MOSFET.

Now, the amplifier is connected to 12v power supply. It doesn’t have any voltage regulator (what for? It thinks it is connected to another LED strip!), so, being connected to an Arduino, it grounds 12v in an Arduino pin that is limited to 5v. Which is obviously bad, even if Arduino may sustain such a treatment (or may not).

That is why the method described in the WARNING instructable is wrong.

But there’s a bright side. Note that an amplifier sinks 12 volts with no load in it. Which means that almost any transistor on the other end will do, it doesn’t have to deal with high Amps, just with 12 volts. So if you connect RGB amplifiers to a Darlington array, you won’t need to parallel its transistor pairs, meaning a single Darlington will easily handle two RGB strips connected via amplifiers. And that’s how my LED strips are working this Christmas, by the way.

And there’s more!

You can connect RGB amplifiers to LED drivers like the TLC5940, thus increasing the number of connected RGB strips almost indefinitely! Well, at least to 5 with one driver. In any case, the LED driver is a current sink device capable of dealing with 12 volts, but not a lot of Amps. The amplifier sinks 12 volts with no Amps in it, thus producing an ideal combo. The connection if straightforward – color channels from an amplifier go to output pins of a driver, and that’s it. You may read more on the LED drivers in my other instructable.

STEP 5: Making Your Own Board to Run 5 RGB LED Strips

After dissecting an amplifier and playing around with LED drivers I decided to make an Arduino-like board capable of controlling 5 RGB strips (or more with additional boards attached). As I was ordering some other PCBs from the fab and had place on a 10x10cm default plate, I included the first prototype in there. And it was wrong, so I had to make a second one. This ‘bonus’ step may help some of you avoid my errors.

The board design is pretty simple: it has an Atmega328 chip, a LED driver (DM633 in my case), a 1117 5.0 voltage regulator and 15 N-Channel MOSFETs on 5 RGB outputs. Unlike an RGB amplifier, this board doesn’t have any logic-inverting chips, so the logic is inverted in software (namely, 0 means full on and maximum value means off). The MOSFETs gates go to LED driver outputs and are pulled up to 5v by 10K resistors, so they keep the current flowing when the driver is closed and stop doing it when the driver output opens, sinking current.

Which leads to the first important thing: there must be a powerful master MOSFET on such a board that will keep the power to the strips off when it’s not needed there. That is, while the device boots up. If there’s no such MOSFET installed, all the LEDs on all connected strips will turn fully on the moment the power is connected (as the driver keeps outputs off by default, but we have the logic inverted). And this will lead to extreme power consumption and possible death of the power supply unit or something of the like.

Secondly, the voltage regulator (in SOT-223 package) must have its heatsinking bump properly connected or it will heat a lot. And the aforementioned bump is NOT the ground, as one would think, but output. I didn’t check the datasheet and my ‘logic’ failed me here, don’t repeat that mistake. I even made a big heat sinking zone on my version 2 board, but that’s not needed.

The rest is pretty straightforward here.

And that’s it! Please feel free to ask any questions!

18 Comments

Hi Ontaelio,

Thanks for putting this together. I really liked your explanations of the MOSFET and the resistor values.

I plan to use your design to control an RGB LED strip (5mtrs) in tandem with an IR sensor on the Arduino (via an IR remote). There was one thing that confused me. In your article you suggest using a master MOSFET. Could you elaborate on where to connect this in the circuit? Since I plan to turn off the LED strip with an IR remote occassionally, I wonder if this master MOSFET is all the more important in my circuit.
Hi SamuraiJack,

I don't have the contraption by me at the moment (it's in another town where we tend to spend the winter holidays with the daughter), thus I can't check. But both the master MOSFET and the IR sensor are present at the photo in step 4 above. In fact, the device still looks the same, I never bothered to do anything to it: if it works don't fix it. Although the breadboard is pretty dusty now.

In any case, in my device the master MOSFET (N-Channel) connects grounds from both RGB amplifiers to the power source, and is controlled by the Arduino. Thus, when I press the off button on the IR, the power stops flowing through the strips, but the Arduino stays on awaiting the next IR command. I guess that's what you need.

If you don't use the amplifiers and go with a bunch of Darlingtons or per-channel MOSFETs, I guess you'll need a P-Channel master MOSFET on the 12v power line going to the strip from the power source.
Hi!!! Thanks a lot for your time and effort!
I have a question, How do I use this with a 5v led Strip?? I know it may be a simple thing, but I'm a total newbie... so, any help would be appreciated... :)
I am wanting to buy your controller, but I need to run 24v LEDs, like these RGB+24 stripes EAGWELL 20M LED Strip Light,65.6ft SMD5050 1200 Leds Light Strip LED Flexible Waterproof LED Strip Lighting Kit with DC Adapter,24V 5050 Strip Lights , https://www.amazon.com/dp/B01CRNP2HS/ref=cm_sw_r_cp_api_Zq3gAb0VSH5VD

Note that the RGB strip at your link is 12v, not 24. It's the warm white one that's 24v. If you need to run both of them, I'd suggest connecting the 24v to the Arduino PWM pin (even on my board) via a power mosfet, as described in step 2.

Couple questions. I am interested in your boards, but can I tweak it to support 24v strips? How hard would it be to make a handful of “scenes” like a breath bright to fade that cycles colors for holidays? So the 5 channels would match or cycle RED/WHITE/BLUE, press a button and then REF/GREEN press button ORANGE/PURPLE, and so on. So far I can only find generic simple Chinese controls or have to build a expensive DMX controller.
Hello!
1) can you please provide the info on your particular 24v strips?
2) didn't get your idea exactly, but generally, if you can produce the desired effect on RGB LEDs connected to an Arduino, it's simple to port it. It's just more LEDs and setRGBpoint() instead of three analogWrites().

hi i have question i followed thwe schematics here but my LED strips is not communnicating with my arduino because i tried to disconnect arduino from the LED strips and it is still on with out the arduino all colors on full brightness

So I had a question regarding the led strips and how you connect it with the arduino's. So Im looking at using a IP-65 rated 3.5 Watt Led strip and to connect it to the arduino, I need a transistor. My main question regarding that was, what transistors do I use, or which is the best transistor to use for this project since it's going to be a long term thing.

Thank you

Nice project.is that possible that you post the schematic of your 'custom-made RGB strip board'?

I'm not good with schematics, but here's what I've drawn today. These are the basics, hopefully I did it right.

great instructable I've been looking for one like this for ages now, could you post the code you used with the N channel MOSFETs as im not very good when it comes to coding.

the lights instructable is on here https://www.instructables.com/id/How-to-Make-Proper-Rainbow-and-Random-Colors-With-/ There's some code in it, it will work with LED strip too.

Thanks! LED strips connected via N-Channel FET are controlled the same way as a simple RGB LED, that is, via AnalogWrite(). The basic example from the Arduino software (03.Analog -> Fading) will do.

If you're meaning the stuff in the video, this is material for another instructable that is being written for a long time - I'll try to finish it ASAP. The code used in my Christmas strip uses my TV remote as a controller, so it won't be useful to anyone, and as even I don't remember already how it works (I didn't comment it) - well...

However, I can drop a sketch for a simple but smooth RGB rainbow effect if you wish, if it will help. The not-yet-written instructable is going to explain how it works and why it was written so.

No, my scheme is right. 220 Ohm resistors on my schematic are 'recommended' ones, they are used as a kind of protection against some stray currents that may appear on a MOSFET gate (and which are bad for an Arduino pin in Output mode). The resistors on your picture are pull-down resistors, they can be used to make sure the MOSFET gate is grounded when nothing comes from an Arduino pin. However I'm not sure that 100 Ohm ones pictured there are enough (I'd go for something bigger, like 100K, but I never tried this setup). And they are not needed, as a MOSFET will work without pull-down.

In any case, there's one big bad wrongness on your picture: the +12V of a LED strip is connected to Vin pin there. I suppose that means that the Mega pictured is connected to a 12v power supply via its power jack. With a long LED strip that will lead to extreme heating of a diode on the Arduino (it is located right below two big capacitors close to the jack), and this diode will eventually either fry or unsolder itself. As far as I understand, this diode is placed there for this purpose, btw, as it is a current limiting one (correct me someone if I'm wrong).

Hello Ontaelio, yes your scheme is right, sorry to claim your for a mistake.

As I work with the mosfet and led strip right now I only found scheme's and program with resistor from gate to ground. But now as I search mosfet with resistor I found a very good explanation about the resistor between gate and arduino pin. http://forum.arduino.cc/index.php?topic=153543.0

And yes the pictures I linked to, not my side or the pictures, is not the best and has a big wrongness as you write, the +12V should not go to the Arduino Mega it should had there own powersupply.

With kind greetings from Denmark

Gregor