An LED lighting project with slow fade-in effect and two switchable lighting levels.

## LED Fader for Home Lighting Applications

LED lighting is all the rage these days. With prices falling rapidly and efficiency increasing, LEDs are becoming an attractive choice for home lighting projects. Though LED light-bulb replacements are increasingly common, there is still room for the enterprising hobbyist building high-quality LED lighting systems based on discrete components. This is the avenue I took in this project. Besides building a light strip with high-efficiency Cree XM-L power LEDs, I also built a fading-in effect using a small PIC micro-controller with two selectable light levels.

## Hardware - The Light String and Power Supply

Since l had access to several laptop PC power supplies that were otherwise headed for recycling, I decided to use one of them in this project. Laptop AC adapters are generally switch-mode power supplies with good efficiency. That plus the fact that they output an 18 to 20V voltage (depending on model) and can source more than 3A, makes them good choices for driving multiple LEDs in series while keeping losses low. The Dell notebook supply I used outputs 19.5V. The key is to keep the total voltage drop across the LEDs near the output voltage of the supply to minimize losses across the series limiting resistor (See Figure 1). With the arrangement below, I measured about 1.7A through the string which is well within the Cree XM-L capability (with adequate heat-sink). The voltage drop through each Cree LED for I = 1.7A is about 3.1V. Therefore, the total efficiency of the string (setting aside losses in the AC-adapter) is :

Eff = Po/Pi = 1.7*(6*3.1)/(19.5 *1.7) = 95 %

This is a pretty respectable value. Of course, since this is an "open-loop" design (i.e., not a current source with feedback, etc), some experimentation is needed for a given particular application to find an optimum current limiting resistor value.

The more traditional way of driving power LEDs is to use a current source arrangement. This is not very difficult to do (I actually experimented with this approach before settling on the simple/obvious series resistance solution). However, the series resistor is simpler and arguably more reliable since there is no active series pass element (bipolar transistor or MOSFET).

Figure 1 - LED String

Figure 2 shows a photo of the LED string mounted on an aluminum bar. I used a long aluminum strip available at Home Depot which is intended for carpeting but that worked quite well as a LED "heatsink" in this application.

Figure 2 - The LED string

For a long time, my lighting system consisted exclusively of the circuit in Figure 1 (with an external AC adapter). I thought it would be a nice touch to add a "Fade-in" effect to the string when the circuit is first powered. I was inspired by this Instructables.com article that uses a microcontroller from an Arduino. Hwever I decided to use an inexpensive 8-pin 12F683 PIC microcontroller instead (about \$1.25). I also made some improvements to the LED fading algorithm as described below. But first, let's have a look at the hardware.

Figure 3 shows the LED fader circuit. The circuit is built around a PIC 12F683 PIC microcontroller whose internal PWM circuitry drives an external N-channel MOSFET. The PWM duty cycle controls the brightness level of the LED string connected to header P2. Resistor R2 ensures the FET is OFF by default by pulling the gate of Q1 low. Resistor R1 limits the current transient when turning the mosfet ON (gate capacitance charge). Power to the microprocessor is derived from a 5V, 78L05 linear regulator and associated decoupling capacitors. D1 is an (optional) transient voltage suppressor (could also be replaced with a 24V zener diode).

Figure 3 - LED Fader Circuit

## PCB

As shown in Figure 4, I designed a small PCB for this project. This was actually my first pcb design using the open-source KiCad package (highly recommended). I decided to make this project totally "open-source" so you can download the complete KiCad schematic and board files at the link provided below. Note that some SMD decoupling capacitors are mounted in the bottom of the board.

Figure 4 - The PCB

For the enclosure, I used a Radio-Shack standard hobby box as shown in Figure 5. Notice that the Mosfet doesn't require a heatsink. Because this is a very low on-resistance device (0.022 Ohm typ), the power dissipation through the Mosfet is low and it remains relatively cool during normal operation.

Figure 5 - The final pcb in the enclosure

## Software

As in the original "instructable" article referenced above, this fader has two possible states depending on whether the fade was allowed to fully progress or not on startup. Normally, the circuit fades slowly up to full brightness over a period of about 4 seconds. If this fade-in period is interrupted however (the switch is turned-off mid-way) then the next activation progresses only to half-brightness. This is a simple way to implement a two-level brightness control without requiring extra switches (other than the mains switch). The state of the fade process is stored on internal EEPROM memory and is therefore kept even when power is off.

## Human light perception

As mentioned above, one improvement in this project over the original Arduino based project is the fading algorithm. Mathematically speaking, human light perception is roughly logarithmic (it actually isn't exactly logarithmic, but it's close enough to be a useful model). So our "perception" of light intensity doesn't increase proportionately with the actual light intensity. Put another way, we are more sensitive to the small increases in brightness when the light output is dim than we are when the light output is very bright. This has a very real impact on how you fade the LED brightness while keeping a "smooth" transition as perceived by a human eye. If you implement a simple linear algorithm ( something like adding a fixed k factor in a for loop: B(n) = B(n-1) + k, when B(n) is the brightness) the ramp is not smooth at all. It will seem as if the LED brightness is low for too long. To counteract the logarithmic perception characteristics in our vision, we must make the brightness increase exponentially (something like B(n) = k * B(n-1) ). This is implemented in the final code as a lookup table. I ended-up separating the ramp-up into two segments as experimentation showed this made the ramp even smoother (as I mentions, the logarithmic model is also a rough approximation).

## Capacitance issues

The circuit in Figure 2 worked fine with my lab power supply but, as Murphy's law dictates, it didn't quite work as expected when connected to the laptop AC adapter. The circuit relies on detecting that power was cut mid-way through the fading cycle to activate half-brightness the next time around. However, the laptop supply seems to have a huge amount of capacitance which meant the supply rail was kept high long after the power switch was cut (several seconds). This effectively meant the that "mid-way" power cut was never detected since the supply was always kept ON long enough to allow the microprocessor to reach the "final =1" state. I don't expect that all supplies will "suffer" from such an issue so I didn't include my solution in the schematic in Figure 1. However, for your reference, my solution was to add a 330Ohm 5W power resistor across the 19.5V supply. This load effectively speeds-up the capacitance charge/discharge cycle enough to allow the mid-point power failure detection as originally intended. The downside of course is that the resistor "wastes" about 1W of power when the lights are fully ON (though this is small compared to the overall power consumed by the 6 LEDs, about 30 W).

## Results

The photos in Figures 6 and 7 were taken using the same exposure setting (i.e. the same apperture and shutter speed) so they are a fair representation of the difference between the two brightnees levels.

Figure 6 - Full Brightness

Figure 7 - Low Brightness

## Possible improvements

I've been happy with the opeation of this device over the last couple of months. Since the PIC microcontroller has a few available I/O pins available, one possible improvement would be to add an "auto brightness" mode that depends on the measured ambient light. This could be implemented using a photoresistor and the internal ADC. Maybe the topic for a future article:)...

Comments, questions, suggestions? You can reach me at: contact (at sign) paulorenato (dot) com