Using ESP32 to control a fan with PWM - Replacing Current MOSFET

I'm using an ESP32 to control a fan through PWM. I'm working with the same fan as in this thread. The fan runs on +10V.

I found a long discussion about this fan on another forum and the basic control circuit was something close to this:


Since the manufacturer uses a USB-C cable to connect the controller to the fan, I'm using the same for my controller. (So I don't have to open up the control box on the fan for final wiring.)

The diagrams I'm working from do not include any resistors and I've wired this up as-is and it works. This is my MOSFET wiring diagram:


I'm using a common ground for the ESP32 and the fan. (In fact, I use the +10V line, running through a regulator, to power the ESP32, so I don't have to plug in an adaptor to power it.)

This mayseem picky, but I wanted to replace this MOSFET gate with something smaller and more easily attached to a PCB or something I could easily put in a breadboard for prototyping and experimentation. I'm new to this kind of thing, but did find a few pages reference the IRLB8721. I've also found these are available easily from Amazon. Seems like it'd be easier to use the IRLB8721 than what I'm using now (in terms of part handling and placement).

Can I use this as a replacement for the MOSFET gate in the wiring diagram I included above? And if so, can I do it directly, without adding more components, or do I need to add a resistor or two in there? If so, why and how do I calculate the values for them? (I really want to understand what I'm doing, instead of just popping in the right parts - knowing the parts is good, but I also want to know how they're determined.)

