šŸŒˆ ESP32-S3 Rainbow: ZX Spectrum Emulator Board! Get it on Crowd Supply ā†’
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