Controlling RGB led strips (Analog) using Arduino

led_strips_ledstripbjt

There are basically 2 types of LED Strips, Monochrome Led Strips and Colour (RGB) Led Strips.

We will be focusing on the Colour (RGB) led strips, this group is further divided into 3 groups; Analog RGB Strips, Addressable RGB (Data line & Clock line inputs) and Addressable (Data line input only). The main difference between the 3 types of Colour RGB strips is The Anolog RGB led strip requires  3 PWM signal to shuffle through a pattern to create a rainbow while the other 2  Addressable RGB led types require only 1 data line(and clock input ) to create many patterns ; chaser, rainbow, fire anime, bubbles, sparkles, bouncing.

Our main focus will be the Analog Colour RGB ( 12v, Red, Green and  Blue input lines)

Items you will need. All are available Call +254716806025 – Nairobi, Kenya.

  • RGB led Strip.
  • Arduino Board (any type will do)
  • 3 NPN or N-Channel MOSFET.
  • Soldering Iron & Wire.
  • Perfboard
  • Razor or scaple
  • laptop.

 

Today was a good opportunity for doing some basic tests. My first step was to control the color of the RGB LED Strip with the help of the MOSFETs ()and an Arduino.

Before your read the rest of this blog post, you should read Adafruit tutorial on RGB LED Strips and Bildr tutorial on MOSFETs.

Connecting up to the strip is fairly easy, you’ll want to solder four wires to the copper tabs. We’ll use white for +12V, then red, green and blue wires for the corresponding LED colors.
led_strips_astripend_t.jpg
Cut away the waterproof overmolding at one end of the strip. The strips are symmetric so it doesn’t matter which end you use.
led_strips_astripcut_t.jpg
Scrape away the rubber to expose the copper pads.
led_strips_astripscraped_t.jpg
Melt some solder onto the pads to tin them and also burn away any left over rubber.
led_strips_astriptin_t.jpg
Solder the four wires on. We used stranded wire, which is more flexible and is probably a better choice than solid-core.
led_strips_solderred_t.jpg
led_strips_wires_t.jpg
To protect the wires and maintain some waterproofness, you can use heatshrink.
led_strips_heatshrink_t.jpg
led_strips_heatshrunk_t.jpg

Because these LED strips are very simple, we can easily use them with any microcontroller. We suggest using PWM dimming techniques to control the strip. Since each ‘LED’ pin may end up requiring an Amp or more to sink to ground, power transistors are required! Don’t try to connect the pins directly to your everyday microcontroller, they will burn out and/or not work.

You can use any power NPN or N-Channel MOSFET, make sure the transistor is rated to be able to pass as much current as you need. For example, since we draw about 0.2Amps per channel per meter, if you have a 5 meter strip you will need to pass up to 1 Ampere per transistor. Get the beefy “TO-220” packages, not the dinky little guys. Make sure they look like this:

led_strips_7805_t.jpg

For basic, low-cost usage we suggest using N-channel MOSFETs such as the IRLB8721 – they are very popular and inexpensive and work with 3.3V or 5V logic. If you can’t get those, TIP120 are also good but there is more voltage loss in a transistor than in a MOSFET which is why we suggest those first (less heat loss, more light!)

This diagram shows connecting up with N-Channel MOSFETs where the Gate is pin 1, the Drain is pin 2 and the Source is pin 3

The IRLB8721‘s can handle up to 16 Amps of continuous current – so that’s at least 750 LEDs, and if you don’t have them all on bright white, 1500 LEDs. You may need to heat sink depending on the continuous/overall power draw/disappation

led_strips_ledstripfet.gif
This diagram shows connecting up with power NPN transistors such as TIP120, where Base is pin 1, Collector is pin 2 and Emitter is pin 3. Its very similar except this time we have 100-220 ohm resistors between the PWM output pin and the base.

Controlling the LEDs via RGB colors, like the Adafruit example, is nice, but when you want smoother color transitions HSV or HSL (hue, saturation and lightness) is a better way to do it. Usually you keep the same saturation and lightness and only change hue.

Here is an interesting example illustrating this:

If you have any questions or inquiries please email (brainschild.bc@gmail.com) or comment

// HSV fade/bounce for Arduino – scruss.com – 2010/09/12
// Note that there’s some legacy code left in here which seems to do nothing
// but should do no harm …

// don’t futz with these, illicit sums later
#define RED 9// pin for red LED
#define GREEN 10 // pin for green – never explicitly referenced
#define BLUE 11 // pin for blue – never explicitly referenced
#define SIZE 255
#define DELAY 20
#define HUE_MAX 6.0
#define HUE_DELTA 0.01

//long deltas[3] = { 5, 6, 7 };
long rgb[3];
long rgbval;
// for reasons unknown, if value !=0, the LED doesn’t light. Hmm …
// and saturation seems to be inverted
float hue=0.0, saturation=1, value=1;

/*
chosen LED SparkFun sku: COM-09264
has Max Luminosity (RGB): (2800, 6500, 1200)mcd
so we normalize them all to 1200 mcd –
R 250/600 = 107/256
G 250/950 = 67/256
B 250/250 = 256/256
*/
long bright[3] = { 107, 67, 256};
//long bright[3] = { 256, 256, 256};

long k, temp_value;

void setup () {
randomSeed(analogRead(4));
for (k=0; k<3; k++) {
pinMode(RED + k, OUTPUT);
rgb[k]=0;
analogWrite(RED + k, rgb[k] * bright[k]/256);
}
}

Void loop () {
a + = Hua_delta;
if (a> Hua_maks) {
a = 0.0;
}
Rgbvl = Acsvi_to_rgb (which, Saturtion, value);
RGB [VERSION] = (Rgbvl & 0x00FF0000) >> sixteen; // There must Vez Bay Better
RGB [one] = (Rgbvl & 0x0000FF00) >> eight;
RGB [two] = Rgbvl & 0x000000FF;
for (a = Change of Control; a <three; k ++) {// For All Three Klurs
Anlogvrite (Red + A, RGB [A] * Bright [a] / 256);
}

delay(DELAY);
}

long HSV_to_RGB( float h, float s, float v ) {
/* modified from Alvy Ray Smith’s site: http://www.alvyray.com/Papers/hsv2rgb.htm */
// H is given on [0, 6]. S and V are given on [0, 1].
// RGB is returned as a 24-bit long #rrggbb
int i;
float m, n, f;

// not very elegant way of dealing with out of range: return black
if ((s<0.0) || (s>1.0) || (v<1.0) || (v>1.0)) {
return 0L;
}

if ((h < 0.0) || (h > 6.0)) {
return long( v * 255 ) + long( v * 255 ) * 256 + long( v * 255 ) * 65536;
}
i = floor(h);
f = h – i;
if ( !(i&1) ) {
f = 1 – f; // if i is even
}
m = v * (1 – s);
n = v * (1 – s * f);
switch (i) {
case 6:
case 0:
return long(v * 255 ) * 65536 + long( n * 255 ) * 256 + long( m * 255);
case 1:
return long(n * 255 ) * 65536 + long( v * 255 ) * 256 + long( m * 255);
case 2:
return long(m * 255 ) * 65536 + long( v * 255 ) * 256 + long( n * 255);
case 3:
return long(m * 255 ) * 65536 + long( n * 255 ) * 256 + long( v * 255);
case 4:
return long(n * 255 ) * 65536 + long( m * 255 ) * 256 + long( v * 255);
case 5:
return long(v * 255 ) * 65536 + long( m * 255 ) * 256 + long( n * 255);
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s