Ways to adjust LED brightness

Hello,

I want to adjust the brightness of an LED and I have some questions.

  1. Does the PWM function adjust brightness by turning the LED on and off like in the image below and thus tricking the eye and the brain that the LED is continuously turned ON ?
    https://www.arduino.cc/en/uploads/Tutorial/pwm.gif

If the answer to question 1) is yes, is there a way to adjust the brightness by adjusting the voltage in 1-10mV increments and thus keeping the LED ON at all times to avoid the flickering?

  1. yes
  2. connect the led to a DAC which has a continuous voltage

Thank you for the reply. I can't seem to find any info on Digital to Analog converter pins for the Arduino Pro Mini 5V. I found for the Due and Zero.

Does anyone know if the Pro Mini has such pins?

The pro mini does not have a DAC.

Afaik all 8-bit arduinos lack a DAC. You can always add a DAC-IC though.

The trick with analogwrite / PWM is indeed as on the link you gave. If your visual cortex is faster as the frequency that analogwrite uses, you'll indeed notice flickering. I don't notice any, so perhaps I've got a slow brain :slight_smile:

Any way, besides dimming a led by changing its voltage to avoid flickering, you can also increase the frequency PWM uses. Once you feed a fast brain more frames/sec as it can handle, the flickering should be gone again.

https://arduino-info.wikispaces.com/Arduino-PWM-Frequency

Most DAC circuits output a voltage. That would not vary the brightness of a LED correctly because they are current driven devices. So you need a DAC with current output, or a conversion circuit to drive the LED.

LED's use current, not voltage.
LED's are not linear, or rather the emitted light from 1ma is not proportional to the emitted light at 10mA.

What you want may not be what you are asking for. we call this an XY problem.
What you are asking for is a variable voltage, but that will not work.
what you think you are searching for is an adjustable current source. to vary the current, you can vary the output of an LED.

to vary the voltage, you are attempting to alter one side of OHM's law, and relying on the selection of the resistor to deliver the changing current needed to change power in the LED to effect a change in output.

since this is not the correct approach, you are having a very difficult time finding it. kinda like looking for a 5 wheel car to have a softer ride when you should be looking at shock absorbers.

there are lots of LED driver chips from all the name brand suppliers, TI, fairchild, OM, you name it.

that said, most LED data sheets offer that you can pulse and LED about 2.5 times more power than you can deliver continuous.

as you mentioned, POV or persistence of vision, means your perception of the brightness of the light is based on it's highest value. so pulsing a light with much higher power, but for a brief time, will deliver a much higher perceived light.
go into a dark room with a cigarette lighter and flick the flint. you can see what is in the room from the very bright light.
any of the chips that can do lots and lots of LED's with independent brightness control, rely on the POV effect and by delivering a higher power pulse, they conserve time so they can do more LED's.

but this also means that a constant power LED will have to be powered to the specs on the data sheet or it will overheat.

Since you appear to have an XY problem, would you offer why you do not want to use the industry standard and universally accepted method of lighting LED's ?

TV refresh times are 60 hz movie frame rates are about 72hz. new HD TV's claim 120hz and even 240hz.
in comparison, the PWM output of a 16mhz Atmel 328 chip as used in the Arduino's is about 976hz .
the pulse is not perfect, but at those speeds, few things have the ability to notice.
you can wave correct the pulse stream to get a more uniform pulse and that consumes clock cycles, you might drop to 694hz or 347hz..... still 10 times faster than a TV set.

don't confuse the plasma TV pulse of 600hz to charge the screen with the 60hz refresh rate for the picture. it uses the POV to charge the individual pixel at a pulse of 600hz, but only changes the value at 60hz.

Please enlighten us why you want to drive an LED at a constant power.

Thank you all for the detailed answers.

I want to measure brief flashes of light on the order of thousands of a second at a certain level of brightness. Think of a shutter tester. I read that the arduino can take up to 10000 samples per second, depending on the code and hardware. I haven't done any testing but I worry that when I will read a sample the results might be influenced by the on/off behavior of the LED. For example, If I take a 0.0001 sample I worry that the LED will be turned OFF when taking the sample.

Would something like a digital potentiometer work? I never used one. Does it work like a passive one that is turned by hand and the digital one is "turned" by the arduino?

How many different brightnesses? If it's only a handful, connect several different resistors to different Arduino output pins. Then they all go to the resistor, then to ground. By switching different outputs on (and sometimes multiple outputs) you can get a lot of different brightnesses, for all the different combinations of resistors. 4 Arduino pins will give you 8 brightness levels. 5 pins 16 levels and so on.

