dimming 12 V RGB LED strip using processing

hey guys,
i posted a similar post regarding 12 V RGB led strip regarding a confusion about which mosfet to use, but i was also wondering if i could control use processing to control the input voltage supply in order to dim the lights?

I want the color to remain the same, but i would like the lights in general to go dim.

ive come across a couple of projects where people used potentiometers, but what if i want to control this voltage regulation, what component must i use? would a transistor do the job? how do i control it using processing??

attaching a pik of the circuit connections. ( only difference is i have used 1 K resistors & external 12 v adapter ). Also attaching my current arduino code ( which changes the light color )

Thanks! & please help! :slight_smile:

#include <Servo.h>

Servo myservo;

char val; // Data received from the serial port
int greenPin = 11;
int redPin = 10;
int bluePin = 9;

 void setup() {
   Serial.begin(9600); // Start serial communication at 9600 bps
   pinMode(greenPin, OUTPUT); // Set pin as OUTPUT
   pinMode(redPin, OUTPUT);
   pinMode(bluePin, OUTPUT);
   myservo.attach(8);  // attaches the servo on pin 8 to the ser
   analogWrite(redPin, 255);
   analogWrite(greenPin, 220);
   analogWrite(bluePin, 0);
 void loop() {
   if (Serial.available() > 0){ // If data is available to read,
     val = Serial.read(); // read it and store it in val
     if (val == '0') { // change color to BLUE
       analogWrite(redPin, 0);  
       analogWrite(greenPin, 0);  
       analogWrite(bluePin, 255);  
       myservo.write(180); // 
       delay(1000); // turn servo back and forth 180 degrees, ONCE
       myservo.write(0); // 
     else if ( val == '1') { // change color to RED 
       analogWrite(redPin, 255);
       analogWrite(greenPin, 220);
       analogWrite(bluePin, 0);
     else if ( val == '2'){ // change color to GREEN
       analogWrite(redPin, 0);
       analogWrite(greenPin, 255);
       analogWrite(bluePin, 0);

Just use the same technique on the power rail as you do with the LEDs. That is feed a PWM signal to a transistor switching 12V. Then smooth it, and apply it to the strip's power supply.

It is bad form to edit the first post after someone has replied. I assume you did not understand the reply otherwise you would have made a comment on it. Again it is bad form to ignore someone who has replied.

What you need is the circuit attached to give a variable voltage to your LED strip.

Strip power.jpg

so sorry mike! i didnt see your first reply! hence i edited my post to try and be more specific! my bad..

so from the image i understand the 22 k resistor wire is going to the PWM input on arduino?

Also, both BC846B & 2SK3065 are transistors right? in which case the emitter of 2SK3065 is going to ground?

thanks. sorry again :smiley:

ok just got it ! so the final wire will supply voltage to my led strip circuit!

thank you

I don't understand why an extra pwm output and transistor are needed for this. Why not achieve overall dimming in software?

All that is needed is to reduce the pwm duty cycle in the r, g& b channels by the same proportion. This maintains the same colour.

silvergravel, in your original question you mentioned "processing". Did you mean using a program written in the Processing language, running on a PC, or did you mean by extra code in the Arduino sketch?


well, i guess that wouldnt happen because there are R G B inputs right ? changing those values would probably jus change the color..

No. Read my reply again...

Why not achieve overall dimming in software?

Because the PWM from the over power will beat with the PWM of the individual colours.

Yes, I wouldn't be surprised if it did, Mike. But why use pwm to switch the power rail or vary the voltage to dim the strip in the first place? If the OP just wants to control the colour and dim the leds without changing the colour. I would have said that can be done in S/W without any H/W changes. What am I missing here?

I would have said that can be done in S/W without any H/W changes.

Ah, I see what you mean - sorry. Yes you could just tweak all the PWM values down to achieve the dimming.
Although you are only working with 8 bit values and a none linear response.

I was a bit tied up with answering the OP's original question about reducing the drive voltage.

OP's original question about reducing the drive voltage.

@mike: Another case of asking for help with A when what they really want to achieve is B?

@silvergravel: Mike and I agree that you can dim your strip without changing the colour, without any extra transistors, just the circuit you have now.

@paul: by processing i meant the software processing ( is that the right thing to call it ? ). On processing, based on a string input either a video or an audio plays. when the audio plays, i need the RGB led strip to be bright. when the video plays, i need it to dim out.

now honestly paul, its great news that i can achieve the dimming without any extra hardware, but all this stuff that you guys are saying is going over my head :frowning:

could you elaborate on what you mean by tweaking the pwm values down?

for example when i need a blue light, i am using the following code -

if (val == '0') { // change color to BLUE
       analogWrite(redPin, 0);  
       analogWrite(greenPin, 0);  
       analogWrite(bluePin, 255);

now if i want to dim out this same light then what must i do??

thanks a lot guys..

Easy. In this line of code here:

analogWrite(bluePin, 255);

the 255 value is maximum brightness on the blue channel. The AnalogWrite() function is misnamed in many people's opinions. No analog voltage is actually produced. Instead, a 5V square wave is produced with a frequency of around 500Hz. What varies is the % of the time that the square wave is 5V vs. 0V. This is called the Duty Cycle and 255 corresponds to 100% of the time at 5V. 128 is 50% of time at 5V and 50% at 0V.

ok great! thanks for all this info. it really helps to know the technicalities behind all this :slight_smile:

so just one last question,

im going to take a few steps behind back to the circuit diagram that i have posted. So i have been reading a bunch of posts regarding applying an external power supply ( mostly for servo motors ) , and many people have mentioned that the ground wire, ( in this case, the one coming out of the emitter of the mosfet ) must be connected to the GND of the power supply as well as GND of arduino.

does that hold true in this case of RGB led strip as well? i dunno... does that give stability to the circuit or something..?

It holds true for all electronics this link tells you why

Okay! thanks mike.

Yes, your grounds should all be connected.

PS. That pin is called the Drain on a fet (field effect transistor). The term Emitter applies to bjt (bipolar junction transistor).

thanks paul. i looked up the difference between field effect & bipolar.. too complicated for me to grasp as yet :smiley: