Custom LED Touch Light Fixture

by Kurt E. Clothier in Workshop > Lighting

22132 Views, 60 Favorites, 0 Comments

Custom LED Touch Light Fixture

Finished Without Cover.JPG
My wife and I really didn't care for the light fixtures that came in out fifth wheel camper, so we decided to replace them with a pair of cheap, matching fixtures we found on clearance. Since the camper lights run on 12V DC, I knew I would have to rip out the 120V AC sockets and replace them with 12V DC ones as well as as some sort of switch. Of course, I ended up over-complicate things, and after one thing lead to another, I ended up designing and building a set of LED fixtures with multiple brightness modes that operated by a simple touch of the fixture.

LEDs are much more efficient than the bulbs in use and will probably never have to be replaced. The decision to make the fixture touch sensitive came from my difficulty in finding a suitable push on-off button in white that can handle larger amounts of current.

Although my design is based on a 12V DC power source, a similar project could be made by using a regulation circuit to convert the AC power in your home to a suitable DC level. Remember, any time you are working with electricity it is VERY important to turn off the power source before you try to connect anything. NEVER work with live voltage lines!

I posted this project on my website a while ago, but I thought it deserved an Instructables makeover! It project involves a bit of complex circuitry design and programming but has been a lot of fun, and if you are ready and willing than so am I! Let's get to it...

Gather Your Materials

Tools.JPG
Normally, I would say the first step is to figure out what you are wanting to do, but I kind of already did that for you! So we'll just skip straight to the necessary components and tools. I believe I have listed everything that I used, but in case I missed something, all of the parts should be labeled in the upcoming schematic, and what tools you may need or want to use will really depend on your style of doing things and the fixture you choose to use!

Tools
Drill with various sized bits and and drivers  
Needle Nose Pliers 
Wire Cutters
Wire Strippers
Soldering Iron and Electrical Solder
Hot Glue Gun

Electronics
Computer - To view Instructable, look at designs, and download program
AVR Programmer - I use the Pocket Programmer from Sparkfun
Multimeter - Always useful when building circuits!

Computer Programs
Eagle PCB Designer - for schematic file viewing and editing (Optional)
WinAVR - To install the source code (AVR Studio should also work)

Hardware
Light Fixture to Convert - Needs to be conductive at the core, but can have a non-conductive coating.
Screws to Mount Fixture - Should come with the fixture
Small bolt and a few nuts - to connect our touch sensor to the fixture
Piece of sturdy cardboard - roughly the size of the fixture
Aluminum Foil

Electrical Components - All available at Digikey
Small Perf Board to solder components - the size depends on your ability to solder and what fits in your fixture
Small Guage Wire for circuit connections - I used gauges 30 and 22
Various Wire Caps for safe connections
Large Guage wire for power and LED connections - I used 10 guage wire
Roll of warm white surface mount LEDs - I found mine on Amazon 
1 x AVR ATtinyx5 microcontroller - the "x5" means any uC in that line will work: 15, 25, 45, or 85 [ Datasheet ]
1 x Atmel AT42QT1010 Single Channel Touch Sensor [ Datasheet ]
1 x 8 Pin DIP socket for uC chip
1 x 3.3V regulator (could work on 5V, but I wanted less power consumption) - I used the MCP1702 [ Datasheet ]
1 x Logic Level N Channel Power MOSFET, Must fully turn on at regulated voltage level! - I used the STD50NH02 [ Datasheet ]
1 x NPN Transistor - I used the common 2N3904 [ Datasheet ]
1 x 3 Position Screw Terminal for Power and LED connections
4 x 4001 Rectifier Diode
1 x 100uF Electrolytic Capacitor
1 x 10uF Electrolytic Capacitor
2 x 1uF Electrolytic or Ceramic Capacitor
1 x 0.1uF Ceramic Capacitor
1 x 0.01uF Ceramic Capacitor (Optional)
1 x 47nF Ceramic or Polyester Film Capacitor
7 x 10k Ohm Resistor
1 x 0.33 Ohm Resistor - Must be rated at least 1.5 Watts!!!






Circuit Design Overview

Schematic-v3.jpg
The circuit can be divided into four sections: power supply, touch sensor, microcontroller, and LED driver. The touch sensor is connected to the frame and alerts the microcontroller whenever it is activated. The microcontroller then sends a pulse to the LED driver to power the lights. The pulse width determines the LED brightness, and has three modes: low, medium, and high. The power supply regulates the voltage for the electronics, but the LEDs receive power directly from the 12V battery.

The circuit was created in Eagle PCB designer, and I have attached the latest version of the schematic.

I will also cover each of the four circuit sections in more detail in the following steps. If you are not interested in how they work, you can skip to Step 7 to see the complete soldered circuit!

Downloads

Schematic Overview 1 - Power Supply

