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.
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.
{
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.
{
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:
- CPU - Intel I7 5820K
- GPU / Video Card - GIGABYTE GV-N970G1 GAMING-4GD GeForce
- Power Supply - Rosewill Glacier-1000M, Glacier Series 1000W Modular
- Motherboard - MSI X99S Gaming 7 LGA 2011-v3
- Hard Drive - Seagate Constellation ES.3 ST1000NM0033 1TB 7200 RPM 128MB Cache
- SSD Drive - SAMSUNG 850 EVO MZ-75E500B/AM 2.5" 500GB
- Memory - CORSAIR Vengeance LPX 32GB (4 x 8GB) 288-Pin DDR4 SDRAM DDR4 2400
- Water Cooling - Corsair Hydro Series H110i GT High Performance Water/Liquid CPU Cooler. 280mm
- Case - Rosewill B2-SPIRIT ATX Full Tower Gaming Computer