View All Posts
read
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi

Learn how to build a USB-powered LED filament circuit using an ESP32 microcontroller and DC boost converter. This project explores the use of a gate driver, inductor, diode, and capacitor to create a circuit that can power multiple LED filaments from a 5V USB supply.

Related Content
Transcript

[0:00] Big Clive did a video a few months back showing these LED filaments

[0:04] and I thought it would be fun to do a little project with them.
[0:07] There are 18 LEDs in each filament all in series

[0:10] so to get them to light up we’ll need around 43 volts or more.
[0:14] Now obviously big clive just connected his straight to the mains using a capacitor dropper
[0:18] But as I’ve pointed out before I’m not Big Clive.
[0:21] I’d quite like to power mine from a 5-volt USB supply

[0:24] so we’re going to need to boost our power supply up by quite a bit.
[0:28] So DC boost converter circuits are conceptually pretty simple.
[0:32] All we need is an inductor, a switch, a diode, and a capacitor.
[0:36] So I’ve set this circuit up in KiCad and I thought it would be interesting to try and simulate it.
[0:41] I’ve added a 4K7 load onto the output
[0:45] We’ll see how well it actually drives that
[0:47] We should get around 10 milliamps at our target voltage
[0:51] For the capacitor and the inductor, I’ve used the standard PSpice simulation symbols
[0:56] If we look in the component library and search for PSpice

[1:00] we can see that we have some built-in models
[1:02] We have the capacitor and we have the inductor
[1:06] For the diode, I’m using a Schottky diode.
[1:09] I’m using a 100 volt 1 amp Schottky diode and I have a spice model that I’ve downloaded for this
[1:14] The only thing i had to do was change the node sequence to 2 1

[1:18] instead of 1 2 because i found my diode was being simulated in the wrong direction
[1:23] For the switch, we have an IRF640N
[1:26] I’ve downloaded a spice model for this and we should be able to simulate this fairly accurately
[1:32] To power the circuit I’ve set up a 5 volt DC voltage source
[1:36] And to power the gate of the MOSFET I’ve set up another voltage source
[1:39] And on the spice model for this,

[1:41] I’ve set it up with a 25 microsecond period which should be 40 kilohertz
[1:46] And I’ve set up a 12.5 microsecond pulse width which should give us 50% duty cycle
[1:52] Let’s try simulating this
[1:53] The only thing we need is some instructions for the simulator to tell you what to do
[1:57] So this bit of text tells the simulator to run a transient simulation

[2:01] running with 0.1 microsecond steps for 0.2 seconds starting from 0 seconds
[2:06] On KiCad 6 we go to inspect and then click the simulator button
[2:11] We can now hit the run stop simulation and it will start to simulate our circuit
[2:18] So that’s our simulation completed let’s have a look at the output voltage
[2:24] If we bring up a cursor we can measure this exactly
[2:28] We click show cursor and now we can drag this cursor around

[2:31] and we can see we’re getting around 58 volts on the output
[2:35] Let’s go back to our voltage source that’s driving the gate and change the period to slightly lower
[2:40] Let’s change our period to 10 microseconds which should be a duty cycle of 40
[2:46] We’ll change that and then we’ll go back to the simulation and re-run it
[2:54] Our simulation is completed and we’ve hit our magic number of 47 volts on the output
[2:59] If we add the current going through the load resistor we should see around 10 milliamps
[3:05] Which we do so let’s just double-check that
[3:07] We’ll show the cursor

[3:09] and we can see we get almost exactly 10 milliamps going through our load resistor
[3:14] So I think our circuit should work pretty well
[3:16] Let’s move over to the workbench and build it and see how it performs in the real world
[3:20] Do you like PCBs?
[3:21] Do you want to make a PCB in a weird and wacky colour like purple?
[3:25] Maybe you’d like a flexible PCB?
[3:27] Or maybe you’d like someone to do some CNC work for you?
[3:31] Check out the link to PCBWay in the description
[3:39] So I’ve built the circuit on a breadboard and I’ve wired up to my signal generator
[3:44] I’m running the signal generator through a gate driver chip just