SCH - Power Supply.jpg
This circuit is designed to run on 12V DC, but it could really be sourced by anything (including AC mains) as long as proper regulation is used. I chose a logic voltage of 3.3V instead of the more widely used level of 5V because the components will consume less power. The MCP1702 regulator comes in a 3.3V package, but can only accept inputs up to 13.2V. However, a 12V battery  charger will actually reach a level of around 14.4V DC, and for this reason, I placed 4 series diodes before the regulator to ensure the input voltage does not exceed this level. The first capacitor, C1, is to help supply the LEDs with immediate power when they are turned on. The surrounding capacitors are needed for proper regulator output and voltage stabilization. If this circuit were to be used in a typical house using an AC voltage, a transformer and rectifier circuit would need to be used to create a suitable DC level for the LEDs as well as an acceptable input level for the shown 3.3V regulator. 

Schematic Overview 2 - Touch Sensor

SCH - Touch Sensor.jpg
This is really the central component of the entire circuit. I used a single channel touch sensor chip from Atmel - the AT42Qt1010. The only bad thing about this chip is that it didn't come in a through hole part, so I had the joy of soldering a tiny surface mount component to the perf board... but more on that later. The sensor really works through capacitance, and it is important to get a proper value for C7. Without being connected to the fixture, the LEDs would randomly turn on and off just by walking by the circuit, but this high of a capacitance was necessary for the large fixture to be sensitive enough to work. A different sized light fixture may require a different sized capacitor. The two shown resistors are only there so the sensor is not directly connected to the fixture or two the microcontroller.

Schematic Overview 3 - Microcontroller

SCH - Microcontroller.jpg
The Atmel AVR ATtiny25 is the heart of this circuit, although any similar uC could be used. It has two jobs: 1) Wait for input from the touch sensor and 2) Send an appropriate pulse to the LED driver. The only other thing this uC should do is conserve power, so it waits in a sleep mode which can only be interrupted by a pulse from the touch sensor. The bypass capacitors C5 and C6 are not entirely necessary, but at least one of them should be used. The resistors R6, R7, and R8 are used to safely connect the unused pins to ground. Floating pins are never a good idea, and directly connecting a pin to ground or a voltage can be dangerous if a pin goes into the opposite state for whatever reason. 

The LED driver is connected to a dedicated hardware timer output, so it's operation is independent of the main processor, but I'll talk more about that in the Step 8 - Source Code.

Schematic Overview 4 - LED Driver

SCH - LED Driver.jpg
The LED driver is a very simple constant current source with a pulse width modulated (PWM) input from the uC to control the LED brightness. The operation is pretty straightforward as well. When a voltage is present on the gate of Q2, the MOSFET, it turns on, allowing current to pass through like a relay switch. The transistor used will determine the voltage level necessary, but mine fully turns on with the supplied 3.3V from the uC. Current flows through the LEDs and into the resistor R3. This is where it gets a bit interesting. Q1 will also turn on, and will do whatever it can to maintain a constant base to emitter voltage level of 0.6V. Other transistors may settle at a different voltage level. This constant voltage across R3 forces a constant current through the resistors. The current is essentially V-Q1,B-E / R3, or in this case 0.6V / 0.33ohms which equals 1.81 amps. Of course, this current is shared through many strings of LEDs, 24 to be exact, meaning each LED will have a full on current of around 76mA. The data sheet for the 3528 SMD LED states that a constant forward current of 50mA or a pulse current of 100mA is acceptable, so we should be in the clear as long as the LEDs are pulsed.

The brightness control comes from the pulsing. If a pulse width of 50% is used, than the LEDs will only be on 50% of the time and will appear at about 50% of the total brightness. This is because the human eye has a slower refresh rate than the pulse frequency, and the LED retains some afterglow in its off state. A frequency of 122 Hz was used for the LED pulse.

Building the Circuit

Complete Circuit.JPG
SMD Soldering.JPG
I always try to use through hole parts when working with a perf board, but they aren't always available. In this case, the touch sensor only came in small SOT23-6 package. I was able to glue the part to the board and solder small wired directly to the pin leads. I then covered the chip in hot glue to prevent the wires from getting yanked off.

The rest of the build was pretty straight forward as long as you know how to solder. The most important thing to remember is that the wires going to and from the LEDs need to be bigger gauge because of the larger current flow. Another important aspect is heat regulation. The MOSFET transistor will get hot sinking this current, even though it is rate for a much larger one. This component cannot be up against other things because it will need plenty of airflow and potentially a heat sink for proper operation. I learned the hard way and had to replace it twice before decided to house that particular component outside of the fixture, but more on that in Step 10 - Completing the Fixture.

ATTINYx5.jpg
Don't worry if you don't have any programming skills, I've done it for you! The attached file is the most up to date source code I have for the project. I have also included the various header files and makefile needed for the project to compile.

I used WinAVR to compile and the USB Pocket Programmer from Sparkfun to download the code into the AVR chip, but you could use AVR Studio and whatever programmer you are used to; just be sure to alter the makefile accordingly. The AVR fuse bits are the default values.