I guess you could use a digital pot, in single-ended mode. You might find it difficult to find one with an appropriate current rating. I just had a look at my favourite supplier and I could not find one with an appropriate resistance range (1k) with more than 4.4mA current. You need 20-40mA maximum for the pot.

I would like as many brightness levels as I can get.

Does the MCP40D18 have 128 steps and can it support up to 25mA?

If the answer is yes, maybe I could use a 5 kOhm one and only use the values relevant to me from those 128.

If something like the MCP40D18 won't work would something like shift registers used for 7 segment displays work? Instead of an LED segment, enable a resistor.

MorganS:
How many different brightnesses? If it's only a handful, connect several different resistors to different Arduino output pins. Then they all go to the resistor, then to ground. By switching different outputs on (and sometimes multiple outputs) you can get a lot of different brightnesses, for all the different combinations of resistors. 4 Arduino pins will give you 8 brightness levels. 5 pins 16 levels and so on.

I guess you could use a digital pot, in single-ended mode. You might find it difficult to find one with an appropriate current rating. I just had a look at my favourite supplier and I could not find one with an appropriate resistance range (1k) with more than 4.4mA current. You need 20-40mA maximum for the pot.

I think 16-20 levels might be enough for me if I choose the resistors that I need and if I can group them. I did not quite understand how to do what you mentioned. Could you give some more details on how I could control 16 resistors with 5 pins? For example, can I activate a 100 ohm resistor and a 15 ohm resistor to give 115 ohms? How did you do the math that gives 16 levels for 5 pins?

use a stepper or servo.
connect it to a pot.
you can get a nice 5k pot rated for 50ma or more

can you use a digital pot on the base of a transistor and use the transistor in the linear range ?

I would like to avoid using motors and other complex mechanical setups.

I just thought of another setup. To have the resistors in series and a switch in parallel for each resistor. If I could find a way of switching each switch individually without using 16 pins I could select what resistors I want to use.
It would be great if I could find an IC that is not too big or too expensive and has at least 4 switches that can be controlled by an arduino pin. I don't know if there are parts like this.

I made a quick drawing to explain what I said:
http://postimg.org/image/ygyx0llnt/

Or just use an RC filter on the PWM or even a second order RC if required.

Mark

holmes4:
Or just use an RC filter on the PWM or even a second order RC if required.

Mark

Something like this?

Will it give a smooth voltage value? The Steady state voltage line in the graph looks thick and fuzzy. Like it has a tiny oscillation between 2 values. Would this cause flickering?

numlo:
I think 16-20 levels might be enough for me if I choose the resistors that I need and if I can group them. I did not quite understand how to do what you mentioned. Could you give some more details on how I could control 16 resistors with 5 pins? For example, can I activate a 100 ohm resistor and a 15 ohm resistor to give 115 ohms? How did you do the math that gives 16 levels for 5 pins?

I think several pins providing different LED currents could be a good solution.
4 pins and 4 resistors/diodes could give you 15 levels.
5 pins and 5 resistors/diodes gives you 31 levels (2^5=32, but one is "off").
One pin could provide 1mA, a second pin 2mA, a third pin 4mA, a fourth pin 8mA, and a fifth pin 16mA.
1-31mA in 1mA steps.

What sort of LED do you want to drive.
100ohm and 15ohm suggest a high current LED. Something an Arduino pin can't handle.
External transistors could be used.
Leo..

Now I understand the theory behind that suggestion. Thank you! What is the name of this method? Are there any good tutorials for it?

The LED would be similar to this one:
http://www.luckylight.cn/UploadFiles/LL-304WC4B-W2-3PD.pdf

Yes. If you don't like the little bit of roughness then add a second such filter.

Mark

R-2R ladder.
Just a small 3.3volt/20mA LED.
You could drive this directly from 4 or 5 Arduino pins.
You also need a diode "OR-port" so pins don't influence each other. e.g. 1N4004.
That leaves ~2volt for the current limiting resistor.
Use ohms law to calculate 10mA, 5mA, 2,5mA, 1.25mA etc.
Assume ~25ohm output pin impedance.
Leo..

Well actually it would take even fewer pins. The outputs can be tri-stated, which means on,off or floating. Then you can have the resistors set up like voltage dividers and some pins can be used to subtract current from the LED.

An RC filter is also a good idea and once you have checked that it is filtering properly then the maths with the different resistors is avoided.