Thursday, October 12, 2017

Controlling the fan speed with your Arduino





Intro

You savaged a fan from an old PC to use it as a ventilator? Just hook it up to 12V and the sucker runs. Well, it runs at a constant speed. Maybe too fast, maybe too noisy. There must be a possibility to slow it down.

The idea

When you apply 12 Volts to it and then remove the power supply, it keeps spinning while getting slower. So if you continuously apply and remove the power, you can control the fan of the speed by the duration of the phases when the 12V is on and when it is not.

What do we need

The Arduino doesn't supply 12 Volts. So we have to use some sort of switch. An electronic switch. A MOSFET. That's a kind of transistor, that can handle the needed current/voltage needed. I used the IRF530N, because it was the only Mosfet I had and it matches the specification of the vent by far ;-). It's a N-channel Mosfet. That means you can control the connectivity of the negative pole of the power source to the fan by applying a positive voltage.

PWM

Pulse Width Modulation is the magic phrase. A digital output pin can only have two possible states. On or off. 1 or 0. HIGH or LOW. While HIGH is typically indicated by an output of 5 Volts (3.3 Volts occasionally) is LOW represented by a 0 Volt output. So how do we simulate an output of 2.5 Volts? Well, simply spoken, if we have a time frame of 10 seconds. Half the time we put out 5 Volts and half the time 0 Volts, we will have an output of 2.5 Volts of the time of those 10 seconds. Wired? Sure. But this is how math works ;-)
PWM



Video



Wiring





Links
IRF530N at Amazon

PWM-Image
https://commons.wikimedia.org/wiki/User:MatthiasDD


22 comments:

  1. this looks cool,
    wanna try it
    can u share the code with me.
    s.k.alimoestar@gmail.com
    thank you.

    ReplyDelete
  2. I love what you are doing with this blog. Could you please send the code to me @ vincentmuchiri1@gmail.com

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. You helped me supper with you explanation!
    Very newby in code

    But when I'm trying to implement your code I notice the write speeds:
    // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
    https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/

    or do I mis something?

    ReplyDelete
  5. can you share your Code to sayemmy007@gmail.com ,please!!!

    ReplyDelete
  6. can you share your Code to sayemmy007@gmail.com ,please!!!

    ReplyDelete
  7. No resistors needed?? Is the same wiring if I use a irf 520? Thanks

    ReplyDelete
  8. I like this pleasr share your code to hutainaml@gmail.com

    ReplyDelete
  9. can you send the code to webberlexx@gmail.com please

    ReplyDelete
  10. Could you please send the code to nkaymak2002@yahoo.com please?

    ReplyDelete
  11. can you please send the code to crissmuss@yahoo.com? thanks

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. Could you please send the code to lucasbonatelli0@gmail.com

    ReplyDelete
  14. hi. i love your explanation in the video. it gave me a better understanding. i would love to try it out. could you please share the codes to me @khairinazahar@gmail.com . Thank you sir :)

    ReplyDelete
  15. great video , would you be able to send me the code please to kalotan_mihov@yahoo.com
    regards

    ReplyDelete
  16. Could you please send the code to eddue662455@gmail.com

    ReplyDelete
  17. Working on a college project involving such motors. Can you please send the codes to nibirranjangogoi@gmail.com . Thank you

    ReplyDelete
  18. Would you be able to have the same kind of circuit but with a heater, I want to monitor it with a temperature sensor and then either increase the power into the heater or decrease it so that I can control it. If you could send me your code I am not sure if you do that but it would be appreciated, my email ml545@duke.edu

    ReplyDelete
    Replies
    1. I am working at a similar project. Could you please send me the code to at my email: fotizagl@hotmail.com

      Delete
  19. Pls I need the code johnstanley669@gmail.com

    ReplyDelete
  20. Hi I thought this blog was extremely helpful! Do you think you could send the code to my email clint.dejesus.2019@mumail.ie ? it would be amazing thank you so much

    ReplyDelete