+86 400-003-5559 CN


Control Thy LED | Hackaday

tagscapacitors electronics components

in a

, I discussed LEDs and their characteristics in general. In this article, I want to give some examples of driving LEDs and compare some of the most commonly used methods. There is no “one size fits all” option, but I will try to generalize. The idea is to be able to effectively control the brightness of the LED and extend its life. If you plan to deploy them for a long time, efficient drivers can do everything. Let's look at the problem and then discuss the solution.

Most novices will be interested in making LEDs glow without being blown up. Going a little further down, you can perform brightness control and then color mixing to produce any shadows from the color picker. In any case, there must be a clear understanding of the final application. Lighting applications such as work desk lamps rarely require romantic atmosphere light control. On the contrary, disco lights will require the fluctuating intensity of various colored LEDs.

So how do you perceive brightness? Logically speaking, when you have two 100-lumen LED lights, the result should be twice the brightness. In fact, the human eye is logarithmically sensitive to intensity changes, which means that doubling the intensity will be considered a small change.

The perception of light intensity follows Stevens's power law, and its index depends on the amount of field of view occupied by light. For a 5-degree point, the index is about 0.33, and for a point source, the index is about 0.5. This means that for a 5 degree point, the light source needs to be increased by 8 times to make the brightness appear to be doubled, while the point light source needs to be doubled.


Let's start with a simple 1 W SMD LED, like from

. This product has a rated lumens of 90 lumens and is equipped with an aluminum PCB as a heat sink. Take a quick look at some of the LED parameters.

There are some very important information in the data sheet, starting with the forward current (continuous) and peak forward current. The values ​​are 350 mA and 500 mA, respectively, and should not exceed this value.

Two more important pieces of information are used, and they are represented graphically. The first is the forward current and voltage graph, which shows that a voltage of about 1.8 V is sufficient to forward bias the LED. Thereafter, the current rises in ohms and consumes about 200 mA of current at about 3 V. The second curve is the relationship between the relative current LI and the forward current, indicating that the current controls the light output (extending to the straight line marked "4").

Since LEDs follow Ohm's law, the current should be proportional to the voltage, so we can change the voltage to control the brightness. Well, there is only one small glitch, that is, the curve of the forward current is so steep that a small increase in voltage will have a larger current change. If you connect a button battery instead of two alkaline batteries, the brightness will be different. Both have a potential difference of 3 V, but the amount of current provided by either side is different, so the brightness is also different. Instead of controlling the voltage, it is better to directly control the current flowing through the LED.

The easiest way is to add a potentiometer in series with the LED. simple! Essentially, when you change the resistance, Ohm's law comes into play, and voila! Variable resistance equals variable current equals variable brightness.

This is an analog LED variable resistor whose impedance ranges from 100 ohms to 1 kilowatt. The only problem is that if the resistance of the LED changes or the voltage fluctuates, the result can be catastrophic. This is essentially an open-loop control, in addition to changing the brightness, no other circuit feedback to the user.

Of course, there are also efficiency issues, because potentiometers also consume power.

The easiest method next is to create a constant current circuit. There are many ways to create a simple constant current source. I strongly recommend that you read the book "Electronic Art" carefully for detailed instructions. Not surprisingly, there is a

On this topic.

You can use the classic LM317 variable voltage regulator to provide

. This is not very effective because at higher currents, a lot of heat will be dissipated in the regulating resistor.

A better method is to use a closed loop circuit that provides analog feedback to suppress excessive current and compensate for load changes. The circuit shown is a simple current limiter and is recommended because it has higher efficiency than other transistor circuits.

Its function is to limit the current flowing through R_sense so that the voltage drop flowing does not exceed 0.6V. If this happens, Q2 will be turned on and Q1 will be turned off, which will limit the current flowing through R_load, which in our case will be an LED. Using Ohm's law to adjust R_sense, we can adjust the maximum current of the LED.

I personally prefer the above circuit with Q1 instead of MOSFET, but when we want to digitally control the brightness, the next method will be better.

