# Programmable Current Source

#### Alexandru Chiser

Joined Feb 16, 2017
44
Hello there. Im new here and i was wondering if i can get some help.

I want to make a programmable current source, so i can control the current through a LED. The current will be controlled with an Arduino (via Arduino ID). Until now i have this in my mind:

The Arduino will generate a PWM that will be filtered with a low pass filter. The voltage resulted will be added at the PLUS terminal of an OP-AMP that controls the gate of a N-MOSFET transistor. The schematic that i think it works, of the op-amp and the transistor, is this one:

The current through the LED should be between 10mA and 100mA (add or give). The problem i encounter is what op-amp should i use, what nmosfet transistor (probably one with a low Id current), what should VDD be...

Feel free to come with ideas (simple ones), and provide me info to understand them. I'll try my best to understand them asap, and come with questions if there are any problems.

Thanks guys!

#### dl324

Joined Mar 30, 2015
9,151
Welcome to AAC!

Why not just use PWM to control LED brightness? With PWM, you can drive the LED at a higher peak current as long as you have safeguards to prevent average current from exceeding the maximum the LED allows.

#### joeyd999

Joined Jun 6, 2011
4,271
Welcome to AAC!

Why not just use PWM to control LED brightness? With PWM, you can drive the LED at a higher peak current as long as you have safeguards to prevent average current from exceeding the maximum the LED allows.
Perhaps he is concerned about constant brightness vs. Vdd?

Even in that case, though, I'd do it via the PWM.

#### Alexandru Chiser

Joined Feb 16, 2017
44
Yes, constant brightness matters! This is a project im working on, and the "boss" told me to create a circuit that drives a LED using a transistor and the current will be controlled with the Arduino. Where should i start from?!

#### crutschow

Joined Mar 14, 2008
23,532
i encounter is what op-amp should i use, what nmosfet transistor (probably one with a low Id current), what should VDD be...
I would also suggest using PMW to directly drive the MOSFET.

If not, a cheap, single-supply op amp, such as the LM324/LM358 (not a 741) should work fine.

The N-MOSFET can be just about any device with a maximum Vgs(th) threshold voltage of no more than 3V.

Vdd needs to slightly greater than the LED forward voltage drop plus the voltage drop across Rs at the maximum LED current.

#### crutschow

Joined Mar 14, 2008
23,532
Yes, constant brightness matters!
What will the LED light be used for?

#### Alexandru Chiser

Joined Feb 16, 2017
44
This project refers to automotive clusters that have lots of LEDs. At the end of the project, this "gadget" will be able to control the current through arround 50-60 LEDs. For now i need to make a circuit that is able to control 10 currents through 10 LEDs.

What should be the power supply for the LM358? 5V? And the VDD also 5V, cus the LEDs need arround 3V to light up.

#### joeyd999

Joined Jun 6, 2011
4,271
This project refers to automotive clusters that have lots of LEDs. At the end of the project, this "gadget" will be able to control the current through arround 50-60 LEDs. For now i need to make a circuit that is able to control 10 currents through 10 LEDs.

What should be the power supply for the LM358? 5V? And the VDD also 5V, cus the LEDs need arround 3V to light up.
You need a switching LED driver. For example:

http://www.linear.com/product/LT3518

#### crutschow

Joined Mar 14, 2008
23,532
This project refers to automotive clusters.....

What should be the power supply for the LM358? 5V? And the VDD also 5V, cus the LEDs need arround 3V to light up.
You can operate everything from the 12V vehicle battery.

If you are controlling more than 1 LED, you can put several in series, until their total voltage approaches 12V, (3 or 4 in this case) which improves efficiency.

#### Alexandru Chiser

Joined Feb 16, 2017
44
Lets summarize only for one LED. A nmosfet thats either driven directly by PWM, either using the op-amp, a VDD of 5V, and thats all... This schematic should be able to change the current through the LED by changing the PWM, right?

#### OBW0549

Joined Mar 2, 2015
3,027
Note that if you go with the design you showed at the beginning of this thread, your value for Rs is way off; 10Ω would be more like it, and would give 0 - 100 mA out for 0 - 1 volt in.

#12

#### crutschow

Joined Mar 14, 2008
23,532
A nmosfet thats either driven directly by PWM, either using the op-amp, a VDD of 5V, and thats all.
If you drive the MOSFET gate directly with the PWM signal, then you need to put the limiting resistor in series with the LED in the MOSFET's drain and connect the source to ground.
For 100mA max. the series resistor should be about 20Ω.

#### Alexandru Chiser

Joined Feb 16, 2017
44

Ive found a nmosfet transistor with a 2.8V treshold. With a 40ohm resistor in series with the LED, that maximum current is 121mA. Now let me show you some values:

Gate Voltage: 2.7V -> Current: 11.25 uA (its good, cus its treshold is 2.8, so its still closed)
Gate Voltage: 2.9V -> Current: 8 mA
Gate Voltage: 3.0V -> Current: 45 mA
Gate Voltage: 3.1V -> Current: 114 mA
Gate Voltage: 3.2V -> Current: 118 mA
Gate Voltage: 3.5V -> Current: 120 mA
Gate Voltage: 4.0V -> Current: 121 mA

From what i see, the current jumps from 0mA to arround 110mA really fast (the voltage jumps only 0.2V to have that current value of 110mA), but from 110mA to 121mA, you need to increase the voltage significantly (from 3.1 up to 3.7 or something like that).

Is there anyway to make this change linear? I think it logarithmic now...

BTW: if i have mistakes in expressing electrical terms, tell me!

#### Alexandru Chiser

Joined Feb 16, 2017
44
Any suggestions?

#### Alexandru Chiser

Joined Feb 16, 2017
44
I think i can solve this using a PWM with a big resolution. I see that Arduino has a Timer 1 with 16bit resolution, the step would be 0.000076V. That would allow me to increase the voltage in the gate of transistor with a lot of precision.

#### crutschow

Joined Mar 14, 2008
23,532
Yes, you can't use a DC voltage with that post #13 circuit.
It has to be PWM pulses with a varying duty-cycle.

#### Alexandru Chiser

Joined Feb 16, 2017
44
Yes, you can't use a DC voltage with that post #13 circuit.
It has to be PWM pulses with a varying duty-cycle.
It seems that using a bigger resolution for the PWM is the best result. This way i can achieve all kind of voltages, with that step i told you earlier (0.000076V). Given that i need 10 LEDs, and 10 PWM, i searched on google a lil bit and i found a board just like arduino, named TEENSY. This board provides 20 PWM.

These days im out of my hometown, but monday ill get back. Then ill start gathering the parts: transistors (2N7002), LEDs, resistors, capacitors, the Teensy board, and other parts.

One last question untill monday/tuesday. About the low pass filter, what values should the resistor/capacitor have? 1kohm with 1uF?

#### crutschow

Joined Mar 14, 2008
23,532
About the low pass filter, what values should the resistor/capacitor have? 1kohm with 1uF?
You don't use a low pass filter.
You directly drive the MOSFET with the PWM digital signal.

#### Alexandru Chiser

Joined Feb 16, 2017
44
You don't use a low pass filter.
You directly drive the MOSFET with the PWM digital signal.