patrickcollins12 / esphome-fan-controller

ESPHome Fan Controller
382 stars 41 forks source link

make fan stop spinning at zero #17

Open sobrarbe opened 1 year ago

sobrarbe commented 1 year ago

Hello, I just installed a Corsair ML120 fan as you say and it works well except for the one when it reaches the stop temperature and it keeps turning at 1400 RPM. Could you help me create a stop or what parameters can I change to make it stop? the adjustments that you had at 13% the stop changed it to 0% but it continues turning. could you help me?? thank you.

patrickcollins12 commented 2 months ago

OK, so I have two fans, I unplugged one and plugged in the Arctic P12 Slim PWM PST. It stopped spinning at 0 power for me.

https://github.com/patrickcollins12/esphome-fan-controller/assets/942296/28a32c41-11d0-4a82-bcf9-c58a802ff4bd

image
patrickcollins12 commented 2 months ago

@DeDiConsulting I suspect there might be something wrong with your circuit. Like for instance, joining the two ground lines together. The 12v and 5v lines need to be earthed together. If that's not the issue can you share your circuit with a diagram and photo?

DeDiConsulting commented 2 months ago

oh oooh ... i think i forgot to join the ground of the 12V & the 5V. i will check this tomorrow ....

DeDiConsulting commented 2 months ago

i can confirm, my bad. as i was firing up the esp8266 from usb, from other power source, i forgot to join the grounds. Once i did this, its working fine! doh... how could i forget that .... Many thanks to everyone who jumped in right away

patrickcollins12 commented 2 months ago

I'm actually glad the solution was that simple because a lot of people have had this issue. I'm also glad that people don't have to add a mosfet because that impacts the simplicity of this project.

How can we adjust the instructions to be much clearer on this topic? Feel free to suggest or make a pull request.

BasJansen commented 2 months ago

I have my Corsair fan now replaced with an Arctic above and it just works. So I guess some people still need a mosfet solution but you can always buy this affordable fan.

patrickcollins12 commented 2 months ago

@BasJansen any chance you can test both fans with and without the grounds connected?

BasJansen commented 2 months ago

I tested both fans with and without ground connected. There seems to be no difference in behavior with or without. Corsair fan: always spins, even when the esp32 did not totally boot. In the web interface I can switch it on and can speed it up or slow it down but not stop it. Arctic fan: stays off until I switch it on in the web interface. In the web interface I can speed it up and down.

patrickcollins12 commented 2 months ago

We're all getting inconsistent results. My Corsair works fine. @DeDiConsulting arctic keeps spinning, but works when grounded properly.

BasJansen commented 2 months ago

Strange maybe we can make a small fan only project. Get all the noise away and try to get something consistent

On Thu, 13 Jun 2024, 15:00 Patrick Collins, @.***> wrote:

We're all getting inconsistent results. My Corsair works fine. @DeDiConsulting https://github.com/DeDiConsulting arctic keeps spinning, but works when grounded properly.

— Reply to this email directly, view it on GitHub https://github.com/patrickcollins12/esphome-fan-controller/issues/17#issuecomment-2165601216, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA5N5DT2ELXGJVWWL7CIG3ZHGJWDAVCNFSM6AAAAAAW5OI5POVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNRVGYYDCMRRGY . You are receiving this because you were mentioned.Message ID: @.***>

mainmind83 commented 1 month ago

664 RPM wich NXZT 140mm fan 🥴 I'll test with another fan...

corgan2222 commented 1 month ago

550RPM with NZXT 120mm. Have to buy the mosfet. :/

mainmind83 commented 1 month ago

Here is my recommendation. It should work fine.

Buy a logic-level mosfet. I would recommend either the IRLZ44N or FQP30N06L.

The fan's power needs to connect to the Drain pin of the MOSFET. The other side of the, the Source, needs to connect to the 12v power ground.

Gate: Connect to the ESP32's GPIO (possibly through a small resistor, like 100Ω to 220Ω, for gate drive protection). Drain: Connect to the negative (or ground) side of the fan. Source: Connect directly to the circuit ground (0V).

Remember, the ground of the microcontroller should be connected to the same ground as the MOSFET and the fan.

Flyback Diode: It's good practice to place a diode (like the 1N4007) in parallel with the fan, but oriented in such a way that it normally doesn't conduct (anode to the fan's negative terminal and cathode to the fan's positive terminal). This diode will protect the MOSFET from voltage spikes that can occur when the fan is turned off due to inductive kickback.

Assuming you use GPIO PIN 25 for the MOSFET gate, your YAML would be as follows:


# this power supply is turned on/off when the output below
# meets the min_power.
power_supply:
  - id: mosfet_power_supply
    pin: GPIO25

output:
  # Wire this pin (13) into the PWM pin of your 12v fan
  # ledc is the name of the pwm output system on an esp32
  - platform: ledc
    id: console_fan_speed
    pin: GPIO13

    power_supply: mosfet_power_supply

    # 25KHz is standard PC fan frequency, minimises buzzing
    frequency: "25000 Hz" 

    # my fans stop working below 13% powerful.
    # also they're  powerful and loud, cap their max speed to 80%
    min_power: 13%
    max_power: 80%

Please test this and if it works, I'll add it to the documentation,

adds a graphical scheme for electronics newbies :D

BasJansen commented 1 month ago

I don't think this works. The fan has no 12V + power and also the diode is not there. What I understand (and I'm totally new to this so I might be totally wrong) the diode is only needed for some extra protection. When the power switches of the fan it will still spins and if a motor spins it generates power and this power shouldn't go to your esp32 board. But I also don't understand how the fan will get it's 12v power and how the Mosfet should be connected (sorry mainmind83)

mainmind83 commented 1 month ago

Waiting @patrickcollins12 ;D

patrickcollins12 commented 1 month ago

Doesn't look right, nothing connecting the mosfet to 12v. I won't have a chance to build and test this got a while. I suggest someone has a go and sends back the fritzing diagram that works

mainmind83 commented 1 month ago

Did I understand this correct?

@corgan2222 please hide wrong scheme 🙄😉

corgan2222 commented 1 month ago

I gave up on the Mosfet approach and now use a simple relay like this guy https://www.speaktothegeek.co.uk/2023/01/esphome-fan-v3-variable-speed-pwm-and-temperature-control/ For my usecase this works fine, because I use this fan in my cellar. But, I can imagine, that the clicking of the relay may be too loud for a living room installation.

BasJansen commented 1 month ago

I think I now know how it can be done. Please keep in mind I'm a noob, Don't know anything about electronics and all credits go to https://electronics.stackexchange.com/users/68839/sergiu-reznicencu for his answer in tread https://electronics.stackexchange.com/questions/521154/verifying-schematic-idea-circuit-design-for-mosfet-driven-by-esp32.

I made 2 projects. First one for a fan which stops by itself (faneasy) and one that uses a Mosfet to stop the fan (fanhard). So check the easy project first and if the fan keeps spinning go for the mosfet solution.

Faneasy

image

It uses this code

substitutions:  
  PIN_PWM:   GPIO26    # Green          
  PIN_Tach:  GPIO25    # Blue        

esphome:
  name: faneasy

esp32:
  board: esp32dev

logger:  

api:

ota:
  platform: esphome

wifi:
  # Read the wifi/pass from secrets.yaml:
  # wifi_ssid: "My Wifi XX"
  # wifi_password: "XXXXXXX"
  ssid: !secret wifi_ssid
  password: !secret wifi_password  
  fast_connect: true
  power_save_mode: NONE

web_server:  

sensor:  
  # Read the Tacho PIN and show measured RPM as a sensor (only with 4-pin PWM fans!)
  - platform: pulse_counter
    id: fan_speed
    name: Fan Speed
    pin: 
      number: $PIN_Tach   # Connect to any input PIN on the ESP
      mode: INPUT_PULLUP    
    unit_of_measurement: 'RPM'
    update_interval: 5s         
    accuracy_decimals: 0
    filters:
      - multiply: 0.5  # Depending on how many pulses the fan sends per round - should be 0.5 or 1 - try... 

output:
  # ledc is the name of the pwm output system on an esp32
  - platform: ledc
    id: PWM_output
    pin: $PIN_PWM
    # 25KHz is standard PC fan frequency, minimises buzzing
    frequency: "25000 Hz"     
    zero_means_zero: true 

fan:
  - platform: speed
    id: fan_1
    output: PWM_output
    name: "Fan"     

Fanhard

image

ps: the original schema uses a resistor of 110 Ohm but I didn't have one so I used a 220 Ohm and it still works.

substitutions:  
  PIN_PWM:   GPIO26    # Green          
  PIN_Tach:  GPIO25    # Blue      
  PIN_ONOFF: GPIO33    # Orange

esphome:
  name: fanhard

esp32:
  board: esp32dev

logger:  

api:

ota:
  platform: esphome

wifi:  
  ssid: !secret wifi_ssid
  password: !secret wifi_password  
  fast_connect: true
  power_save_mode: NONE

web_server:  

sensor:    
  - platform: pulse_counter
    id: fan_speed
    name: Fan Speed
    pin: 
      number: $PIN_Tach   # Connect to any input PIN on the ESP
      mode: INPUT_PULLUP    
    unit_of_measurement: 'RPM'
    update_interval: 5s         
    accuracy_decimals: 0
    filters:
      - multiply: 0.5  # Depending on how many pulses the fan sends per round - should be 0.5 or 1 - try... 

output:  
  # ledc is the name of the pwm output system on an esp32
  - platform: ledc
    id: PWM_output
    pin: $PIN_PWM
    # 25KHz is standard PC fan frequency, minimises buzzing
    frequency: "25000 Hz"     
    zero_means_zero: true

  - platform: gpio
    pin: $PIN_ONOFF
    id: 'OnOffFan'  

fan:
  - platform: speed
    id: manual_fan_control
    output: PWM_output
    name: "Fan"
    on_turn_on:    
    - output.turn_on: OnOffFan
    on_turn_off:    
    - output.turn_off: OnOffFan

Please let me know if something can be improved.

patrickcollins12 commented 1 month ago

I have these components, I will test it and publish it.

patrickcollins12 commented 1 month ago

Did you know also with this schema you can use the mosfet as the pwm and you don't need a pwm fan. Could be helpful for people who have a 3-pin fan sitting around.