logo elektroda
logo elektroda
X
logo elektroda

How to drive a MOSFET at 3.3V with the ESP8266? Making a dimmer from scrap MOSFETs

p.kaczmarek2 3417 10
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • Electronic circuit powering an LED strip, showing a lab power supply, ESP8266, and bright LED lights. .
    In the previous section I showed how a beginner can get transistors for free from old scrap PC motherboards. Here I will show how to use them in practice. We will drive the MOSFET transistors from 3.3V and, in the process, see the importance of the voltage at the gate of the transistor. Here we will make the hardware basis for our own ESP8266-based WiFi-controlled dimmer.

    See the previous part: Good MOSFET transistors at 5V for free? Recovering parts from an old PC motherboard .
    A similar project has already been published, but there it was controlled from the 5V level so there were no combinations:
    PIC12F683 and SDCC - tutorial - we create a simple dimmer (read datasheet notes) .

    Free transistors and desoldering them with a regular soldering iron .
    This time I found an old flat screen TV, still with fluorescent backlighting. Time for a quick visual inspection of the backlight module, which had already arrived to me damaged anyway:
    Old printed circuit board with electronic components .
    Bottom of a motherboard with recovered MOSFET transistors .
    Four promising transistors can be seen at the bottom:
    Close-up of four MOSFET transistors KMB054N40 mounted on a circuit board.
    KMB054N40, N-type channel MOSFET, Vds=40V (drain-source voltage), Id = 54A
    KMB054N40 MOSFET datasheet
    Resistance in the open state at Vgs=4.5V (gate voltage) not bad either, only up to 11mΩ.
    They just need to be soldered out. This can be done without hot air. My method is first flux, then lead binder on the solder to soften it, then alternate heating of the ground pours. The transistor can be removed with tweezers.
    Close-up of a circuit board with mounted KMB054N40 MOSFET transistors and surrounding components. .
    Close-up of a circuit board with KMB054N40 MOSFET transistors. .
    Electronic board with MOSFET transistors KMB054N40 .


    Dimmer program on ESP8266 (NodeMCU here) .
    I programmed the ESP8266 in PlatformIO based on ArduinoOTA so that I could upload the batch over WiFi:
    How do I program the Wemos D1 (ESP8266) board in Arduino shape? ArduinoOTA in PlatformIO .
    PWM - Pulse Width Modulation, pulse width modulation - is used to control brightness. Basically, we quickly "turn on and off" a logic state on a pin, here 0V or 3.3V. In Arduino, the analogWrite function is used for this. I made my program to simply dim from 0 to 100% in a loop, while refreshing the ArduinoOTA so I could still update the program over WiFi:
    Code: C / C++
    Log in, to see the code
    .
    I expose the PWM to the GPIO2 pin, which is D4 on the NodeMCU.
    Result:


    .
    The program works, and the PWM is both on the LED on the ESP12 board, and on D4.

    Dimmer on KMB054N40 .
    The first schematic that comes to mind is probably to connect the output of the ESP to the gate of the transistor, preferably through some sort of resistor. I've decided to start with that, although I can't say it's the correct approach. We'll see.
    Schematic diagram with MOSFET for controlling an LED strip. .
    The recovered MOSFET is surface mounted, so we won't use a contact board. Anyway, I would advise against a "contact board" for higher currents. Instead, we will make a so-called 'sculpture', as some people colloquially say, on a piece of laminate. I start the process of creating such a board by cleaning the surface of the laminate so that it is easier to solder:
    Copper plate on a wooden background. .
    Cleaned piece of laminate on a wooden surface. .
    I make the breaks with a grinder, then test if there is a short circuit with a multimeter:
    Fragment of a PCB with a mounted transistor. .
    Multimeter on a wooden table next to a copper laminate and a transistor. .
    When assembling, it is worth remembering that the entire circuit must share a common ground. In addition, respect the maximum input voltage of our module from the ESP, 12V can damage it. This is the case with the NodeMCU. To power it from 12V, you will need a step-down converter, but that's off topic....
    Getting started:
    LED dimmer controlled by ESP8266 powered by a laboratory power supply. .
    It looks like everything is working. The MOSFET does not heat up excessively....
    I also connected a resistor from the gate to 3.3V instead of the PWM output, it flows 2.3A, still without excessive heating:
    Laboratory power supply connected to an electronic circuit. .

    Dimmer on 2SK3918 .
    Only is it always so colourful? Let's find out. Let's replace our KMB054N40 with the 2SK3918 I have from the topic about old PC motherboards .
    The pinouts match. Swap done, boot up and:
    Laboratory power supply display and connected NodeMCU module. .
    Something has reduced the current, it's already strange. It was 2.3A and it's 1.73A, the LEDs are not so bright anymore, but that's not the only problem.
    The transistor heats up and after a while it is already very warm:
    Prototype electronic circuit with MOSFET transistor on copper laminate .
    Why did the KMB054N40 manage and the 2SK3918 no longer does? .
    It all comes down to the control of the transistor. This is a MOSFET transistor, it is controlled by voltage. The voltage at the gate (relative to the source) is determined by the parameter Vgs. How much current will be passed through the drain (resistance in the open state) depends precisely on Vgs. This is detailed on the first page of the datasheet note, but we should actually check the diagrams as well:
    Section of the datasheet for the 2SK3918 transistor. .
    Technical specification of KMB054N40DB MOSFET. .
    The graphs show the drain current as a function of gate voltage, in addition with separate curves for different temperatures:
    Graphs of characteristics for two MOSFET transistors 2SK3918 and KMB054N40. .
    As you can see, the 2SK3918 will fail in our circuit, i.e. at Vgs = 3.3V and at the current we expect. No wonder, it does not open fully and the resistance is too high, as a result of which it heats up. With the KMB054N40 it is slightly better, although still Vgs could be higher there.
    Of course, in practice there are more dependencies here, although even on the posted graphs you can see that the junction temperature itself also has an influence (and worse, the higher the temperature, the worse the conduction), but this was supposed to be a simplified presentation so we won't go that deep.

    Now this needs to be fixed somehow. We need to give the gate of the MOSFET a higher voltage. The easiest way will be to add another control stage, this time a current-controlled transistor, I will find some small signal-controlled NPN. This will short the gate of the MOSFET to ground, which I will additionally pull up to 12V.
    Need to search the boards again to see what is available. On the board from the inverter I saw the TL431 itself in a case in TO-92, but it's not even a transistor, but a "programmable Zener diode"... so I looked on another board, this time the power supply module, well bingo:
    Electronic components on a printed circuit board, including a STN2222 transistor. .
    STN2222 is a small NPN bipolar transistor, the parameters look promising:
    Table of maximum and electrical characteristics of the STN2222 transistor. .
    Planned circuit:
    LED dimmer circuit diagram with ESP8266 and MOSFET transistor .
    Just a note - now when the ESP output is 3.3V (logic 1), current flows through R1 to the base of the auxiliary transistor, causing it to open. The open auxiliary transistor then short-circuits the gate of the MOSFET to ground, simultaneously closing it. So here we have the logic reversed, but since we are writing the software for the ESP ourselves this is not a problem.
    Implementation:
    Copper laminate with a mounted transistor and resistors. .
    Time to check our work. This time the logic is reversed, so I connected the resistor to ground. You can immediately see that more current is flowing - almost the same as with the previous transistor, 2.3A:
    Electronics lab with power supply, ESP8266 board, and prototype circuit. .
    We wait, we wait and ... The MOSFET continues to be cool. Success.
    I also checked the control from NodeMCu and it continues to work, we can continue to control the brightness of the LED bar.
    Looks like problem solved. Maybe we can even do without a heatsink - the copper plate also dissipates some heat.
    Of course, this is not the only way to control a MOSFET transistor, a lot depends on the switching frequency, gate charge, there are also dedicated drivers, but for a simple dimmer, the circuit shown here fully copes.

    Summary .
    This short practical demonstration showed us the importance of reading the catalogue notes of the components we intend to use in our projects. The two transistors are quite similar, but the devil is in the detail - one still somehow managed to drive from 3.3V (Vgs) at 2.3A current (Id), while the other one got excessively hot. Fortunately, we were able to fix this, even while maintaining the theme of the game - that is, selecting components from electro-waste. A side effect of this approach is that the control logic is reversed, but this is not a problem when programming such a dimmer from 0.
    Now, we can take it easy on the circuit, improve the board, add some buttons, and program everything in PlatformIO with a suitable web page for control and perhaps automation (e.g. gradual lighting at a given time according to NTP time from the web).
    Finally, I have allowed myself some minor simplifications in the topic, but I don't think this is a problem, in fact I hope that such a presentation will encourage beginners to experiment more with transistors.
    Have you encountered a similar problem in your own projects, and if so, how did you solve it?

    Cool? Ranking DIY
    Helpful post? Buy me a coffee.
    Do you have a problem with Arduino? Ask question. Visit our forum Arduino.
    About Author
    p.kaczmarek2
    Moderator Smart Home
    Offline 
    p.kaczmarek2 wrote 11822 posts with rating 9927, helped 564 times. Been with us since 2014 year.
  • ADVERTISEMENT
  • #2 21383677
    acctr
    Level 38  
    p.kaczmarek2 wrote:
    there are also dedicated controllers, but for a simple dimmer the circuit shown here fully copes
    .
    There was probably a controller to the right of the transistors with such drivers, why not use it?
    What kind of TV was it? are there any markings on the PCB?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #3 21383698
    p.kaczmarek2
    Moderator Smart Home
    The reason for not trying to use a PCB controller is very simple - it's just been on my mind for a while to show (in my opinion) the simplest way, which is the method with a bipolar transistor, which, although inverted, does the job.
    And besides, as it is well worth trying, here is a bit more info:
    Circuit board with soldered wires and a transistor. .
    Image of a circuit board with an integrated circuit and electronic components.
    Markings:
    Close-up of a circuit board labeled PLHL-T808A with electronic components. .
    Part of a PCB with markings and electronic components. .
    I haven't checked them yet, if anything I'll edit the post
    Helpful post? Buy me a coffee.
  • #4 21383700
    androot
    VIP Meritorious for electroda.pl
    This is an example of an anti-guide. I get it, you wrote about some simplifications, but this guide is misleading.

    Firstly:
    The statement that mosfets are voltage controlled. This is what happens in a static state. When switching quickly, gate current flows. Why are drivers for mosfets or IGBTs capable of putting out several A of current? Precisely to overcharge the gate capacitance. Your circuit masks the problem, because the PWM frequency is probably a few hundred Hz. I use several kHz to control the LEDs in my flat, because otherwise you can hear the LED strips squealing. Then these transistors would desolder themselves.

    Secondly:
    Focusing only on the channel resistance. There is also such a patrameter as the charge needed to overcharge the gate and the associated capacitance. Losses during the switching state are one thing, but when switching is another. See the point above.

    Thirdly:
    This circuit with an NPN transistor and 10 kΩ in its collector.... I suggest you count how long this 1 nF capacitance will charge (and, as a rule, the lower the channel resistance, the higher the gate capacitance, so it could be several nF as well). If you don't want to count, you can take an oscilloscope and see what is there instead of the expected rectangle.... An analagic circuit is made of the digital.

    Fourthly:
    There are transistors that have switching voltages even below 1V and we can control them straight from the ESP leads, using the full capabilities of the GPIOs, more specifically their current capacity of the push-pull outputs.
    In the mentioned circuit (point 3), we have a high pull current, and a push current of about 1 mA thanks to the unfortunate 10 kΩ resistor....

    I would see the tutorial as discussing the problem rather than masking it.

    You do a lot of good work when it comes to programming, but I had to write my own as someone gets into topics that MAY not fully understand and is still trying to teach others.
  • ADVERTISEMENT
  • #5 21383725
    p.kaczmarek2
    Moderator Smart Home
    I am aware of the issues you have written about, but in my opinion for a simple dimmer not operating at a higher frequency (which you yourself have given as being unusual), this is in my opinion negligible. Anyway, there is a sentence in the text that I don't know if you have paid attention to?
    p.kaczmarek2 wrote:
    .
    Of course, this is not the only way to control a MOSFET transistor, a lot depends on the switching frequency, gate charge, there are also dedicated drivers, but for a simple dimmer the circuit shown here fully copes.
    .
    Even more so, if I wanted to control some IGBTs at higher frequencies in some inverter, I wouldn't use the simple solution shown here, and I also have dedicated MOSFET drivers after various projects, for example, the first of the bunch at the time of writing the posts:
    Various electronic components, including transistors and drivers, on a wooden background. .
    Now, one would still have to wonder what exactly is the object of your criticism, i.e. do you even think that such a solution as I have shown for beginners has no right to exist, and anyone to control an LED strip with an ESP8266 needs that much theory? Or are you more concerned that it's not emphasised enough in the topic that it won't work in other situations? If it's the former I'd debate that such LED control under these conditions will work, in the latter I can still agree.
    Helpful post? Buy me a coffee.
  • #6 21383749
    androot
    VIP Meritorious for electroda.pl
    And if one does not have a dedicated driver? It will not know that this 10 kΩ resistor, can be reduced, accepting losses in it, but many times lower than in a mosfet. At 1 kΩ we have losses in the range 0...144 mW (PWM 100...0 %), but lower in the mosfet.
    Then suppose someone takes a dedicated driver and gives a gate resistor of e.g. 1 kΩ instead of a few Ω, "because mosfets are voltage controlled".

    And what if you don't have both a driver and a 12V voltage available? The bootstrap circuit can also be used in the example above.
  • ADVERTISEMENT
  • #7 21383792
    jvoytech
    Level 21  
    It is worth mentioning the main disadvantage of such a simple driver, i.e. the 'slow' charging of the gate by the 10k resistor, so at higher PWM frequency the heating problems may return.

    For the output connector it is worth giving a diode in parallel as for the coil, and when designing a PCB it is better to leave a solder field for such a component. Someone at some point might connect a coiled longer cable and high voltage pins could form when switching off with a mosfet. I have seen designs where such diodes were placed but I don't know if such protection is not overkill 🤔.
  • #8 21383815
    acctr
    Level 38  
    This looks like a UBA2071-like IC. He is intended for CFL control, but you could try generating a simple PWM.
    The argument in favour is the drivers and charge pump inside, allowing high-side control.

    Block diagram of the UBA2071 integrated circuit. .

    androot wrote:
    In the tutorial I would see a discussion of the problem rather than a masking of it.

    Apparently you are right, but the author got the results to his satisfaction, i.e. a cold transistor in a simple way. He also mentions charge and switching frequency which shows that he is aware of the problem. You've gone a bit overboard with your criticism.

    jvoytech wrote:
    I have seen projects where such diodes have been placed but I don't know if such protection is not overkill
    .
    Electrostatics.
    Helpful post? Buy me a coffee.
  • #9 21383926
    p.kaczmarek2
    Moderator Smart Home
    On the topic of simplification in the presentation, I would like to point out one more thing - as far as I can see, in our time, programmable modules (and ones with WiFi) are cheaper and simpler to use than ever. For example, depending on promotions and whether or not you create a new account on the site, you can import such a NodeMCU with ESP8266 from China for just 4£ and 18 cents:
    Image of an online store listing for the NodeMCU V3 CH340 module, priced at 4.18 PLN. .
    Practically everyone can start the adventure with NodeMCU, because the expense of 4 PLN is as nothing (rather everyone has a USB cable), for this reason I wanted to present such a simplification of the whole process, of course noting in the text that it is a simplification. All with the hope that maybe someone will get motivated to tinker and then, once the LED bar lights up, he or she will catch the interest and, if necessary, read deeper into the book and gradually add to the knowledge. I work a lot with younger people and I know that to start with, one small practical presentation is hundreds of times more interesting than theory, so this can be used as a kind of 'lure' to get them away from FB, for example....
    Of course, here you have to be careful not to over-simplify, but this has already been mentioned, rightly so too.
    Helpful post? Buy me a coffee.
  • #10 21391970
    MatthewGlen
    Level 2  
    Thank you so much for the info.
  • #11 21397156
    marweg1967
    Level 14  
    If the purpose of the entry is to show how to "make something out of nothing", i.e. use sold-out and cheap driver and in a specific application, and in my opinion this is what it is all about, then by all means it fulfils its role. With a budget close to zero, circuit simplifications are necessary, and the author rightly points out (and demonstrates in practice) the influence of the parameter often overlooked by beginners, which is the minimum gate-source voltage causing the transistor to open "fully". It would only be advisable to sharply reduce the value of the resistance in the collector, as pointed out by the "pre-writers" ;)

Topic summary

The discussion revolves around using MOSFETs controlled by a 3.3V signal from an ESP8266 to create a WiFi-controlled dimmer. The author emphasizes the importance of gate voltage and presents a simplified method for beginners to utilize free transistors salvaged from old electronics. Various responses critique the approach, highlighting issues such as the need for dedicated MOSFET drivers for higher frequencies, the significance of gate capacitance, and the potential heating problems due to slow gate charging with high resistance. Suggestions for circuit improvements, including the use of diodes for protection and considerations for PWM frequency, are also discussed. The conversation reflects a balance between practical application and theoretical understanding, aiming to motivate newcomers to explore electronics.
Summary generated by the language model.
ADVERTISEMENT