Controlling an LED Filament With a Microcontroller

by fototrip in Circuits > LEDs

1215 Views, 4 Favorites, 0 Comments

Controlling an LED Filament With a Microcontroller

IMG_20220702_210518920.jpg

Ever since I saw my first LED Filament bulb, I've been fascinated by them. I immediately had all sorts of questions: How did they make an LED which is long and skinny? What voltage is needed to light it? Does it need a resistor in series (like most LEDs)? Can I control the brightness using a microcontroller (like other LEDs)? Etc.

This Instructable should help answer those questions for you, too, and help you set up your own microcontroller-controlled LED filament.

Step 1 below contains an explanation of my process, research and some helpful hints and advice. If you're in a hurry, and want to get started right away, you can skip that and go straight to Step 2.

Supplies

Motivation and Research

IMG_20220702_212104958.jpg
IMG_20220702_211829845.jpg

What is an LED Filament?


I saw my first LED Filament in a light bulb at a local hardware store. I was so curious about it, that I actually bought the bulb, brought it home, and took it apart (yes, that means I destroyed it, but, like most Makers, my office/lab is littered with many things I've bought simply to take apart.) The clear part of the bulb was actually plastic, so I was pretty sure it wasn't made like the old-time bulbs. And I was right: there was no vacuum, and it did not contain a tungsten filament.


So, what is an LED Filament? It's a string of SMD (Surface Mounted (meaning tiny)) LEDs all soldered in series in a row, coated in something translucent like a silicon sheath. And they're very brittle: if you try to bend the row, it will crack, thereby breaking the solder and leaving that filament useless. Take my word for it.


DC Boost Voltage Converter


OK, so now how can I incorporate that into my projects? The first problem is the voltage. Because all the LEDs are in series, it requires a relatively high DC voltage (high for the microcontroller world, anyway): my experimentation showed me that I needed about 50v to light the bulb filament brightly. Most transformers plug into the wall and produce 5v, 12v, 24v and sometimes as high as 36v DC. It's very uncommon to find a DC transformer with a much higher rating. I could have tried to find one of those, but, since that's too much for the microcontroller, which can normally only handle up to about 32v max, I'd then need to step it DOWN, or (even uglier) use 2 different transformers. So I decided to stick with the transformers I'm used to and see what I could do with them.


I couldn't find any easy circuits I was willing build which would take low voltage and step it up to 50v DC. But, luckily, I did find a class of devices, known as DC Boost Voltage Converters. Most of these devices are made for use in cars (where the standard voltage is 12v DC). 12v transformers are common and very easy to find. And, besides, I'm very comfortable working with 12v DC. So, I decided to use my 12v DC transformer and incorporate (i.e., "buy") a DC Boost Voltage Converter. There are many options all over the internet. Just make sure its input can handle the voltage your transformer outputs (in this case, 12v DC), it can output a little more voltage than you think you'll need (in this case, about 60v DC), and, finally, that it can output the amperage you'll need (I estimated approximately 500 mA). The one from Drok listed above fits this description, and is reasonably small.


So let's look at the Drok DC Boost Voltage Converter. The first thing I noticed was that it has a jumper, which arrives open, labelled "IN CHOICE ON=8-16V". Since my "IN CHOICE" is 12v, I decided to research that. On the Drok website I eventually found the following: "This item has two input ranges. Factory default is DC12-60V input. When 8-16V jumper is used, input range is 8-16V (input voltage can’t be over 16V in this case, otherwise it will burn the item)." There was no danger that my transformer would supply more than 12v, let alone 16v, so I installed a jumper on this.


The next thing I noticed is that the Converter has two blue rectangular components with tiny screws on top. The instructions (on line) say one is for the voltage output (labelled "CV"), the other is to control the max amperage output ("CC"). You supply your input voltage (in my case, the 12v DC from the transformer) and then use a jewelers screw driver to turn the tiny screw on the CV component to adjust the output voltage: clockwise boosts the voltage upward, counter-clockwise drops it downward. I hooked up my volt meter to the output, and watched the voltage vary up and down as I adjusted the screw. How cool! I was then ready to adjust it to the voltage needed for my filaments ... as soon as I had some working filaments.


The following links can give you a place to start finding more information about DC to DC Converters:


The LED Filaments


Well, all the filaments I had from disassembled light bulbs were now trash. So I checked online and found that you can, not surprisingly, buy them very cheaply from China. I used Ali Express (see the link above), but you can probably find other sources. It seems like there's currently no "standard" voltage to light filaments (they can vary from about 30v DC to about 70v DC), so make sure you find out what the filament's rated voltage is before you buy it, and make sure your Converter can output that voltage. The ones from Ali Express above are conveniently rated at 48v DC.


When the filaments finally arrived, I got to work. I used my volt meter to set the output of the Converter to 48v. The first thing to know about the filaments is that, just like any LED, it has an explicit positive and negative side. The positive side of the filament is denoted by a very tiny hole in the metal piece next to the yellow sheath. So, I hooked up the LED Filament directly to the Converter's output. It was VERY bright; I mean BLINDINGLY bright. I used the screw to adjust the voltage downward eventually to a level which didn't blind me. You can actually use very low voltages to cause the filament to glow dimly, if that's an effect you're looking for.


So: SUCCESS! Now I can light the filament. 


Controlling the Brightness?


But, it's not really all that interesting just to be able to set the filament to one brightness. My goal is to be able to control the brightness using a microcontroller. Being able to control the brightness allows for much more interesting and flexible displays.


The first thing I thought of to control the brightness was to use a continuous-rotation servo driving a jeweler's screw-driver, and use that to "manually" turn the CV screw up and down to make the filament brighter and dimmer. Well, while that's interesting (and cool retro, almost steam-punky), it's really not practical. By its size and placement, I'm pretty sure that screw is meant to be set once and then forgotten. I'm worried that it will probably break rather quickly if it's turned left and right continuously. Besides, an analog solution like this doesn't allow for quick or abrupt voltage changes: it can only go up or down as quickly as the servo can turn the screw. And finally, it seems like it would be very easy for the screw-driver to come off the screw head with just a little vibration. So: not optimal.


What we need is a transistor.


The NPN Mosfet Transistor


A transistor is an electronically controlled switch; well, it's much more than that, but it's at least that. There are many, many types of transistors. I'm not going to go into a deep-dive into transistors here, mostly because I myself do not have the depth of knowledge necessary. I'll leave that as an exercise for the reader. There is a huge amount of information on the internet about transistors, and, if you plan on working with them a lot, or are just curious, it's worth it to learn more about them.


I will give you some links to sites which helped me to better understand transistors during this project:


I chose the MJE 3055T NPN Mosfet Transistor because it can handle the voltage and current I need, and it's easy to wire up.


One thing I found out which I will pass on, though: Smaller, lower power transistors (like the P2N2222, which I use often for other, low-voltage LED projects) use the middle pin (called the "Base") as the pin to which you wire the output pin from the microcontroller. Higher power "mosfet" transistors (like the one used here, the JME 3055T), use the left pin (called the "Gate") as the pin to which to connect the microcontroller output. I don't know why this difference exists (if you haven't noticed yet, I'm NOT a transistor, nor even an electronics, expert), but it's something you should be aware of, in order to avoid frying some perfectly good transistors (as I have done many times).


What we're going to do is use the microcontroller's PWM (Pulse Width Modulation) functionality. Like transistors, there is a huge amount of information about PWM on the internet, so I won't go deeply into it here. Basically, we're going to use PWM to switch the transistor on and off very quickly, which will control the voltage allowed to the filament, and, therefore, control the brightness of the filament. More on this below.


So, now we're ready to start.

Setting Up the DC Boost Voltage Converter

IMG_20220703_211517634.jpg
IMG_20220703_211750144.jpg
IMG_20220703_211818559.jpg
IMG_20220703_211449471.jpg

We need to identify and attach a few things to the Converter.


First of all, identify the two blue, rectangular components topped with a tiny screw on each. Under them you can see the labels "CV" and "CC". This means the top blue component controls the output voltage (CV), and the bottom one controls the output current (CC). We'll be working with the CV screw later.


Next, identify the Converter's jumper pins labeled "IN CHOICE ON=8-16V" (it's centered in the picture). If you're using a different Converter, you might check the specs to see if this applies; you may not need a jumper at all. In the next picture you can see the (yellow) jumper I've placed across these pins to turn it "on", since we're using a 12v input.


