PWM controlled fan with ESPhome on ESP32

No it should not need more Amp than this. Nor sure why this does not work for you @dominate4life

Afternoon,

How did you work out the frequency for this?
I have the same MOS Module and I have 2 x 12v Fans connected and everything works great.

The problem I have is I want to control a 12v DC water pump that pulls 8A max. I purchased a XY-MOS that supports 400w 15A (https://www.robotics.org.za/XY-MOS) but I’m just not sure what Frequency to use in esphome or how to work it out. Google is telling me 0 - 20 Mhz supported signal frequency. is it that simple?

Yes I just tried different frequencies until I got the results I wanted. Trial and error :slight_smile:

Following this up

Apologies for posting on this thread, but it’s the only one that I can find that makes mention of using an ESP8266 at 2KHz.

@tom_l I have recently got an ESP8266 with integrated fets (Sinilink XY-WFMS), and have been trying to control a 5V fan in the same way @corvy is.

I’ve used this thread as a rough guide and have noticed that I get coil whine at low freqs as you mentioned above. I set the frequency to 20KHz as you suggested, but I lose speed control all together. I also noticed you set your frequency to 20KHz in your example. I’ve read the ESP8266 isn’t capable of going above about 2KHz due to it’s software PWM. There is an alternative PWM implementation that claims to combat this, but it’s not available in ESPhome at the moment. I opened a feature request, hopefully It is of interest to the devs.

How are you able to run an ESP8266 at 20KHz? Or was this just an example for Corvy’s setup?

1 Like

No it’s what I used. I’ve never actually hooked an oscilloscope up to it to check what frequency it is outputting but it works.

I’m not using MOSFETs, just a GP transistor. See here: HA Fireplace Light

And after refreshing my memory with that thread it seems the output is about 14kHz.

Where did you read that?

Thanks for the info. I read it in a blog post by the author of the improved PWM implementation:

Blog post: https://lurchi.wordpress.com/2016/06/29/esp8266-pwm-revisited-and-reimplemented/
Git: https://github.com/StefanBruens/ESP8266_new_pwm

The problem I am having is that I cannot get the fan to have low/med/high speeds as well as no whining on low speeds. If I set the freq to 20KHz, low/med/high are all the same. I tried setting varying integers for the speed in the ESPhome config (0.01 to 0.99 and many in between), but it’s only if I reduce it to about 2KHz that I get speed control back but the lower speeds are terribly whiny.

I’m trying to decide what the best option would be. I have a couple of 5V USB fans (2 wire) that I have gutted and want to replace their PCBs with a HA controllable alternative. The Sinilink XY-WFMS seemed great, but I cannot get it to perform as it did with the fan’s own board. I tried Tasmota to start, but the slider in the Tasmota UI was only useful for the last 10% or so. Anything below that was whiny. I tried adjusting the pwm freq via the console, but it doesn’t appear to go as high as 20KHz, so I moved to ESPhome and whilst I can set the freq to 20KHz, I still cannot get the results I want. A ton of reading led me to the above blog, which has now pushed me towards thinking an ESP32 and fet board may be the better option… Unless you have any suggestions? I am willing to try things before I put an order in for more parts.

@tom_l Some more info: Looks like the limit mentioned in the blog post above is not applicable to ESPhome or Tasmota because they do not use pwm.c from the Expressif SDK, they use the Arduino libs which are greatly improved and can reach 60KHz.

1 Like

Hi! Would you be able to share the hardware you used for this project? Also one question. Would I be able to tie two fans to this to control them with one output? Also I would like to attach a thermostat if possible.

Basically I’m just trying to replace these two loud fans up top here https://www.amazon.com/gp/product/B00P00LFPO/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1 with quiet noctuas. Basically I need very little to no airflow for what’s inside.

Hi, I am trying to make my first project but I am really stuck.
I have an ESP32 board (modell: ESP32-WROOM-32 it says on the box).
I have also bought a MOS Module like the one in the first post.

I would like to do exactly the same, do a PWM controlled fan and integrate it into Hassio but were to start?

I have downloaded esphome-flasher but I haven´t found what to flash on the board. I have read on ESPHOME homepage but I feel totaly lost.

In Hassio I have added the add-on but think I will understand how what/how to flash the board first.
I have used arduino ide and flashed same basic sketch. For example got it to join my WiFi-network.
Is that enought to just get it to connect to my WiFi-network or where should I start?

This is a good place to start. At least I found it to be.

Hope it’s of help.

Hi Akriss, (My question is solved, see EDIT 2 in the bottom, thank you)

That is were I started but I feel dumb like an idiot…
I have added the add on. Then I pressed on “Create New Node” in Hassio.

Node name, I guess this doesn´t matter. I can namned it whatever?
WiFi & Updates, is it my normal wifi ssid and password where Hassio also are connected to?

In the config file. Is this correct?

esphome:
name: fanis
platform: ESP32
board: esp32dev

wifi:
ssid: “XXX”
password: “XXX”

manual_ip:
static_ip: 192.168.0.138
gateway: 192.168.0.1
subnet: 255.255.255.0

When I try to compile and upload I get the following error.

INFO Successfully compiled program.
INFO Connecting to 192.168.0.138
ERROR Connecting to 192.168.0.138:3232 failed: [Errno 111] Connection refused

Do I have to open any ports or how to continue?

EDIT:
Can this depend on that I haven´t connected the board directly to the NUC where Hassio is installed? I have choosed OTA in the ESPHome gui in hassio.

EDIT 2:
I tried to connect directly in my NUC and now I got it running.

How can this project be modified to include the tach wire for rpm reading in home assistant?

1 Like

Maybe try this:

Just found this topic and it is exact what i need. SO I tried finding the right components but struggle a bit.

I found without problems the esp8266 but here comes the first problem. I read that esp only needs 3,3v, so I can not use a simple USB Power adapter, correct?
Second thing was the part where I connect the power for the fan, 12v. But that was easy after rotating and scaling the image a bit. :slight_smile:
So what power supply should I use for the fans? I find a lot 12v power supply but not sure wich to use.
And is there an option without cutting the cords from the fans?

Oh and what is the board in the latest post with the image called?

Hello all,

I have also installed a FAN on my system.

Hardware: ESP32 + Mos Module

Everything works, except that ON is OFF / OFF is ON and slider 100 = 0 V and 0 = 24V.

So just the other way round.

How can I change this setting? And it is possible to start by 10V → Slider 0-100 because with 2 or3 V my fan will not start.

ESP Config:

output:
  - platform: ledc
    pin: GPIO19
    frequency: 100 Hz
    id: ventilation_fan_pwm

fan:
  - platform: speed
    output: ventilation_fan_pwm
    name: "Basement Ventilation Fan"

ESPHOME Version 1.72
HA: 2021-5-2

How did you wire it up ?

For my ON / OFF problem , I found a solution :slight_smile:

inverted: True - But now I fighting with the MIN an MAX value

Wire - Should fit - otherwise the motor would not move - right?

output:
  - platform: ledc
    pin: GPIO19
    frequency: 5 Hz
    id: ventilation_fan_pwm
    inverted: True

How come your frequency is so low ? I have mine set to 10000 Hz

With 10000HZ the motor does not work. I have a 24V DC PC fan that I have as a fan in the house wall.