Also, I saw a reference somewhere on a page I was looking at that the signal out from the MOSFET might be inverted. Would it be? (If so, I'm using ESPHhome, which would let me just invert the output on the GPIO pin.)

1 Like

You need an external power supply, the esp32 can not provide that much power. Only the mosfet Gate terminal is connected to the esp32 plus G of course.

Right, that's what I'm doing now. The ESP32 only controls the switch.

So are you saying if I wire it that way, the IRLB8721 could do it?

I don't know the specs on the IRLB8721 but if it's ok, then disconnecting the red wire from the esp32 VCC and putting it on an external power supply will work.

Oh - I see what I did. I have a bunch of white boards I use for diagrams and sketches and when I'm done with a sketch, I take a photo of it so I can study it when not in my shop. I posted the wrong diagram!

While the part about the MOSFET is right in the sketch, the power supply is something I was looking into for powering the ESP32 from the fan power supply. (Others who have done similar have said they've done that.) So, first, the Vcc line there would come from the fan and would include a voltage regulator before going into the ESP32. Second, it's the wrong photo! Just imagine that the red line does NOT connect to the ESP32 and is +10V, which the fan uses for PWM with its factory made controller. Oops!

But your info helps a lot, so I'm going to check the numbers on it now. Thanks!

The part I'm not clear about, in this kind of situation, is if I have to use resistors in a circuit to pull up or pull down the voltage at any point. I would think there would be no need for anything like that in this case, since the signal from the ESP is just low or high and, on the other side, the output going to the fan is supposed to be +10V, the full value of the power line.

You are right, there is a pull down resistor between ground and gate so that a HIGH turns on the N-Channel MOSFET. Here is my crib note from DBWS.

Thank you!

A few questions, for my understanding (I'm such a newbie!) - I really am trying to learn what I'm doing so I'm not just copying and pasting to make things work.

  • If I invert the output from the ESP32, then do I still need a pull down resistor?
  • Can I use a P-Channel MOSFET and also eliminate the need for the resistor?

And what is DBWS?

The pull down resistor is needed. This circuit is a low side switch, a P channel is used for a high side.
what you need is a basic course in transistors and MOSFETS if you want to be able to do more than copy. There are no shortcuts, my training lasted for many years

I get that. I started reading up on electronics and putting together kits in the 70s, before I was even in my teens, but I never had the time to just really focus on it and learn the things I wanted to. So now that I have more time to experiment, I can finally do things other than solder together kits - but I realize I know, in terms of practical usage, very, very little.

This was a big help - I had never heard of the term "high side," so I looked up high side and low side and found out what they mean. That's when I realized I don't know for sure if, in this circuit, I am using a high side switch or low side. A lot of the info I find on controlling this fan is from non-authoritative resources. I think they all mean well, but I haven't seen any indication the people I'm talking to are more than hobbyists.

This is the MOSFET switch I'm replacing in the circuit. Once I read your use of high side, I realized there were conditions for using a P channel and for an N channel, so I looked up "high side switch vs low side switch," figured that out, then looked up the info on the MOSFET switch in the link above and found nothing about whether it was P or N channel, or if it's for high side or low side.

And that makes me realize I don't know if this MOSFET we're discussing is a replacement for what I'm using now. One reason I want to replace it is size. I want to be able to control 4 fans from one ESP32. The MOSFET switch I'm using now is big and fitting 4 in a box would make the box a lot bigger than if I can just use a single one, with three pins, that easily goes into a breadboard or a PCB.

Is this single MOSFET (the IRLB8721) even a viable replacement for the other one?

I also considered using an optocoupler, but I understand those are slow compared to a MOSFET. (Although if it's used in a cycle, and the delay is the same rising and falling on a square wave, I would think it'd work - the cycle would just be a bit delayed on the output side. Still, seems people don't like optocouplers for that kind of work.)

I studied over the webpage on the original MOSFET and they include this diagram:

And this one of a sketched schematic of what's inside the switch:
image

I could be way off, but that makes me think that, in this application, the +10V going to the VOUT+, then the signal is coming out of the VOUT-, and, from there, going to the load (the fan), indicating it's a high side switch, as discussed. If that's right, then I would think I could use the IRLB8721like this:

MOSFET-Changed
I left the pull-down resistor out, since I was just doing a quick diagram by editing the one provided on the page on the MOSFET I'm replacing.

Am I even close on this?

You always have to try to find the schematic and datasheet of the relevant parts. Searching in google I found this. I think that this is the module:


And the datasheet of the mosfets.

You can see that they are N-channel mosfets and it's low side.

No, I think that it's low side. The source lead of the mosfets is connected to GND, so they disconnect the load from GND.

No, that will not work with an N-channel mosfet.
To activate an N-Channel mosfet the voltage drop between gate and source, Vgs, has to be positive, about 5V. In this case you have +10V at the source, so you should apply about 15V to the gate to activate it, what is not posible, or not easy.

Besides that, these mosfets AOD4184A and IRLB8721, are specify to work at 4.5V or more, but not at 3.3V. They will somehow work, but could heat up. They mention that in the web I linked above.

That's because of the Rds(on) parameter in datasheet:


They specify the resistance at 4.5V or more, but they don't say anything about 3.3V. The resistance will be higher, maybe not a lot, but we don't know. For a mosfet you always have to check this parameter.

If you want to practice, I would recomend to get a couple of mosfets, not the boards but the mosfets, and do some experiments just with an Arduino, the mosfet and an LED+resistor. Try both high and low side configurations.

What is the fan's full load current?

IRLB8721

mtr_mosfet

Yes, so the sketch I found was nowhere near as complete or useful. So what did you use to specify that particular part? It seemed to me that what I saw for the identifying info was just ratings and capacities. Just "High Power Dual MOS Tube Transistor MOSFET" or similar searches weren't turning up anything more than sale links for it.

Is that a rule I can follow? That if the source connects and the drain to Vcc or positive, that it's low side and it's N-channel? And if the source connects to positive and the drain to GND, it's high side and P-channel?

Ah - I see, now. I was treating the entire part as one component and wasn't thinking of looking for the parts on the circuit board. That's a mistake I won't make again.

So, I take it, I need to get an N-channel MOSFET for this, and I can't just get the AOD4184A because it's rated for 4.5V and up and the same with the IRLB8721. I was looking for maximum ratings and it didn't occur to me to look for the input voltage it needed - that the 3.3V could be too small. (And I'd like to confirm, the IRLB8721 is N-channel, so it will work for low side, BUT it needs more than 3.3V and that makes it unsuitable for this use.

Not even .25 mA - which seemed low. (Is it - again, I'm still dangerous with how little I know!)


In a question I asked in another post, someone said the line is probably not actually powering the fan, but just providing the control pulse, so maybe that is an accurate measurement? (I measured from the VOUT+ to the ground.)

From what I'm getting from this, I need an N-Channel MOSFET that can be triggered with 3.3V, can handle the current drawn on the line (I would think if it handles 1 amp or more, that'd be enough), and that it can handle +10V input. Am I right on those specs? And once I find the MOSFET, how do I calculate what value I need for a pull down resistor?

Not exactly. That is how it should look like:

  • In the low side configuration the mosfet is 'below' the load, and it disconnects it by cutting the connection between the load and GND.

  • In the high side configuration the mosfet is 'above' the load, and it disconnects it by cutting the connection between the load and VCC.

And what matters is Vgs, so the voltage between the Gate and Source leads of the mosfet, to open or close it.

1 Like

I googled for: dual mosfet module. And checking the photos I found this page: High-Power Dual MOSFET Switch Module - ProtoSupplies
I think that it's the same module, but could be a similar one or a clone with other components. You could check with a magnifier the labels of the mosfets in yours.

Check all the explanation in that page, the part about the 3.3V levels.
In my opinion they should advertise it only for 5V level, not for 3.3V. But with low currents and something not critical can work.

Was that at the fastest speed?
If yes, then all you need is one transistor and one resistor.

That's how you measure voltage, not how you measure current.
So repeat you measurement with multimeter in series with VOUT.

Also, If you still have confusion with high/low side switching, look at the hand drawing circuit you did on post#12. You see that positive side is not connected anywhere on the circuit. You don't need to wire positive side to your module, just take it straight to the load.
So it's quite obvious that you are switching low side. All the common mosfet modules available are low side switches (NPN).

And even if it's 100x higher, that might be valid option.