The next circuit involves using a set of pulses to turn on and off the current through the LED. It's like sliding the power switch quickly, it seems that the lights are dimming. Usually called PWM or pulse width modulation, a series of pulses with variable duty cycle or ON and OFF times can be used for this task.

Under this topic, there are two parts to discuss. The first is a switching source, which can be a simple oscillator or a microcontroller. The second is the switch itself, which will be the driving stage of the design. Let us briefly look at both.

For generating pulses, the humble 555 is a good choice. This circuit shows a simple PWM circuit, where T1 is a switching element.

In order to generate pulses, a low-profile 555 is a good choice. The circuit below shows a simple PWM circuit where T1 is the switching element.

At this point, we have many choices and questions to answer.

1. What is the correct frequency of PWM?

2. How do I know the amount of current provided and

3. How does all this affect brightness?

The frequency of the PWM will affect the flicker. A simple example is that if you use NTSC to record digital video in a 60 Hz lighting environment, the camera will have a lot of flicker, and switching to PAL can be helpful. For PAL, the frequency is 50 Hz, so please try it with a webcam now and check the effect.

The idea is that a higher switching frequency is better, but you cannot increase it arbitrarily. Remember that all LEDs have an on time, which is necessary to turn on and start emitting light. If the switching speed is too fast, the LED indicator will not light up. Another result is that frequency affects the efficiency of switching elements, which we will discuss later. Now, we need to find the best frequency of the LED. Scroll up and view the last item in the data sheet excerpt.

It says 1 KHz, which is recommended by the manufacturer, and in most cases, this information will be provided in the data sheet. If not, any frequency higher than 500 Hz should be used. see this

 Suitable for dimming LED.

Since this technology allows digital control of current (ie brightness), the next step will be to find a way to control brightness. Remember that LI is proportional to current, but the perceived brightness is logarithmic. We need to convert the linear step input into a logarithmic current change.

When using a microcontroller or even an FPGA, the answer is very simple-look up table! Have a list of PWM duty cycles corresponding to a series of brightness values. A good example I have to mention is

, The designer uses FPGA to create a log LUT to generate linear PLI based on user input. The same lookup table can be used with Arduino, I strongly recommend you to try it.

The second item on the menu is the actual switching element. You can use BJT or FET or MOSFET according to your budget and mentality. BJT is a relatively simple creature and hardly needs other components. The 2N2222 can safely handle 800 mA, which is a good choice for many applications.

On the other hand, MOSFETs have higher requirements for components and require more attention during deployment. In exchange, they provide much smaller on-resistance, only a few milliohms, which is more efficient. Let us look at both.

This is the simplest BJT LED driver circuit. It consists of transistors connected in a common emitter configuration. When the input switch is closed, the transistor is turned on, which allows current to flow from the LED to the ground terminal. The resistance is calculated as

r0 = (Va + Vce) / Ic, where Va is the early voltage.

This is not constant, and varies with the operating point of the transistor, and is approximately a few ohms under saturation conditions. A few milliamps of power consumption is trivial, but for larger current consumption, it quickly becomes a problem.

I recommend you to watch the video post of [Dave Jones] on EEVBlog, he is in

. This is suitable for lower power loads, but if you want to drive larger LEDs, you want to add some fairly large heat sinks.

The on-resistance of the MOSFET is very low, only a few milliohms, which means that in this state, according to P = I, it will emit a very small amount of heat


Since these are voltage-driven devices and have high input impedance, we can safely connect some of them in parallel. Unfortunately, they are also prone to false turn-on events, so for switching applications, the circuit must be carefully designed. Provide more detailed instructions

For interested readers, we will continue to introduce the general situation.

I recently purchased two unbranded LED panels from a local hardware store. The seller told me that I should connect them to a 12 V power supply and they will work. When I linked them together and connected to a desktop power supply, I found that at 12 volts, they can draw 2.7 amps of current! The brightness is frightening at close range, and I need to control their brightness.

