Dimming an LED strip

I have an RGB LED strip from Radio Shack and I am making a visualizer. I am new to circuit building (not programming) and am trying to figure out how to dim the LED strip with one of the digital or analog pins. The only issue is that the strip requires 12vDC to run properly and if I recall correctly, the max for any one of the pins is 5vDC. I have looked at JFETs, Digital POTs, or making a jerry-rigged one by combining a flat led with a photo-resistor. My question is: How can I control a 12v current (I would like to be able to control the output voltage from between 0-12 volts) using a 5v pwm signal.

Thanks

That will give you an idea, exactly how you do it will depend on the LED strip. My guess is that your LEDs will require a separate 12v power supply and some transistors of some sort at the very least.

How long is your strip? 5m would require transistor, less than 1m you can do with ULN2003/ULN2803

Yeah you can drive it with a transistor or mosfet. I recommend the IRF540N mosfet.

The Transistor seems like a good idea. The 1 meter strip I have has the capability of lighting up individual lights instead of the whole strip being one color. It uses a TM1803 chip to control the led colors. The only problem is that if power is disconnected, the whole strip resets. Is there a way to maintain a constant power to the strip using a transistor connected to PWM?

Why don't you first write the code? With the transistor the code would be the same as PWM-ing an LED.

The code is already written. Unfortunately I fried my Uno when I was testing a different idea. Do I use a capacitor in conjunction with the transistor to keep a steady,variable voltage going to the led strip? If so, how much (Again, new to circuit building).

I am sorry you fried your Arduino. You don't need a capacitor; PWM is a pulse, if you add a capacitor it will absobe the pulse and there will be no dimming--full brightness.

http://www.titanmec.com/doce/product-detail-217.html

Send the correct data to the part - it has PWM control built in.

alright. Ill have access to a new board tomorrow. Ill see if the PWM and led strip work together. I am thinking that if the power is off for too long, the strip will reset(uses a tm1803 led driver). Im also looking into using a mosfet as a variable resistor.

Crossroads: in reply to your post, the tm1803 has 3 output channels meaning a single ic can control 3 single color leds or 1 RGB led. In my case, its the latter of the two meaning that any change in signal needs to be applied 3 times, once for each color channel. Since Im building an audio visualizer, the brightness changes every loop and since the tm1803 is time based, the calculations to change the color is too slow for the strip to be correctly set to a color sequence (trust me because I did this just before I blew the capacitor on my Uno).

You have to send it different data for each color.

"TM1803 adopts single wire to communicate and RZ (return to zero code) method to sent signal. On power-on resert status, when chip receive complete 24bits data from DIN, it begin transmitting data to next chip via DO. Before transmission, DO will be keep low-level.OUTR, OUTG, OUTB these 3 PWM will output different duty signal according to different data per 24bits, the cycle of signal is 4ms.If input signal is RESET, the chip will be ready to receive new data after displaying all the received data.The same when receive new 24bit data completely, it will transmit them to next chip via DO."

Read the datasheet - send it 3 bytes, 1 for each color. If you have multiple LEDs/TM1803s, then you will send it multiple groups of 3 bytes.

Yes but if the signal on the input is a low bit for longer than 20 microseconds it sends a reset code. This is the issue I had before. For instance if I had a color 0xFFFFFF, extracting the RGB components, multiplying them by the correct brightness scale and then concatenating them together took too long and therefore sent a reset signal to the chips.

If you have another idea on how to adjust the color, I would be more than happy to hear it.

Here is the "sendColor" function that I have in my code

void sendStrip(uint32_t data){

  int i;
  unsigned long j = 0x800000;
  
  for(i = 0; i < 24; i++)
  {
    if (data & j)
      {
      OnBit;
      __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");
      OffBit;
    }
    else
    {
      OnBit;
      __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");    
      OffBit;
    }

    j >>= 1;
  }
}

OnBit sends a high value to the analog pin
OffBit sends a low value to the analog pin

The groups of "nop"s are delay functions that send the bits to the ic.

Here is the LED strip's documentation as well:

http://www.radioshack.com/graphics/uc/rsk/Support/ProductManuals/2760249_PM_EN.pdf

Ok, so it looks like you have to continuously send data to these parts.
One way to do that is with SPI.transfer( )s

Set the SPI divisor to 1/16 for 1 Mbps data rate, and send out the three bytes of data

void loop(){
currentmicros = micros();  // time elemets are all unsigned long
if ( (currentmicros-previousmicros) >= interval) // interval at 20 ? (microseconds) = 320 clock cycles
   {
   previousmicros = previousmicros + interval; // set up next time period
   SPI.transfer(green_byte); // or whatever order is needed
   SPI.transfer(red_byte);
   SPI.transfer(blue_byte);
   }
// update color codes as  needed
}

After some more research and tinkering, I think that I will end up using an op-amp to scale the voltage from a 0-5 range to the 0-12 volt range I need.

Alright. I'm back. So I bought a generic op amp and am following one of the schematics for voltage scaling but it is making the voltage smaller instead of larger. Can anyone tell me how to scale a 0-5v signal to a 0-12v signal using an op amp?

Take your 12V powered op-amp, connect the 0-5V signal to the + input.
Use a resistor divider and set the -input to 0.5V.
When the + input is >0.5V, the output will be ~12V.
When the +input is <0.5V, the output will be ~0V.
The 0 & 12V will be determined by the load you put on the op-amp, and how close to the rails the op-amp can drive.

I don't see how that helps with the need for your code to continuously the T1803 chip tho.

Sorry. Away from home. The change in the voltage can change how bright the leds are by changing the input voltage. I attached a pot to the 12 volt wire for the strip and changing the resistance changed the brightness.

Is there a way that the 0-12 voltage can be a smoother line.

I attached an image of the graph.

Basically the blue line is the input voltage and the red is the output. The gain is 2.4.
For example when the blue line is at 5v the red is at 12v and when the blue is at 0v the red is also at 0v. All of the values in-between are proportional between the red and blue lines with a gain of 2.4. Can an Op-amp be used to accomplish this?

voltage.tiff (234 KB)

couldnt you change the brightness with PWM though??

(Im confused)

I am interested in this RGB LED Strip from RadioShack.. (as they are always close and everywhere)..

so Im following this thread to see where you end up on communicating/controlling it..

Unfortunately no. That would be too easy. A pwm's max voltage is 5v but the strip needs 12v in order to run properly. I am exploring different options. If the op amp doesn't work I will be attempting to try a digital pot.

I meant cant you just PWM the strip -though- the transistor as mentioned above??

(also...why the op-amp?)