Constant current LED driver with arduino pwm

Hi to all,

I did my first project LED fading by using this guidance;
http://arduino.cc/en/Tutorial/Fade

Now what I want to do is, I want to make constant current led driver, but also I want to be able to set it's brightness by my arduino, (maybe i will make it fade too)
for example if i set my pwm to 50 with arduino (which is quite low brightness), with the help of my constant current led driver, I want my LED (I will use 1 W power LED) to give same (50 pwm) brightness regardless of input voltage.

I found this guidance on internet which is exactly what i look for, he uses NPN transistor and Nchannel FET to make constant current, there is circuit diagram and values in there too.
http://www.instructables.com/id/Power-LED-s---simplest-light-with-constant-current/

So Here I have 2 different projects, but I do not know how to combine them together.
How can I combine this costant current led circuit with my arduino to set its pwm?? Is there any way to do it?
I think I have to feed my circuit from 2 different source 1 for my arduino (in order to protect it from high current) and one for LED driver.But I dont really know how to control that transistors with my Arduino.

Thanks in advance.
And if anything is unclear please let me know so I will try clarify.

A gate for your current source.

The original circuit has 100k for R1. I say, use something lower – 10k, maybe less.

A 2N7000 would be even better for R3, but the NPN should suffice.

gatedcurrentsource.JPG

THANKS a lot for the answer!
The circuit scheme is very clear, but can you tell me how it's working? As I know with the pwm I am changing the voltage level.So for pwm=255 there will be 5 V between the pwm and the ground which is connected to my base of Q3. But how is that affects
my LED's brightness and makes it maximum (for pwm=255)? I mean how the voltage change in base of Q3 can determine LED brightness? I will be very glad if you tell me more about how this circuit is working.

Also I think that I'll connect the digital pwm to pwm in the circuit and i will connect the ground of arduino in to - in the circuit is that true?
Can I use the same coding program as I used in LED fading?(that varies the voltage between 0 and 5 V)

I will feed my circuit with 9V 1 Ampere (from adapter) and i will feed my arduino seperately from it's USB cable. So since I will have higher current how can I decide the the watts and resistance of the equipments i will use? and how can I determine that between how many volts can my circuit keep the same ampere for my led?

Sorry for my ignorance and thank you for your interest.

Best wishes.

Note: Any reading material related is welcomed.

With that circuit, when pwm = 255 then the LED is full off and when pwm = 0 then the LED is full on.
When Q3 is On, whenever its base is forward biased, then its collector goes to Gnd -- which takes the FET's gate to Gnd (which turns it off).

Yes, link the Grounds (Arduino Gnd to external supply Gnd.)

Of note, whenever the LED circuit is connected to 9V and the Arduino is not powered (off) then the LED will be full on.

Thank you very much again, I am planning to buy the equipments and make the circuit tomorrow. So, I can use the same code as I did for fading the LED but this time pwm=255 means led is off and pwm=0 is led is on(brightest).

As far as I know, the R3 sets my current value, I am gonna use only one 1 Watt power led. And Lets say I want to set it's current to 225mA.
My voltage source is 9 V 1 A DC. How can I calculate the resistance of my R3 ?
Also for other resistances( I will use 10 k for R1 as you said and i will use 1 k and 10k as you draw in the scheme will they work fine on 9 V 1 A?)also will 0.25W resistors is enough? and how can I determine the highest and lowest voltage levels that my circuit will work?

Thank you very much again

Best wishes!

Your R3 is “independent” of V_supply, for the most part. Like the instructables author noted, current ? 0.5V / R3.

This article explains the circuit thoroughly

Are you trying to ask how big a supply you can use?
The LED and the FET and R3 should be seen as a series circuit.
Provided the LED is within its range, the voltage across it is sort of self-regulating and the voltage across R3 will “always” be about 0.5V.
So, those are two “fixed” figures, V_LED (whatever that is) and 0.5V.
The only thing left to worry about is the FET’s R_DS(on) figure.
What share of V_supply is not across the LED or R3 will be across the FET,
so its power dissipation (W) ? (V_supply ? V_LED ? V_R3) / R_DS.

Start small, don’t get carried away, and progress.

I suggest 1/2W resistors.

Added parentheses to PD equation

I finished my project and I wanted to put it's final photo in order to THANK Runaway Pancake.
I couldn't have done this project without you.
THANK YOU VERY MUCH.
I hope this pictures will also be helpful for someone who wants to do that in the future.

Warm regards.

(sorry for the slipper in the picture I noticed it just now :slight_smile: )

Good deal.

Here's a little something with a cool effect for that -

const int transistorPin = 9;  // change to Your pwm pin of choice
int x;   
void setup()
{
  pinMode(transistorPin, OUTPUT); 
}

void loop()
{
  x = 1;     // x = { 1,2,...15}
  float val = (exp(sin(millis()/1500.0*x*PI)) - 0.36787944)*108.0;//the function of breathing led
  val = 255 - val;      //  val 'inverted'
  analogWrite(transistorPin, val);
}