PWM Fan control with ESP32

In my case, using 4pin fans (dell/server) I have not needed a level shifter, datasheet for my fans say they want 3.3v PWM at 25Khz (above human hearing) which esp32 can do but esp8266 cannot.
You need to manually set PWM frequency in esphome to 25000hz, some fans also require min_pwm 0.3 (30%) to get them going from a dead stop

Beware the tachometer output is usually pulsed 12V, which will probably kill ESP without a voltage divider circuit, so triple check you have everything hooked up properly before applying power

1 Like

Great post! I want to make exactly that - control a 12V PWM fan with ESP from HA. One question: did someone solve the inverted levels? Why are the levels backwards?

1 Like

Default behaviour of the fans when they don’t recieve a PWM signal (0% duty cycle) they failsafe into a full speed setting.
Using LEDC the fans work as expected, but again I’m not using level shifters and always send them a minimum PWM value so they start reliably and don’t go into failsafe

1 Like

I assembled this thing today. Used Arctic PWM fan + level shifter + voltage regulator which lowers 12V to 5V to power the ESP32 and provides the reference voltage for the level shifter. It mostly works correctly. No inverted control in HA, but there’s one problem: when I set the speed to 0 in HA the fan still spins at a low speed. It doesn’t stop. Any ideas?? I don’t want to add a relay to cut the power off.
What can be wrong?

Hey there, I came across this thread by chance. Apparently, some fans can’t be turned off using PWM and just have a minimum speed. Noctua can be turned off.

Hello together, since reddit is currently not working and I cant see my post there I’m also posting here. I hope here are some ESP experts around which could help me out.

This is my “first” big ESP project. 3 years ago I build BRUHs Multisensor but thats basically just putting things together.

What I want to archive is basically this but with temperature & PWM controlled fans monitored by HomeAssistant

r/homeassistant - Need help building a radiator booster with ESP32 and PC fans

I’m by far no expert in this topic but I hope that I have enough knowlegde to archive this.This was my fist time using fritzing so please dont blame me :slight_smile:

That’s what I currently have. But I’m unsure if its wired correctly. The GPIO Pins were randomly connected because I dont know which pins I must connect.

r/homeassistant - Need help building a radiator booster with ESP32 and PC fans

The thing should be powered by a 12V power adapter. A Buck converter will step this down to 5V to power the ESP32. The mosfet driver is just a placeholder (couldnt find a proper one in fritzing) the correct should be the one in the picture. The DS18B20 will measure the incomming water temperature of the radiator. When there are high temperatures, the fans should spin up. Since I’m going to use Arctic fans which cant be turned off via PWM I hooked up a relais to cut the 12V to the fan.

So, my questions are: Is this wired up correctly or will the hole thing explode?

And: Which pins must be used to control the relais, monitor the sensor and sent the PWM signal?

Do you have other recommendations how to archiv this? The mosfet driver could possibly replaced by a level shifter and PWM fans but i haven’t found any informations about hz or voltage for the PWM signal of the Arctic fans.

1 Like

Controlling your fan by true PWM is more efficient than having a mosfet controlling the power to the fan. You only need a 3.3V to 5v logic convertor (cheap transistor(s) and some resistors). Fan PWM is 5V. You can also connect Tach-wire to ESP32 as input with pulse_counter sensor to get RPM-readings.

PWM-fan: Ground, 12V, Tach, PWM. Google “Pinout PWM fan” ,

logic level convertor something like; Simple Level Shifter With Transistors (3.3V-5V) Probably you can use a single 2n3904 BUT you have to invert PWM signal. Possible with ESPHome as property for output component. So get rid of first transistor in schematic.

2 Likes

I’ve got a question concerning speed fan component within ESPHome. When configuring this component in ESPHome Home Assistant only exposes a toggle button. I’m missing a slider-control.

Within homeassistant MQTT-topics this component config is;

