Introduction: Universal High-Power LED Driver With 3D-printable Case

About: I am an electronic artist living in Upstate New York. I work with LEDs, microcontrollers, and analog electronics to create objects that I find beautiful.

*** There's a firmware update. Please check out! ***

LEDs are taking over conventional lighting every day. High-power LEDs over 1W are becoming more and more affordable, and I wanted to start using them to replace the lighting fixtures around me. However I realize that finding and configuring the power supply was a bit of a pain, since I wanted to use different LEDs in different configurations depending on what the lighting was for. Power supply needs to regulate the current that goes though the LEDs. With higher current that high-power LEDs require, active constant current circuit is the only practical option. Commercially available buck regulators are easy to use, however, they are usually made for a specific current and voltage range. For me that means having to purchase variety of buck drivers.

Also, most of LED drivers lack dimming function, or have poorly functioning dimmers. I think dimming is essential for modern lighting, and I want smooth control of brightness.
So I decided to develop a universal, dimmerable high-power LED controller. It has taken me four months to develop this controller. Although it's still in development, I think it's quite useful to all DYI'ers with LED lighting projects.

I made this an Open Source project. Both hardware and software are open - please use, and extend this project and share the knowledge. A 3D printable enclosure as well as couple of LED mounting hardware is also available as Open Source, download-able at Thingverse. Together you can really kick start LED conversion of your household lighting!

Step 1: Features

Here's the list of main features:
  • Inductor "switch mode" controller for high energy efficiency.
  • Wide supply voltage range of 5 to 18V (can go higher, but not tested). Great with batteries as well as AC adapters.
  • Up to 20W maximum output power (can go higher with active cooling). (at supply voltage 12V or above)
  • Constant current (pulsed) - configurable up to 3A peak current.
  • Selectable between buck-boost and boost mode.
  • Analog style dimmer control (smooth, flicker-free continuous adjustment)
  • IR remote receiver - controllable via Sony IR remote control
  • Digitally controlled dimming - via external microcontroller including Arduino.
  • Master/slave gang dimming - connect multiple units together and control the dimming from any one of the units.
  • High frequency pulse drive - 32kHz to 175kHz - no flicker even in video!

Step 2: Technical Overview

This circuit is a relatively straightforward implementation of switch mode voltage converter. An inductor works to convert electric energy into magnetic energy, then it converts back to electric energy. By controlling the charge time you can control the output voltage.
My implementation is a bit different from typical boost or buck-boost circuit in that, instead of rectifying the output voltage, the output voltage drives LEDs directly (pulsed drive). This implementation provides a few advantages:
  • Reduced part count.
  • Higher overall energy efficiency (because rectifier has voltage loss)
  • Better dimming characteristic.

In practice, you can connect 1 to 20 LEDs to the controller. Depending on the supply voltage you can choose between buck-boost or boost mode.

Buck-boost mode can supply output voltage lower and higher than the input voltage. However, efficiency suffers at higher output voltage, so boost mode should be used when you need higher output voltage than input.

Boost mode can only supply output voltage higher than input. As LEDs need minimum voltage (usually about 2V per LED) to start lighting, boost mode is effective when supply voltage is below 2 x (number of LEDs).

More on configuration later...


Peeking into the Output

I think looking at the waveforms will give you the best understanding of how this circuit drives the LEDs. As you can see in the picture, the unit is hooked up to an oscilloscope. Using two inputs, output voltage and the inductor/LED current are shown simultaneously.
The squarish wave is the voltage, and triangular wave is the current.
Notice how at the low power/dimmed level, both the current and the duty rate are low. As you increase the power level, both the current and the duty rate increases. This scheme results in a very wide dimming range with minimum color shift.


Development Notes