[3:47] to make sure we get a nice clean signal on the gate of the MOSFET
[3:52] Let’s slowly ramp up the duty cycle and see what happens to the output voltage
[4:02] At around 42 or 43 duty cycle we get 47 volts going across our 4k7 resistor
[4:10] The circuit works pretty well and actually matches the simulated circuit fairly accurately
[4:15] Let’s try it with one of our LED filaments and see how well it works lighting one up
[4:19] I’ve plugged one in and I’ve put a 100-ohm resistor just to measure

[4:23] the current going into it and limit the current
[4:26] So my multimeter is currently set on the millivolt range

[4:29] so if we divide this number by 100 we get the current going through the filament in milliamps
[4:36] This is around two milliamps running through the filament
[4:39] I’ll need to change the range on the multimeter now
[4:44] so we’re at 2.3 milliamps as we ramp up we get to around 3 milliamps
[4:50] it’s actually pretty bright now and as we keep going up this is now five milliamps
[4:57] six
[4:58] seven
[4:59] eight
[5:00] nine
[5:01] and now we’re at 10 milliamps going through the LED filament
[5:04] It’s actually quite hard to look at
[5:06] The camera is doing quite a good job at capturing the dynamic range of the video
[5:12] So let’s turn this down let’s try on a slightly harder problem
[5:15] We’ll try plugging in seven of the led filaments
[5:18] We’ll just unplug this one
[5:25] And once again I’m just using the 100-ohm resistor to limit the current

[5:29] and I’ve plugged in seven filaments so let’s ramp up the duty cycle again
[5:35] I’ve left the multimeter on the 20-volt range

[5:38] so this is currently around five milliamps driving these seven LED filaments
[5:45] Now we have 10 milliamps going through them
[5:48] Let’s just check the components are not getting hot
[5:50] and the finger test says they’re all okay
[5:53] So let’s ramp it up some more
[6:05] 20 milliamps
[6:09] 30 milliamps
[6:15] that’s 40,
[6:16] 50,
[6:17] 60 milliamps
[6:18] So with seven filaments, that’s just under 10 milliamps per filament

[6:23] and our circuit’s still performing well
[6:27] So let’s measure the voltage that’s actually running across our load
[6:30] So we’ll move our multimeter around and switch it to the 200-volt range
[6:36] and we have 44.5 or 44.6 volts going across our load
[6:41] and what happens if we remove our load?
[6:43] suddenly it jumps up
[6:44] it’s now 116-120 volts
[6:48] this is actually out of spec for most of our components
[6:51] if we now plug back in our little single filament then it drops down to 46.1
[6:58] but then if we remove our filament it jumps up again to over 100 volts
[7:04] and we can see this as we add and remove the load,
[7:07] the voltage swings around quite dramatically
[7:09] So what we need to do is add some feedback to this circuit so the duty cycle is controlled
[7:14] So as the load comes on and off the circuit

[7:17] we adjust the duty cycle to maintain the output voltage
[7:22] Now I know right now lots of you will be thinking:
[7:25] “Chris, you can just buy chips that will do this. Stop messing around”
[7:29] And you are right
[7:31] But in my project I’m going to need an ESP32

[7:34] anyway - so we might as well use it to drive the MOSFET as well.
[7:38] The ESP32 can output PWM signals and it’s got an Analog to Digital Converter
[7:43] So we should be able to use it to monitor the output voltage

[7:46] and update the duty cycle that is driving the MOSFET
[7:49] For the feedback from the output,

[7:51] we do need to be careful not to put more than 3.3 volts into the ESP32
[7:56] I’m going to have a voltage divider on the output with a

[7:59] trimmer potentiometer on the bottom and quite a high-value resistor on the top
[8:03] but I’m also going to be extra careful

[8:05] and I’m adding a 3.3-volt zone diode across the output of the potentiometer.
[8:10] This should mean it’s impossible for the voltage to go over 3.3-volts.
[8:15] We’ll compare the voltage coming from the potentiometer against a reference

[8:18] voltage in our code and try and drive the duty cycle so that we get zero error.
[8:24] This is the circuit we’re going to build.
[8:26] It’s not very complicated we have the ESP32