The next step is to find the most suitable MOSFET. Considering the overshoot during switching, I want to choose a drain-source voltage device of 20 V or even 30 V to ensure safety. As for the current, if I intend to deliver a peak current of about 5 amps, a Res (ON) of 0.1 ohm means 2.5 watts! In this case, the cost of my radiator will greatly affect the final product. Instead, I want the on-resistance to be only 0.01 ohms or less, especially for SMD devices.

Next, I plan to switch the MOSFET with 555 or Arduino. This can be converted to 5 V Vgs, so logic level MOSFETs are preferred. Although I will drive the LED with a 12 volt power supply, I can use a transistor or a dedicated MOSFET driver. Without it, the effective resistance will be higher, but it is still worth a try.

I would also like to see PH2520U and the now obsolete logic level MOSFET MTP3055VL. The MTP3055VL has a relatively high on-resistance and can be turned on at 5.0 volts at the cost of 0.18 ohms and dissipates a lot of power.

IRF530, IRF540, IRFZ44N and AO3400A are all good choices because I have several stocks. Using IRFZ44N, I made a simple LED driver and used Arduino Uno directly. Remember, the Arduino pin goes up to 5V, and I used the gradient example that can directly generate PWM. The frequency of the PWM signal is 490 Hz, which is quite good.

The result is that the panel is effectively dimmed. However, observing the waveform carefully, we find that the output of a single LED panel has a significant rise time.

This is caused by capacitive parasitics and weak current drive, which can be remedied by adding a transistor driver stage. This one

(PDF) Refers to the in-phase bipolar totem pole driver, which illustrates the gate driver circuit well.

By [Joost Yervante Damad]. Since our switching frequency is in the lower range, these switching losses are negligible. If we switch in the kHz range or MHz range, these parasites will soon become the death of the prototype.

In my case, I didn't have the drive stage, but then modified the code for the 75% duty cycle and measured the current consumption with the changing PWM value. It turns out that the peak current it absorbs is slightly shorter than 1A. The MOSFET is not heated to the extent that a heat sink is required, so this circuit can also be used for the LED panel. I can continue to make PCBs for my small lamps, but there is another option I want to see.

The dedicated LED driver chip allows you to effectively control the LED without considering all parameters. TPS92512 is a good example, which allows the use of internally controlled PWM to control high-brightness LEDs. Current control is implemented internally, and external signals including PWM and analog signals can be used to linearly control brightness. No lookup table is required.

I connected the test board with the same LED panel to control the brightness using the IADJ pins. Use a simple preset to change the voltage between 0.8 and 1.8 volts on the desired pin. The output is a clean and effective changing voltage, filtered by the output stage capacitor.

When probing between the inductors, the PWM frequency is approximately 580 kHz. Although no oscillations can be seen on the output LED pins, this means that the filter stage can effectively complete the work. I created a DIY version of the PCB

  (GitHub), you can download to make your own.

There is a small purple OSHPark there, I want to solder it myself. Checking the size of the pins should be an interesting exercise. Let me know if you do it yourself.

So how to drive the LED? The answer lies in your application area. For smaller LED current consumption, BJT is simpler and has the lowest cost. For medium current consumption, MOSFET is a more suitable choice. If you want a solution that provides an out-of-the-box experience, you must use a dedicated driver chip. For me, I want to complete a light, because it can be solved in my test, so I will use the middle way. If I find flickering in the video, the TPS92512 solution will be very convenient. I'm sure you have your own solution, and the best way to share it is to do a project on Hackaday.io. Go on, light up a small lamp with a white light and share your story with us.

The forward current (continuous) and peak forward current values ​​are exchanged.

This is also a name

And musical instruments!

(There is also a typo.)

This and the exchanged vowels have been fixed. Thank you.

But why twice


Or generate pulses, the humble 555 is a good choice. This circuit shows a simple PWM circuit, where T1 is a switching element.


It is safe to say that "voila" only means "seeing there", that is, from "voir" (seeing, seeing) and "la" (not sure if it is like "la bas" means "where" ), still means "she/it", in the female form "le/la")