Even though I was always fascinated by the way inductors work, designing my own switch mode converter seemed impossible. I somehow managed mostly by trial & error, burning numerous MOSFETs and inductors in the process. I wanted to share what I came up with, so that others can build on top of it, or simply benefit from it.
One important point - if you want to tweak the circuit, you NEED a good oscilloscope. Switching mode circuits like this operate at high frequency, only way to know what's going on is to "see" the waveform. I don't think I could have done this project without one. You don't need a fancy new oscilloscope. Just browse eBay for older models from late 70 - 80's (I paid about $240 for mine). Up till early 80's electronics were built to last. I'd trust equipment from this era more than the latest.

Step 3: Circuit

The heart of this controller is a switch mode voltage converter. L1 converts voltage. Q1 is the switch that control current the goes through L1. The basic principle of switch mode converter is that it controls output voltage or current by controlling the "charge" time of the inductor. Inductor stores the electric energy (current)that comes in, and releases that energy when the incoming current stops. It tries to keep the same current that was flowing when the incoming (or charge) current stopped. So by controlling the charge timing, you can control the output current. (This is a very deep subject and it takes more than this instructable to explain. Please read Wiki for more information on this subject.)

Boost converter on Wiki: http://en.wikipedia.org/wiki/Boost_converter
Buck-boost converter on Wiki: http://en.wikipedia.org/wiki/Buck-boost_converter


As you can see that the diode and a capacitor at the output typical of the switch mode converter is omitted. This is because the load (LEDs) is essentially a diode, and LEDs can perform quite well with pulsed current. By removing the rectifier circuit, the overall power efficiency improves, as well as the dimming range.

This controller supports two different switch modes; buck-boost and boost. Buck-boost mode can output lower or higher voltage than the input supply, while boost mode can only output higher voltage than the input supply. You might ask, so why do we ever need boost mode? Because conversion efficiency improves when input and output voltage are closer. So if you always need higher output voltage than the input, it's best to use boost mode. The mode can be selected by connecting the LEDs to the different output terminals.

Q1 (MOSFET) switches the current flows through the inductor L1. The current then flows through R5, this is the "current sense" resistor which creates voltage that's proportional to the current. This voltage is watched by the microcontroller (via R4) to control the output power that goes into the LEDs. The basic principle is that the comparator inside the microcontroller compares the current sense voltage with the reference voltage. The Q1 is turned off when the current sense voltage is higher than the reference voltage. The microcontroller controls the L1 current by controlling the reference voltage.
(see the Firmware section for details)
For the current sense resistor, I used five 1 ohm resisters in parallel instead of using a single 0.2 ohm resister (five 1 ohm, 0.25W resistors = 0.2 ohm 1.25W resistor). This is usually more economical.