{
  "speed_level_command_topic":  "home/esph_pwm_fans/fan/fan_esph_pwm_fans/speed_level/command",
  "speed_level_state_topic":    "home/esph_pwm_fans/fan/fan_esph_pwm_fans/speed_level/state",
  "spd_cmd_t":                  "home/esph_pwm_fans/fan/fan_esph_pwm_fans/speed/command",
  "spd_stat_t":                 "home/esph_pwm_fans/fan/fan_esph_pwm_fans/speed/state",
  "name":                       "fan_esph_pwm_fans",
  "stat_t":                     "home/esph_pwm_fans/fan/fan_esph_pwm_fans/state",
  "cmd_t":                      "home/esph_pwm_fans/fan/fan_esph_pwm_fans/command",
  "avty_t":                     "home/esph_pwm_fans/status",
  "uniq_id":                    "ESPfanfan_esph_pwm_fans",
  "dev":                        {
    "ids":                          "246f28ae0bd4",
    "name":                         "esph_pwm_fans",
    "sw":                           "esphome v2021.11.4 Dec  6 2021, 22:09:06",
    "mdl":                          "esp32doit-devkit-v1",
    "mf":                           "espressif"
  }
}
output:
  - platform: ledc
    pin: 
      number: GPIO23
      inverted: false
      mode: OUTPUT
    id: oid1
    frequency: 25000 Hz

fan:
  - platform: speed
    output: oid1
    name: ${fan_name}
    id: ${fan_id}
    speed_count: 100

When submitting a value (between 0 and 100) to speed_level_command_topic (in MQTT Explorer) the FAN Speed is controllable. Why doesn’t Home Assistant show Slider-control?

To reply on my own question. It appears ESPHome dropped Speed fan MQTT support as Home Assistant changed inner workings. Moving to API websocket communication Speed fan slider will be available. Maybe ESPhome is going to fix MQTT support for Speed Fan.

I got the official answer from Noctua:
“5V PWM fan can easily be driven DIRECTLY from ESP32, 3.3V logic is enough. Also there is no need for additional transistor to amplify the PWM signal”.

Actually I have done the power supply with 3 fans - all are 5V PWM, 120mm and 60mm - all are driven directly from GPIOs from ESP32 without any issue.

2 Likes

For anyone who was beating their head against this like I was, don’t forget to link the ground wire from your esp32 and the fan power supply together.

Wasted a good hour scratching my head trying to figure out why this wasn’t working :sweat_smile:

1 Like

I can confirm I’m driving a Noctua NF-S12B off of 3.3V logic right now

newbies mistake :wink:

Just tested the Noctua NF-S12B redux-1200 PWM 12V fan with an ESP32 where the PWM signal is just 3,3V without any issues. The tacho signal works also great and can be easily read via one of the input pins of the ESP32.

1 Like

I’ve read previously that the tacho signal can be 12V pulses. Also read the input pins on ESP32 read 0-5V. Without a step-down, I guess you haven’t fried anything, but I’m curious how the board reacts to the 12V.

Hi all, I’m just popping by to say thanks, following some of the info in here I managed to set up a 5V Noctua NF-A14 on an ESP32 with an RPM counter.

esphome:
  name: pwm-fan
esp32:
  board: esp32dev
  framework:
    type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
  encryption:
    key: "###############################"
ota:
  password: "######################"
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Pwm-Fan Fallback Hotspot"
    password: "#########"
captive_portal:

output:
  - platform: ledc
    pin:
      number: GPIO23
      inverted: false
      mode: OUTPUT
    id: oid1
    frequency: 25000 Hz

fan:
  - platform: speed
    output: oid1
    name: fan_140mm
    id: fan_140mm
    speed_count: 100

sensor:
  - platform: pulse_counter
    pin: 12
    name: "NAS Fan RPM"

The fan 5V is connected to the 5V on the ESP32
Fan GND is on the Board GND
Tacho from the fan is on Pin 12
And the PWM signal to the fan is from Pin 23

I set up an automation to monitor HDD temps from my OMV server and spin the fan up in 4 different increments.

3 Likes

What’s the circuit? You’re not powering the PWM fan directly from the GPIO pin, are you?

I am, shouldn’t I be?

What’s the amperage (current) on the leads? I really want to know. You are allowed to draw max 16 mA from GPIO pins. If your fan consumes more, you will fry your ESP device. This is why most people use transistors with an independent power supply — and the GPIO is used to connect to the base in the transistor so that current activates the transistor.

The fan is 260 mA max so way over the spec.

I haven’t had any issues (yet), and I’m fairly confident it will be OK especially as the fan never goes above 20% anyway and I have run it at 100% during testing.

Looking at this thread on Reddit:

Seems that other users are pulling a lot more current than I am just fine.

I’m not saying its a good idea though, if you do it like I have then its at your own risk, seems the limiting factor is the trace on the board so be careful!