This will make its meaning similar to "look here [what we have]"

voilà has nothing to do with violence or rape. It is the contraction of voir and là, which literally means "look there!".

This information is located on the same page you linked to-

Recently, I am dealing with microcontroller control of a multi-digit 7-segment display (for clock). Initially, I used a dedicated SPI display driver chip (MAX6951), which can manage segmented current for you, and can also perform character pluralization on numbers. The disadvantage is that it is a very expensive chip. In fact, the cost of upgrading the controller to a faster speed and multi-channel display by itself is about half of the BOM price. Of course, the microcontroller cannot provide or absorb enough current, so an external switch is required. In this case, I found that a pair of chips is an 8x group of high-side and low-side MOSFETs. Unfortunately, the design abandoned charlieplexing, because there is no simple and direct method to make charlieplexing current buffers except for a ton of discrete components, but the upgraded controller also has enough pins to spare, so this It doesn't matter. The last challenge is to limit the current in each segment, but again, there is no good solution other than using 8 discrete current limiters. The second best way is to use a constant voltage power supply, which is slightly higher than the continuous Vf of a segment (because the duty cycle of 8-bit multiplexing is 12.5%). The display power comes from a buck converter, which has good efficiency, and its flexibility is high enough that you can't see any brightness changes for different digital combinations (the 8 next to the 1 means the transition is very challenging).

By using a timer to make a 320 kHz interrupt source, I obtained 4 brightness levels. Four interrupts are used for brightness levels and there are 8 digits, so the result is a raster rate of 10 kHz. This takes about half of the available CPU time, but the rest is more than enough for real applications.

One solution to the problem of segment current control is to use a segment power supply whose output current depends on the number of segments to be illuminated, possibly based on an op amp summing circuit for a constant current source/sink current reference node. Designing a circuit that absorbs or sources N * I (seg) is a relatively simple task, where N is the number of segments illuminated and I (seg) is the current required for each segment. However, if the supply voltage is at least a few volts higher than the LED forward voltage, a series current limiting resistor is usually very useful.

The biggest challenge is to strike a balance between the need for precise supply and the size and cost of the BOM. The disadvantage of choosing constant voltage instead of constant current is that it can only work properly on well-matched LEDs, but in any case, seven-segment displays tend to be well-matched.

In the end, this may be why the MAX6951 is so expensive. A competitive design will also cost a lot. What I am doing is cheaper, but some compromises have been made.

Hello there

"[…]This takes about half of the available CPU time […]"

How do you measure it?

There are several ways. One is by looking at the assembly language of the ISR and estimating how many cycles it takes (I estimate about 50 cycles), and then looking at the ISR frequency (about every 100 instructions).

When I found that the running time of delay() was twice as expected, my math got a little confirmation because it didn't take into account the time it took to handle the interrupt.

Great article. It is worth mentioning (possibly under the PWM section) another option-bit angle modulation or binary code modulation:

Are BAM and BCM the same thing? I have already introduced the latter:

Also want to hear about your use case of BCM instead of PWM. I have always regarded it as a possibility to reduce interrupt frequency overhead.

I think they are the same thing, but I might misunderstand. This is why I used it in the past-to reduce the number of updates required to maintain the proper brightness of the LED for a limited resource system. Although compared with simple PWM, debugging in the "range" is a bit cumbersome, and peripheral devices cannot be used effectively.

"And not effectively using peripherals." This.

No matter what you call it, I am working on the binary version of PWM. Because you have to flip the bits in the code, you run into the limitation of CPU speed as the maximum update rate. The "If" statement took too long, so I ended up adopting a botched approach: when time is abundant, pre-allocate function pointers for each bit, and then run them when the time is up (unconditionally).

But no matter what you do, it is still 4-10 times slower than hardware PWM, just interrupt the b/c of ​​the call overhead.

If the microcontroller is equipped with BAM or pulse density modulation hardware instead of PWM, it would be great from a noise shaping point of view.