Next you'll need to attach the barrel-jack "pigtails" to the input screws and the alligator clips to the output screws. BE CAREFUL OF POSITIVE ("+") AND NEGATIVE ("-"): red (or lighter color) to positive and black (or darker color) to negative. Also be careful not to short the metal of the alligator clips together.

Testing and Setting the Output Voltage

IMG_20220703_213026232.jpg
IMG_20220703_213311721.jpg
IMG_20220703_214725186.jpg
IMG_20220703_213912215.jpg
IMG_20220703_214319810.jpg
IMG_20220703_215320677.jpg

Now you can plug the transformer into the wall, and then plug its barrel-jack into the Converter's input jack. The Converter's LED should come on (green in my case).


Connect the alligator clips to your volt meter, which should be set to DC Voltage. If everything is turned on and plugged in correctly, your volt meter should immediately show some voltage output. For me, it arrived from the factory set to 12v output.


We want to set this to a few volts less than its rating (about 45v) to start, so we're not blinded (assuming the filament you're using is rated at 48v; if yours is rated differently, use a number which is a few volts less than the rating). We do this by inserting a jeweler's (tiny) screw-driver into the tiny screw on the top of the "upper" blue component ("CV"). Turn it clockwise, and you should see the voltage increase on your volt meter. Continue turning it clockwise until it reaches 45 volts.


At this point, you can disconnect the alligators from the volt meter, and connect them to your filament. The positive side of the filament is denoted by a very tiny hole right next to the yellow sheath. Connect the red alligator to the metal on this, positive side of the filament, and the black to the other side. It should light very dimly.


Now the fun part: use the screw driver again to turn up the voltage, as above, making the filament brighter. Although I'm sure it's possible, I have yet to actually "burn out" a filament this way. What will happen (aside from blinding you) is that the filament will get to a point where turning the screw doesn't actually make it noticeably brighter. If you keep turning up the voltage after that (and, if you're like me, you will do this just to see what happens), the filament will begin to blink, "strobe" actually, and you'll be able to smell it cooking. When this happens (because it's overheating), it means you've gone too far, and need to turn the voltage back down quickly. The idea here is to set the filament to be as bright as possible before it overheats. We'll control the brightness below with the transistor, but we can only make it dimmer than it's max, we can't make it any brighter than the brightest you set it here.


When you're done, disconnect the transformer from the Converter so you don't suffer permanent damage to your eyes (just kidding, but, really, don't look directly at the filament when it's at its brightest).

The Circuit

IMG_20220703_225730489.jpg
IMG_20220703_225816967.jpg
filament_breadboard.jpg

OK, so above we've shown that we can light up the filament. Now the goal is to control it's brightness with software. So this is where we need the microcontroller (Adafruit M4 Feather Express, in my case), and the Transistor.


We connect the Feather's D6 pin to the transistor's Gate (left) pin, through the resistor. The transistor's middle pin ("Drain") will go to the filament's negative side, and the right pin ("Source") to ground. Be sure the Feather is grounded to the same ground as the transistor.


We then wire the Converter's negative output to the same ground as the Feather and transistor. The Converter's positive lead connects directly to the filament's positive side.

Programming the Microcontroller

IMG_20220702_210519169.jpg

You should now plug the Feather into your computer with the USB cable. Nothing will happen yet, since the Feather is not programmed to do anything. So now we need to program the Feather to use PWM output on pin D6. Below is the Circuit Python code which will test this.

import time
import board
import pwmio

FILAMENT_PWM_PIN = board.D6

filament = pwmio.PWMOut(FILAMENT_PWM_PIN, frequency=5000)

start = 0
end = 65535
delta = end - start
increments = 10

for i in range(increments):
    intensity = int(start + ((i + 1) * delta / increments))
    print("  intensity: ", intensity)
    filament.duty_cycle = intensity
    time.sleep(2)

Essentially, we set the D6 pin's "duty_cycle" to a range of values from 0 (min) to 65535 (max). As we do so, we'll see the filament's brightness increase in proportion to the duty_cycle value. You should see the filament come on initially rather dim, and step up 10 times to its maximum brightness, and then turn off.

Downloads

All Done

And that's really all there is to it. This is, of course, just an example of how to set up the circuit and program the microcontroller. This would normally be a small part of a much larger design. But that's the fun part, on which you can start now.