Wemos D1 mini and IRF520 fan doesn't work

Hello everyone, I have the following problem:

When I measure the IRF520 output I get 12V but as soon, as the fan is connected the voltage drops to 2V and doesn’t work.

It is a 12V fan with 1,9W.


What am I doing wrong?

esphome:
  name: fan
  friendly_name: fan

esp8266:
  board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "SMyhtms8gs0YfLDF/Zq4jId2Dt8SUC77Cpc78H88MR0="

ota:
  - platform: esphome
    password: "3c31edbc642678e7facd7e6e5666ce2f"

wifi:
  networks:
  - ssid: !secret wifi_ssid
    password: !secret wifi_password
  - ssid: !secret wifi_ssid_cellar
    password: !secret wifi_password_cellar

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "fan"
    password: "5xxolZaDMmHM"

# Enable Web server
web_server:
  port: 80

# IRF520 Mosfet 
output:
  - platform: esp8266_pwm
    pin: D6
    frequency: 25000 Hz
    id: pwm_fan

# Lüfter
fan:
  - platform: speed
    output: pwm_fan
    name: Lüfter
    id: fan
    
sensor:
# Temperature Sensor
  - platform: dht
    model: DHT22
    pin: D0
    update_interval: 5s 
    temperature:
      name: Temperatur 
    humidity:
      name: Luftfeuchtigkeit

I think that irf520 isn’t made for working with 3.3V on gate, it’s not logic level mosfef. It requires bigger voltage to be fully open. Now it’s only partial opened, so when you load it most of energy is spent on mosfet itself. Either try with different mosfet (search for logic level mosfet) or insert some kind of driver between esp output and gate of the mosfet (npn…).

The IRF520 is indeed a terrible mosfet for this application. Sometimes you get away with it if you have a small load but 3v3 is a very low gate voltage for that mosfet.

But I also spot a flaw looking at the code and the image… In the drawing you connect the fan to D5, but you use D6 in the code :slight_smile: Also, 25kHz seems very high, try 1000Hz.