[8:29] driving the MOSFET of the boost converter through a gate driver
[8:33] and we have the voltage divider on the output feeding back into the ESP32.
[8:38] There is one small gotcha that we have with the ESP32:
[8:41] the Analog to Digital Converter on the ESP32 is notoriously noisy
[8:46] I’ve hooked up a potentiometer on the input and you can see just how noisy it is on this trace.
[8:52] To help fix this problem i’m going to be taking multiple readings from the ADC

[8:57] and I’ll take the median value of these readings.
[9:00] So I’ve added this filtered output to the trace alongside the raw value

[9:03] and as you can see it’s now a lot smoother and almost all the noise has been removed.
[9:08] Now that we can monitor the output voltage we just need to compare it

[9:11] with a reference value and adjust the PWM output until the error is zero.
[9:16] Initially, I was thinking of making a PID controller but in the end,

[9:20] I found it was sufficient just to use the “I” from the PID.
[9:24] So we’re just adjusting the duty cycle by adding the voltage difference times a constant factor.
[9:29] One interesting thing to note on the ESP32 is you can’t use floating

[9:33] point instructions in an interrupt routine
[9:36] So I’m using fixed point arithmetic and just multiplying everything by 1000
[9:41] So let’s plug it all together and see if it works
[9:47] I’ve got the same boost circuit as before except I’ve now got the gate driver connected to an ESP32
[9:53] And I’ve got feedback from the output voltage going back into this ESP32 via a voltage divider
[9:58] And I’ve got my safety Zener diode so i don’t accidentally blow up the esp32
[10:03] On the top right, I’m monitoring the signal on the gate of the MOSFET
[10:07] and in the bottom right I’m logging out the duty cycle and I’m logging out the voltage on the ADC
[10:13] I’ve multiplied this voltage by 10 so it’s on a similar scale to the duty cycle
[10:17] I’ve adjusted the trim pot so that we have the lowest possible voltage

[10:21] which gives us a duty cycle of just under five per cent
[10:25] There’s currently nothing connected to the output apart from our voltage divider

[10:29] let’s ramp up the output to 46 volts
[10:40] you can see as I’m ramping the voltage up the value on the ADC is staying pretty constant
[10:52] so to get our voltage of 46 volts we need a duty cycle of around 17.5 per cent
[10:58] Let’s try adding some led filaments to our load
[11:01] I’ll run each one with a 100-ohm current limit resistor
[11:07] with one filament we need a 22% duty cycle
[11:12] with two we need just over 25%
[11:16] with three it’s just under 27%
[11:20] and four just under 32
[11:24] five we need just over 33%
[11:27] and six it’s 36.5%
[11:30] I don’t have any more room on my breadboard for more so six we’ll have to stop at
[11:34] But we can bump up and bump down the voltage on the output
[11:38] So we can dim and make the LEDs go brighter
[11:41] So even at 47 volts we just need 65% or 64% duty cycle
[11:47] So there’s quite a lot of headroom in this circuit
[11:49] So we could easily make it much brighter or add more filaments
[11:53] And you’ll notice the output voltage has stayed pretty consistent throughout adding the LEDs
[11:59] We can also measure the current going into one of the LEDs
[12:02] So let’s have a look at this
[12:04] and we can see we have around 3.7 milliamps going through this LED filament
[12:09] So we could definitely make it brighter or we can add more led filaments
[12:12] I’m aiming for seven so I’ve got six at the moment seven seems really achievable
[12:17] So this is going to work pretty well for my project I’ll do a follow-up video soon

[12:21] when I do the next phase of this exciting project
[12:24] so I’ll see you soon
[12:29] So I’ve just been browsing AliExpress and I found 3-volt versions of the LED filaments
[12:35] So I’ve ordered some of these they’ll take a

[12:36] few weeks to arrive so I’m going to carry on with the existing project
[12:40] but I’m quite interested to see how well these ones work
[12:42] So I’ll see you in the next video


HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
Blog Logo

Chris Greening

> Image

atomic14

A collection of slightly mad projects, instructive/educational videos, and generally interesting stuff. Building projects around the Arduino and ESP32 platforms - we'll be exploring AI, Computer Vision, Audio, 3D Printing - it may get a bit eclectic...

View All Posts