Arduino LED Lighting

This is just a fun project that I wanted to do for couple of weeks, which finally I was forced to do. My computer crashed and I had to build a new PC (you can see specs below with links to the products). With every good build, you want to add these days some cool LED lighting with it. I didn't want want to just buy simple LED color, but to allow myself change the color as I like. Well, couple of weeks ago I was able to buy 1M (around 3 ft) LED strips from Radio Shack (it is 10 LEDs per strip) and I thought It will be cool to just put the strip on my desk facing the floor. Because these strips are controlled by Arduino, I didn't want just to connect them and also what if I will get tired of the color I didn't want to need and upload a new sketch to change the color. Well nothing like Pot to do the job.

Supply you will need

  • Arduino Uno
  • LED Strip
  • Three Pot to control the values for Red, Green Blue (RGB)
  • Power supply - I'm using 12V power supply

How to Connect

You will notice that the strip has 3 wires

  • Red - Power to the strip. You will want to connect this to the Vin on your Arduino (notice that 5V will not be enough for this)
  • Black - Connect it to the ground of the Arduino
  • Green - Data feed.
The strip has an IC on it that can read the RGB values (24 bits) and when it gets more it just pushs it to the next IC (that is how you can chain many together. I have connected two strips together to generate a 20 LED strip)

Let's look at some code

There are couple of functions with in the code. The main one is the function that sends the 0's and 1's to the IC for each LED (24 values). The IC expect to get high for X amount of ns for 0 and soem time for 1. The function is using the nop command that really all it does is spending 1 cycle doing nothing.

void send_strip(uint32_t data)
{
    int i;
    unsigned long j=0x800000;
    for (i=0;i<24;i++)
    {
        if (data & j)
        {
            data_1;
             __asm__("nop\n\t");
             __asm__("nop\n\t");
             __asm__("nop\n\t");
             __asm__("nop\n\t");
             __asm__("nop\n\t");
             __asm__("nop\n\t");
             __asm__("nop\n\t");
             __asm__("nop\n\t");
             __asm__("nop\n\t");
             __asm__("nop\n\t");
             __asm__("nop\n\t");
             __asm__("nop\n\t");
             __asm__("nop\n\t");
             __asm__("nop\n\t");
             __asm__("nop\n\t");
             __asm__("nop\n\t");
             __asm__("nop\n\t");
             __asm__("nop\n\t");
            data_0;
        }
        else
        {
            data_1;
            __asm__("nop\n\t");
            __asm__("nop\n\t");
            __asm__("nop\n\t");
            __asm__("nop\n\t");
            __asm__("nop\n\t");
            __asm__("nop\n\t");
            __asm__("nop\n\t");
            __asm__("nop\n\t");
            __asm__("nop\n\t");
            data_0;
        }
        j>>=1;
    }
}

The other function is the one that we are sending the data to. It will expect to get the RGB value for the LED, the length of the strip (as patternNumber) and how long should we wait when we are done sending the data to the strip.

void sendSameColorPattern(unsigned long rgb,int patternNumber,int frameRate)
{
    noInterrupts();
    for(int patternIndex=0; patternIndex <patternnumber; ++patternindex)
    {
        send_strip(rgb);
    }
    interrupts();
    delay(framerate);
}

You can download the full code here

Here is the code from RadioShack

Computer Specs

In case you are intrested here are the components I have for my computer: