PWM controlled fan with ESPhome on ESP32

Thanks , will try that

How you use it depends on how you wired it. How are you changing directions? Or oscillating really but, you can use eirher.

Ok, got it.
Speed is pwm pin on controller and GPIO 2 on esp
Direction is dir pin on controller and gpio 4 on esp , should be high or low

No idee how to code this
something like this?

    direction_output:
    on_turn_on:
      - output.turn_on: fan_direction
      - logger.log: "Fan Dir Left"
    on_turn_off:
      - output.turn_off: fan_direction
      - logger.log: "Fan Dir Right"

Solution was simpeler:


switch:
  - platform: gpio
    pin: D4
    id: fandirection
    name : ${friendly_name} Direction

Thanks anyway

Hi guys,

I would like to run a

  • ESP32 ( ESP32-DevKitC core Board ESP32 Development Board ESP32-WROOM-32DWiFi+Bluetooth Compatible IoT NodeMCU-32 with 38Pins ESP32 Type-C USB and Micro USB Expansion Board)
  • ANVISION DC 24V 40mm x 10mm Brushless Cooling Fan, Dual Ball Bearing, 2 Pin

Reading the messages above, it seems like I need a Mos Fet to connect them together and also control the fan speed.

Couple of questions here for a newbie on this subject:

  • Can I use my 24V transformer to power the fan and the ESP32 and the Mos Fet?
  • This Mos Fet ( Trigger Switch Drive Module DC 5V-36V PWM Adjustment Electronic Switch Control Board 15A Max 30A 0-20KHz ) states up to 36V but if you read the detailed specs, it says max DC input is 20V. This means my door bell transformer would overload this Mos Fet. Right?
  • This Mos Fet listed above states it has an ESP32-C3 embedded. Do I still need my ESP32 WROOM then, if this Mos Fet already has a ESP32-C3 embedded?

If this is not the right Mos Fet, please point me to the right one. I would appreciate that.

Thanks in advance guys for any help on this subject.

You didnt quite get that right. The mosfet module has specifications for both Input and Output that are separate but, you’re mixing them up.

Input is 3.3v - 20v and this the control voltage that coltrols the output. Your using an esp32 which outputs 3.3v from its gpios. No problems here.

Output is 5v - 36v and this is the min/max of voltage you can control. So, using an esp32 youd be using 3.3v to control 36v. Your well within the specifications if your using a 24v fan

Short answer is Yes. A lot of door bell transformers use 24v AC and some use DC so, you’ll need to find out which one you have for sure. You can use either AC or DC it doesn’t matter but, obviously they will be a different process and have different components.

It would be more ideal if its a 24VDC that youd just need to use another transformer or voltage regulator to turn that 24 into the 5v needed for an esp32 and 5v is the maximum voltage. Giving an answer for it also powering the fan is a little harder. That depends on how much current/watts the door bell transformer can output and if the needed amps/watts of the fan are less than what the transformer is capable of. So. If the transformer can only output 50w and the fan needs 75w… Thats a problem obviously.

Do us a favor and copy/paste or repost the product link your talking about and honestly, If someone is going to help you then help them by not making them go on a scavenger hunt looking through hundreds of posts for whatever product your referring to. It also avoids any confusion in the event multiple products are mentioned above.

Im not exactly sure what your talking about but, it doesn’t sound right. An esp32 embedded in a mosfet doesn’t make any sense. Now there are all sorts of esp32 pcb boards that come in all sorts of configuration like onboard regulator with 1 or multiple relays or whatever, just like this example.

Are you talking about something like this except it has 1 or multiple mosfets? Unfortunately esp8266/esp32 pcb’s with mosfets arent nearly as common as most other types like relay modules so, I dont have much information there.

Ive never used this and cant speak to how well this works but, it looks like it would work well for your project.

It has a voltage regulator so it can be directly powered from 12v or 28v. It has multiple mosfets built-in and could control multiple motors(fans) or they can be used to drive LED lights and your fan for example. It also has wifi and Bluetooth so it could be used for presence detection and has free gpio pins that you could tap into for whatever you want in addition to a fan or may want for a future project, you’ll have that option available.

It also comes with 2 INA240A2 high-precision current sensors to measure and track power being used through the mosfets. Im not 100% sure if that particular INAxxx sensor is fully supported by esphome right now though, full disclosure.

It may be added later or someone could help with if you went that route also. You could also choose to not use the current/power sensors and just use the mosfet to drive the fan FYI. Its just nice having those extra features built-in that’s all.

This esp32 pcb looks really good on paper to me for whatever its worth. Something like this is also a lot easier to install since its a single board. The alternative is you would need a laundry list of parts and components that all need wired together and individually installed in the available space.

Thank you so much for all this input. I will study your information and get back to you. I appreciate your fast turnaround.

I didn’t want to post all kind of links as in other forums this is frowned upon on, but now I know, that I can post them for more detailed inquiries.

Thanks again.

No thanks necessary, ill send you a bill instead.

Oh, not here! Post away! Its actually very important because there are so many sensors, devices, MCU’s all made by different manufacturers and can vary in specifications, capabilities and limitations so, anytime you can include a link, model number, or even photos it allows everyone to be on the same page and not potentially making wrong assumptions that wont help you at all!

The more details you provide, the better people can help you.

If you ask a question like, “I got this temperature sensor and i cant get it to work. What am I doing wrong?”

Nobody knows what the flipping hell your talking about and unfortunately, you’ll see questions like frequently.

Your question was well laid out into individual bullet points and easy to address each one so, excellent job with that, I liked it. If its obvious someone is really trying then atleast for me, ill put in a higher effort and time to help.