If only a few brightness levels are required for each LED, another method I prefer is PDM (Pulse Density Modulation). The basic idea is to load bits into n bit shift registers (where n is # of the required intensity), and its output (carry) is connected to the input (carry) and the LED. This can be easily implemented in software with shift/rotate instructions (my addressable LED project is located at

Use this method).

The advantage is low and constant software overhead, which can be scaled well on a large number of channels, allowing optimal allocation of on/off time to minimize flicker (in fact, the cycle rate may be much lower than similar PWM periods) , And (possibly) avoid some well-known addressable LED patents that explicitly specify PWM. The main disadvantage is that if you need realistic colors, the number of shift register bits (or linked CPU registers/RAM bytes) starts to become ridiculous. 8-bit color requires 256 bits (or 32 RAM bytes/32 CPU instructions per LED update, assuming an 8-bit microcontroller with "carry rotation" or equivalent instructions), so this method The best choice is that the number of brightness steps required for each LED is small, and/or lack of some resources, can not rule out BCM or other more elegant methods (hardware PWM channel, interrupt support (eg PIC10), dedicated timer, DMA Wait).

Just a quick fix-a constant current circuit with two BJTs is actually not better than using LM317, it works almost the same. It is still a basic linear regulator, and all load current flows through the sense resistor and Q1 (generating heat). As the load current increases, the voltage drop across the sensing resistor will increase, and Q2 will disconnect more and reduce the base current of Q1, thereby regulating the load current back. The circuit has no switching operation!

Similarly, there is no benefit to using a MOSFET for Q1 here, because for the correct function of the circuit, it needs to be biased in the linear region and will dissipate a lot of heat. In addition, due to the gate threshold voltage of the FET, it will require a higher voltage.

However, the voltage drop across the sense resistor in the circuit with BJT is only half of that of the LM317 circuit (0.6 vs 1.25 V), so for a given current, the resistor must dissipate half of the heat. In addition, the pressure difference can be lower (0.6 + Vcesat and 2.0-ish).

I came to the same conclusion as Jan. For the same Vcc and load (resistor or diode), for the same required current, in a simple current limiting resistor, the voltage drop across Q1 + R_sense in the above circuit must be equal to R_limit the same. Since P = U * I and U and I are equal, any power loss that no longer occurs in the resistor only occurs in the transistor...

LM317 has a thermal overload function. This is what makes it more useful.

Consider sziklai pair instead of 2xNPN.

Similarly, "Given that LEDs follow Ohm's law" may need to be checked.

Use PWM LED for brightness control because the color temperature of LED will change with constant but analog brightness control. This defeats the purpose of buying LEDs classified by color and wavelength.

It is a safe idea to reconsider passing 800mA current through 2N2222. It depends on the package, heat sink and ambient operating temperature.

The reason why you can connect MOSFETs in parallel is not because of their high input impedance, but because of the PTC effect of the rdsOn characteristic, and the resistance increases linearly with temperature. This is how their servo distributes the current evenly.

Did you forget to check the silk screen layer on this PCB? : P

PWM is harmful to emission-have you seen the magic sine wave?

At such a low frequency (<1kHz), it is easy to add some RC or LC filtering on the PWM output to keep the radio in a satisfactory state.

Please pagination!

This one!

When PWM is not good enough:

It is worth pointing out that the first-order Sigma-Delta is equivalent to pulse [density/frequency] modulation.

One time I tried to use second-order ΣΔ for optics did not seem to work...I might be missing something.

This is a great article and rarely gathers a lot of information in one place. Links are also a large part of it; for example, "Old-fashioned LED bicycle lights using 1W white LEDs" on the Ladyada website.

well done! thank you very much! Don't stop!

