Controlling 5V brushless dc fan with ESP32

Hi
I wanted to ask the experts about something that I think should not be extra hard to do but since I am an amateur in electronics it is quite baffling to me.
I have a 5V brushless fan that I would like to control with my ESP32 board. Since it uses 5V I should be able to power it with the ESP board.
I'll upload an image of the wiring I've done.
Fan_mosfet (1)

So basically I've connected +5V to the fan's positive with a diode between. and the negative side I've connected to the drain of a BS170 N channel mosfet and the source to ground. Then I connect a GPIO pin to the gate.
I am using PWM to control the fan speed, now I am only using two settings 255 or full load and 0. When I turn on the esp the fan spins at like 70%, because it's only getting like 4V because of the diode voltage drop. I use a button to toggle between 255 and 0 duty cycles, when I press the button to switch to 0 the fan slows down but does not completely stop. There is still about 1.7V going to the fan from the power source, however the voltage between source and gate is 0.

Am I hooking up the fan incorrectly? Why does it not turn off completely.

  • Why the series diode ?

This MOSFET will not work with a 3V3 ESP32.

You need a 3V3 logic level MOSFET.

It’s likely the ESP 5V power supply will not have sufficient current capacity to power motors.

I was told that motors and fans can produce kickback that can damage the esp if it's not protected with a diode, maybe I misunderstood :slight_smile:
But you say this mosfet is not fit for esp32, can you suggest some model that is?

  • The diodes goes across the motor, not in series.

  • For these small fans, select a MOSFET that has a low Rds(on), from Vgs = 2.5v to 5v.

  • You need a 5v power supply that can supply sufficient current.

  • What is the current rating of the motors ?

https://aws1.discourse-cdn.com/arduino/original/3X/7/2/7253db9f14a32e3568824488ca7d3ba8cae7aea6.pdf

I suggest you read this. Perry Bebbington did an excellent illustrated article on Flyback diodes and why you need them which includes diode placement.

Next when you find the suggested MOSFET you want about a 10K resistor gate to ground. Actually if this is a low current motor I would just consider a common NPN switching transistor like a 2N2222 rather than worry about the voltage gate source of a MOSFET. I would not power the motor using the ESP32 board.

Ron

1 Like

If it is a brushless fan it probably already has electronics in it including flyback diodes, and may not be properly speed controlled by pwm.

can you share the code

There is no code. The code for what the OP was trying is trivial.

But you've raised a dead thread. From the dead.

Start a new thread and tell us where you are at and why you can't get from there to wherever it is you want to end up.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.