R3 and C5 form a "snubber" to reduce the harmful frequency (ringing) that appears when L1 current is turned off, and protect the MOSFET from it. (http://en.wikipedia.org/wiki/Snubber)

The output voltage is attenuated by R6 and R7 and sent to the microcontroller. This voltage triggers over-voltage shut down, when output voltage goes higher than the MOSFET can withstand (60V). (MOSFETs can easily be destroyed by high voltage.) This situation can happen when the LEDs are disconnected, over-driven, or misconfigured.

Main controller (PIC16F1823) takes the inputs from the driver circuit and control Q1 to achieve desired output. I choose PIC16F1823 as the controller for this project. The key points for choosing this PIC are that it has built in analog comparators, and it runs at 32MHz without needing a crystal.

There's a fuse in the power supply section. In addition to the usual over current (over load) and short circuit protection, this fuse provide reverse voltage protection. If you look at the circuit around MOSFET Q1, reverse voltage will go thorough Q1, as the diode inside the MOSFET is forward biased. The inductor L1 has a very little resistance, so this creates essentially a short circuit condition. Without a fuse, the power supply, MOSFET, or the inductor will be burned. Because of this, the fuse has to be of "fast blow" type.

BOM
5x 1 ohm (R5A-E)
1x 10 ohm (R1)
3x 220 ohm (R8,R9,R10)
4x 1k ohm (R3,R4,R7,R13)
4x 10k ohm (R2,R12,R14,R15)
1x 22k ohm (R6)
1x 47k ohm (R11)
(all resistors are 1/4W carbon film type)
1x 10k ohm Potentiometer (VR1)

1x 2.2nF (2200pF) ceramic capacitor (C5)
6x 0.1uF ceramic capacitor (C2,C3,C4,C6,C7,C9)
1x 10uF/10V electrolytic capacitor (C8)
2x 47-100uF/25V electrolytic capacitor (C1A,C1B)

1x 47-100uH power inductor (L1)

1x 1N4148 diode (D1)
1x LED (D2)

1x MC78L05A or equivalent (IC1)
1x NTD5867NL N-ch MOSFET (Q1)
1x PIC16F1823 microcontroller (PIC1)

1x GP1UX311QS IR receiver (optional) (IC2)

2x Tactile switch (optional) (SW1,SW2)
1x 2A - 3A fuse (fast-blow type recommended)

Step 4: Hardware

I plan to use a controller like this again and again in many projects, so naturally I designed a custom PCB.

I designed the circuit and the PCB to be as universal as possible, including all possible options. For one, you can use either DIP (through hole) or SOIC (SMT) versions of PIC microcontroller. MOSFET and inductor can be chosen from a variety of options as well. Potentiometer and tactile switches can be vertical or right angle types. Controls you don't need such as IR remote receiver, potentiometer and button switches can simply be omitted (though you should have at least one of them to use the controller).

You can design your own, or have them fabricated using the Gerber files provided ("Universal-driver-rev2-gb.zip"). I also have the PCBs and kits available for sale.

Construction
Assembling the controller is quite straightforward. All parts except the inductor are through hole type. The inductor that I chose for this controller is technically surface mount, but because of its size, soldering is very easy with regular soldering iron.

Programming the PIC Microcomputer
You need a PICKit 2 or 3, ICD2, ICD3 or other compatible PIC programmer to program the PIC.
Note: PICKit2 does not support PIC16F1823 (Correction - it does)

Step 5: Firmware

The main function of the firmware is to monitor the brightness control (via VR1, serial port, or IR remote) and control the output. At start, the brightness control via the potentiometer is read via A/D(analog-to-digital) converter and used as initial brightness/dimming level.

Main loop
The controller creates reference voltage V-REF (see "Reference Voltage Generator" circuit of the schematic), which connects to one of the built in comparator's positive input. Current sense voltage C-SENSE is compared against this voltage by the comparator. The microcontroller turns on the Q1 for a quick moment, then see if the inductor current was high enough to "trip" the comparator (which means that L1 current reached or exceeded the desired level). If the comparator did not trip, the "on-time" is increased and the cycle is repeated until the comparator trips. If the comparator trips, then the "on-time" is reduced a bit, then the loop continues. This forms a simple feedback-loop controller. Essentialy the output level is set by the reference voltage.

Reference voltage is created by outputting (software) PWM signal of duty cycle proportional to the desired voltage. The PWM output from the microcontroller is voltage clamped by a diode (to the same scale/level as the current sense voltage), then smoothed by R15 and C8 (RC filter). This reference voltage stays between 0 to 0.6V.

A/D converter is not suitable for reading the inductor current because of the (lack of) speed. Inductor gets short bursts of current, in microsecond intervals. Comparator can respond to a peak current like this, while A/D converter requires the input voltage to be stable while sampling.

The "on-time" signal is generated by the hardware PWM module. It is configured to generate PWM frequency between 32kHz to 175kHz (configurable). The frequency changes according to the dimming level. The lower the brightness the lower the frequency. By changing the frequency, the effective duty cycle of the output also changes. Combining the duty cycle change to the current change via the switch mode converter, much better dimming curve is achieved.

Output over voltage protection
When the output is open (i.e. nothing is connected, bad connection or dead LED) or too many LEDs are connected in serial, the output voltage can get too high for the MOSFET to handle. MOSFET used here can handle up to 60V between Drain and Source. Higher voltage can destroy the device (rather quick smoking death as I experienced a few times during development).
The output voltage is attenuated so that the voltage is safe for the microcontroller (below 5V), then fed to the comparator module. Internal reference voltage is set so that the comparator trips at about 59V (configurable in about 3V steps). The comparator is connected internally via hardware to "shutdown" PWM output when trips. So this output over voltage protection works instantaneously as it should. (Another reason I needed comparators built-in) When the protection kicks in (via hardware), the firmware detects it, and stops the operation, then blinks the status LED. Only power cycling can reset this condition.

Supply Voltage Sense
Supply voltage is read by A/D converter and the value is used to compensate for the output level, so that the output power is consistent over a range of supply voltages. Also, supply over voltage protection kicks in at xxV (configurable in firmware).

IR Receiver
IR remote signal is detected by the sensor and generates interrupts. The signal is decoded by the ISR (interrupt service routine).
You can control the brightness/dimming level, output on and off via the IR remote. When the brightness is changed via IR remote, the potentiometer is disabled until it moves again.
Only Sony remote protocol is supported at this time (of course you can always add other protocols).

Buttons
Button switches are polled about every 4 millisecond and debounced in firmware. Brightness up/down function is implemented for now. (but they can do anything you want)
When the brightness is changed via the buttons, the potentiometer is disabled until it is moved again.
You can also connect external buttons via SPI port for quick & easy remote control. (see the schematic)

Bi-directional Serial/SPI Control
SPI style serial can be used to control this controller. Only brightness/dimming change is supported now. The 8 bit brightness data is sent out via the same port when you move the potentiometer. So if you connect two or more of this controllers via SPI port, all of the controller can be controlled by just moving one of the potentiometers (gang dimming). This comes in handy when you have a bunch of controllers to light a large room.
SPI port and the button switches share the same I/O ports, so the firmware determines the source of the signal by the duration of the pulse. Since humans can only push buttons so fast, pulses that are longer than about 47 microseconds are considered button push, and shorter ones are decoded as SPI signal.
The data format is straightforward - just send the brightness level in 8 bit format. That's it for now - maybe expanded to do other things...

Open Source
You can download the source code as well as the HEX file to program the microcontroller. I'd love to see someone extending my code.

Step 6: LED Configuration/Hookup

The Universal LED Controller can drive high power LEDs up to 20W in total power. (Care needs to be taken when driving more than 10W of power. There will be noticeable amount of heat dissipated from the inductor and MOSFET. Make sure to give good ventilation/cooling so that those parts won't get too hot.)

Please refer to the chart for the configuration of LEDs, supply voltage, and mode selection.

LED configuration chart

Number of LEDs

Supply Voltage

Connection

Mode

Total LED Current (mA)

Parameter (ref_max_duty)

1W LED

3W LED

1W LED

3W LED

1

5

-

Buck-boost

350

700

32

66

2

5 - 10

All Serial

Buck-boost

350

700

32

66

3

5 - 6

All Serial

Boost

350

700

32

66

6 - 15

All Serial

Buck-boost

350

700

32

66

4

5 - 8

All Serial

Boost

350

700

32

66

8 - 18

All Serial

Buck-boost

350

700

32

66

5

6 - 10

All Serial

Boost

350

700

32

66

10 - 18

All Serial

Buck-boost

350

700

32

66

6

5 - 6

3 Serial x2

Boost

700

1400

66

138

6 - 9

3 Serial x2

Buck-boost

700

1400

66

138

9 - 12

All Serial

Boost

350

700

32

66

12 - 18

All Serial

Buck-boost

350

700

32

66

7

9 - 14

All Serial

Boost

350

700

32

66

14 - 18

All Serial

Buck-boost

350

700

32

66

8

5 - 8

4 Serial x2

Boost

700

1400

66

138

8 - 10

4 Serial x2

Buck-boost

700

1400

66

138

10 - 16

All Serial

Boost

350

700

32

66

16 - 18

All Serial

Buck-boost

350

700

32

66

9

12 - 18

All Serial

Boost

350

700

32

66

10

6 - 10

5 Serial x2

Boost

700

1400

66

138

10 - 12

5 Serial x2

Buck-boost

700

1400

66

138

12 - 18

All Serial

Boost

350

700

32

66


For example, if you have 3 LEDs and 12V power supply, you'd use bock-boost mode. In this mode the output voltage can be lower than the input, so the 3 LEDs requiring about 10V as a whole can be driven safely.

If you have 9 LEDs connected in series, and have 12V power supply, you'd use boost mode. This mode boosts the supply voltage, so the 9 LEDs requiring over 29V can be driven.

When you want to connect more than 10 LEDs, you need to combine serial & parallel connection. For example, if you have 12 LEDs, you should connect 6 LEDs in series, then  parallel connect two of the series connected LEDs (strings) with small registers to balance current. These "balancing" resisters are important, and should not be omitted, because each LED has a bit different forward drop voltage, and two strings of 6 LEDs will need slightly different voltage to get the current they need. Without the balancing resister, one of the string will take more current thus overdriven. This condition will lead to premature failure of the LEDs.
You can often "get away" without using balancing resistor. Hook up wires have a bit of resistance to help balance the current. However I still recommend using 5 to 10 ohm resistor in series with each string of LEDs. (The resistor value is a guess at this point, as I can't locate comprehensive formula of calculating the resistance.)

Firmware Parameter

*** There's a firmware update. You can now configure the output current via the two buttons. No need to re-program. ***

*** This step requires a computer and a PIC programmer. I'm in the process of adding "easy setup" to the firmware. Once that's done you won't need to re-program the PIC to change the output current. ***

Once you figure out the LED connections, look up the parameter. Open the source file and look for "ref_max_duty equ xxx". Should be around line 76. This parameter sets the reference voltage that's used to regulate the LED current. The peak output current is about ref_max_duty x11.7 mA. Since this is "peak" not average current, duty rate (ratio between LED on-time and off-time) needs to be taken account. (I'm working on the more comprehensive parameter look up table and/or automated setup. Stay tuned.)

Change this value to the value that you need, reassemble and program the microcontroller.

Your Universal Controller is now ready to drive LEDs.

Step 7: Remote Control

The best thing about using microcontroller is that you can add extra functions without costing nothing. I added IR remote control receiver to Universal LED Driver just by adding an inexpensive IR receiver chip, and a few lines of code in the firmware.
Sony TV protocol is supported by virtually all "universal/programmable" type remote controllers. In case you DO have a Sony TV, and want to control the LED without controlling your TV, alternate device ID can be chosen in the firmware. (Sony uses ID 0 for TV, 4 for VCR, etc.)

You can change the LED brightness using channel up/down button, and mute button to turn off the LEDs. You can assign different buttons to do different things by editing the source code of course.

Here's the Amazon link for the remote I use: http://amzn.com/B001KC08A4

These should also work: http://amzn.com/B000W8JFPGhttp://amzn.com/B00385XUF6

Step 8: Usage Examples With 3D Printed Parts

Custom Enclosure

I've designed 3D printable custom enclosure for this Universal LED Driver. Prints from my printer are not perfect, but good enough to be practical. You can download the enclosure data and print it if you have a 3D printer.


Magnifier Lamp conversion

Here I used 8 of 1W white LEDs to replace the 22W circular florescent tube in the lamp fixture. 8W total output seems as bright as the original florescent. LEDs are connected in series, and the power supply is 12V.
Dimmer is surprisingly handy.

I designed and 3D printed the clips to attach the LEDs to the lampshade. You can download the clips at Thingverse (http://www.thingiverse.com/thing:15263).


Under the Shelf lighting

Here I designed and 3D printed mini-lamp shades to hold 1W star LEDs. These make great economical under the shelf lighting. You can download the lamp shade at Thingverse (http://www.thingiverse.com/thing:15265).
* Due to the (lack of) heat dissipation, only 1W LEDs should be used with this lamp shade. *

Make It Glow Challenge

Participated in the
Make It Glow Challenge