(You need to add the opening word "


You can drive the MOSFET gate from 12 V, just add another driver transistor between the MOSFET and the Arduino. You will get a lower Rds(on) and therefore less heat.

Or use logic level mosfet like ordinary people in 2017

They usually have a higher Rds(on) than conventional MOSFETs with 12 V on the gate.

It does not matter when the SO-8 package can pass 5A or even not preheat

If you used bicycle lights in the linked article and have a generator for bicycle headlights, the conversion couldn't be easier. The diode bridge and cover of the generator directly drive the LED! This is for 350mA LED. Due to the complete lack of protection in the German standard, most generators in the world output about 300mA in 6v. The generator can produce full-speed steps, magnetic current limitation and skidding.

For lookup tables, this handy dandy python script works well for me

Great. This is my point of view, but with adjustable gamma and lower code readability! :)

It is part of this article about getting gamma and hue correctly:

The luminous efficiency of LEDs depends on the junction temperature, which has been standardized as 25°C by the industry. In any application, this temperature will not exceed one tenth of a second, so each LED will be derated in actual use. More honest suppliers will provide derating curves for different currents and ambient temperatures, other suppliers will not mention it.

guard against. The reality is much worse than the data sheet suggests.

I also suspect that there are big differences between the different parts of the LED (although the part numbers are the same).

They have done so, and they should be sorted in factories to find the difference, but since you may have purchased LEDs from China, they are likely to use substandard parts to dilute the more popular bins. Because they can get rid of.

Another difficulty is that LEDs of different colors will change with temperature. Please note that if your ambient temperature is 25 C, the junction temperature will be 60-70 C even if a proper heat sink is connected, unless your diode power is very low.

The "white" here is a blue diode with yellow phosphor.

The article said: "...a small increase in voltage will lead to a larger change in voltage...", I think it should be said "...a small increase in voltage will lead to a larger change in current...".

It looks like a good article (not finished yet), but this part confuses me:

"Well, there is only a small obstacle. The curve of forward current is so steep that a small voltage increase will produce a larger voltage change."

I think it should be displayed as "a small increase in voltage will make a larger change in *current*"

Thank you! absolute. fixed.

>The cost of the heat sink will greatly affect my final product...I plan to use Arduino to switch the MOSFET

The cost of the radiator is the same as the arduino; /

If it is a microcontroller-based project, you can also get the ws2811 chip from your favorite supplier, connect any led and use it as a three-channel pwm controller...

This may cause misunderstanding: "LED has the turn-on time required to turn on and turn on the light."

I don't have a phone, but Leds is already super fast! They turn on and off almost immediately, and I will enter the megahertz range without hesitation!

However, the speed of fluorescent materials is very slow, so for white LEDs, you will not get too much light from a 100ns pulse. For dimming, this is not a problem...

Then, the measurement of light pulse is a challenge in itself.

Oh-Layz doesn't actually "light up" :-)

The circuit diagram under "Design Lamp" has very poor current regulation. This particular LED may be able to handle an unregulated 12V power supply without burning, but PWM alone cannot regulate the current. When the LED heats up, its forward voltage will drop, it will conduct more current and generate more heat.

For high-power LEDs, limiting current and heat dissipation during continuous use should be the primary design considerations. You can add a dimming function to this, but it cannot replace the current regulations.

I have been considering using the PT4115 chip to drive mid-power LEDs (rated current up to 1.2A). It does not require many external components, has a small footprint, is efficient, and costs less than 10c per piece in a small batch. It is still worth understanding the above circuit when using the driver chip (except for the circuit I mentioned above, I think this is wrong, but maybe someone can tell me what I am missing?).

In the current control part, I don't have anything, only 2 transistors: Isn't it linear like LM317? In other words, is it not as efficient as LM317 when there are a lot of dropouts? Anything surplus can be used to turn on Q2 to increase the transresistance of Q1, so conceptually, its dissipation is the same as LM317. Am i right?

Also current limiting diodes. For example, 20mA CLD20B or NSI45020A. It is reminiscent of the old JFET current limiter

Please be kind and respectful to help make the comment section great. (


The site uses Akismet to reduce spam.

By using our website and services, you expressly agree to our placement of performance, functionality and advertising cookies.