Program Operation
Basically, the uC waits in sleep mode until it is woken up by a hardware interrupt from the touch sensor. It then turns the LEDs on in a low state. When the sensor is touched again, the mode is changed from low to medium, and again to high after another touch. One final touch of the fixture will turn the lights off and put the uC back to sleep, waiting to be woken up by the touch sensor. This cycle repeats itself indefinitely. 

Two header files are in use. The first is my custom AVR.h file which contains many useful macros as well as calling other required headers. The second is the sleep.h file that is included with WinAVR.

The program starts by initializing the AVR chip: turning off unused features, setting the I/O ports, reducing the system clock frequency (for more power savings), setting up Timer 0 for a 122 Hz pulse, enabling the pin change interrupt for the touch sensor, and enabling the power down sleep mode.

The program then enters a forever loop which only does one thing: check to see if sleep is enabled. If sleep is enabled, the uC is put to sleep to wait on the touch sensor's hardware interrupt.

Only one interrupt handler is used: the pin change interrupt for the touch sensor. This routine checks the state of the LEDs and decides to turn them on, increase the brightness (pulse width), or turn them off accordingly anytime the fixture is touched. It also holds the program in a loop until the fixture is no longer being touched.

The LED pulse is handled entirely by hardware features of the uC. The only thing that has to be done in the code is to enable or disable the Timer 0 output connected to the LED driver.

Preparing the LEDs

LED Adjustments.JPG
I picked up this roll of LEDs from Amazon. The main thing to consider when purchasing these LEDs is the color. White LEDs can be a point of confusion for some. There are actually cool white LEDs and warm white LEDs. The cools have more of a blue shade and will alter the way things normally appear under light bulbs. This can lead to disappointment if you are not anticipating this change. Warm white LEDs more closely resemble the yellowish light emitted from a standard light bulb or the sun.

The roll of LED strip lights I got was great, but came ready to be used meaning each string of LEDs already had a series resistor. The roll is basically a bunch of 3 LED strings in parallel, so it can be broken up every 3 LEDs. The series resistor in each string needs to be shorted or the current source LED driver won't work correctly. Wait, am I suggesting you alter (or ruin, as my wife would say) a perfectly good roll of LEDs? Why yes, yes I am. 

I used 24 strings to provide enough brightness, but your necessary amount of LED strings may increase or decrease. If so, be sure to adjust the value of R3 in Step 6 accordingly to provide the correct amount of current through each string.

I recycled the leads of components I cut off when building the circuit and used small pieces of solid wire when I ran out of cut leads. The traces on the LED strip can be soldered to directly. When that is done, each LED string needs to have a pair of lead wires so they can all be connected in parallel. 

Completing the Fixture

Fixture 1.jpg
Fixture 2.jpg
Now comes the fun part - putting it all together! To start, we need to take out all of the socket pieces that come in the fixture. The circuit can then be attached. I was able to bolt mine through the hole left by the original socket, but you may need to drill a hole for this purpose. The lead connecting to the touch sensor was wrapped around a small washer on the bolt, connecting the sensor to the conductive core of light fixture. Although the outer coating is not conductive, the sensor is sensitive enough to work through it because it senses the change in capacitance with respect to ground as a finger approaches. In fact, it will work without a complete physical touch, a finger (or nose, if you're in the mood) just needs to come very close to the fixture.

At this point, the fixture can be mounted in the ceiling. I am assuming there is already a hole with the power leads available. The power can then be connected to the circuit with wire caps.

The next step is to create a housing for the LEDs. I used a piece of sturdy cardboard and bent to wings to force some of the light down at an angle, and lower the LEDs from the circuit. The cardboard was wrapped in alluminum foil to aid in the LED head dissipation and to make it look nicer. Once the wires have all been connected and capped, the LED housing can be attached to the fixture using a few strips of Velcro. This allows it to be easily removed for access to the circuit or to remove the fixture.

Heat Considerations

Heat Sink.JPG
As noted in Step 7, the heat dissipation of the MOSFET is very important. I burned up two of these parts before I really solved the problem. Because the LEDs are enclosed in the glass fixture covering, the fixture interior air quickly heats up when the LEDs are on. Since the MOSFET is also hot from sinking a large current, it needs proper airflow to cool off, but it cannot if it is surrounded by other components.

The first time the MOSFET quit, the LEDs flashed a few times, and then remained in a dim state. The fixture was unresponsive, so I took it apart to work on it. I ended up running wire leads to the circuit and attaching a new MOSFET to these leads hoping that the part would get enough air flow raised off of the circuit. But after a few days of running, it too gave up. 

This time, I decided to run the MOSFET leads through a small hole I drilled outside of the fixture. The part would still be concealed by the fixture outer rim, but it would be outside of the hot air filled interior and stood a chance of keeping cool. I also affixed it to a large heat sink. This solution has been very effective. The entire fixture has worked flawlessly with this heat dissipation in mind. I also covered the surrounding fixture area with electric tape to prevent the heat sink from touching the fixture and effecting the sensor sensitivity.