Arduino Fan Control using High Frequency 25kHz PWM // 4-Wire CPU Fans
HTML-код
- Опубликовано: 5 июл 2024
- Join Science Fun on Facebook @ / sciencefun4u
In a previous tutorial, I showed you how to control 2-wire, 3-wire, and 4-wire CPU fans using an Arduino. With 2-wire fans and 3-wire fans, speed control is possible using an N-channel MOSFET and PWM. With 3-wire fans and 4-wire fans, it is possible to measure the fan speed using an Arduino input and a pull-up resistor. With 4-wire fans, speed control is possible directly with a PWM Arduino channel without the use of a transistor or MOSFET.
However, some CPU fans require high frequency (25kHz) PWM in order to function properly. In this video I will demonstrate how to control a 4-wire CPU fan using 25 kHz PWM on the Arduino - Наука
RAD! I was just looking for a good guide to arduino PWM fan control! I'm also excited to see the huverkraeft! :D
Hope you enjoyed it!
Congratulations for covering the topic in sufficient detail, without using the "scary" words of, "Timers" or "Registers" !!
Glad you liked it!
Great work, this is the first sketch that works with my 25kHz fans 👍
Glad it was helpful!
Congratz for getting 1k subscribers:) keep it up
Thank you so much 😁
Not sure if anyone gives a shit but if you're bored like me during the covid times you can watch all of the new series on instaflixxer. I've been streaming with my girlfriend recently :)
@Franklin Ronan Yup, have been using InstaFlixxer for months myself =)
Nice video. I had read that the 25 KHz signal was required, so I planned to code for that without checking. Obviously that wouldn't hurt, but it's good when someone checks more thoroughly, as you have done. Bring on the hovercraft, of course!
Thanks! Hope to get started on the hovercraft soon.
Exactly the video I searched for. Thanks :D
Glad I could help!
@@ScienceFunInnovations Me, too ... but no code available on the discription :'(
@@TheJavaSync It is on my Facebook page @sciencefun4u
@@ScienceFunInnovations sure, I'll go for that :) Thank You
@@ScienceFunInnovations so, if I use pwm directly to drive gate of the N mosfet (to drive another DC motor), it will work, right?
Awesome and thank you so much, just subbed
Awesome thank you!
this was great! it worked (second time), for me the yellow and blue wire functions were swapped, so if it doesnt work for you swap the wires, i did that aftert checking the fan product description.
Excellent!
This video is very useful for me thank you sir!!!
Glad to hear that
Thank you for the video. Don't you also have to set the WGM12 bit in the TCCR1B register? Without it being set you actually don't use fast PWM but the regular dual-slope phase correct PWM.
Wow. Been too long since I did that video to remember. But sounds like you know more about it than I do. :-)
hi! what a great video.i have a question, for the comand "TCCRIA" of the second code (25khz) what library did u include.
it doesn't compile
sorry. and i look foward for our reply.
TCCRIA is not part of a library. It is a command related to timer 1 register A. Did you try to copy my code from facebook.com/ScienceFun4u ?
Very useful video, its so hard to find clear and understandable info about the fan controll, many are just copypasta other sources
Glad it helped
Hello, how did you learn how to establish these connections specifically how did you know to use a 10K Ohm resistor as a pull-up resistor to your Tacho wire. Also, did you provide a specific current from your voltage source?
10k is just a standard pullup. I would probably work with anything in between 1K and 100K. As far as the power source, I didn't limit the current, but these fans don't pull much anyway.
Nice tutorial, Thank you. What about 4-wire(blue, green, black, yellow) CPU intel Fan DC12V 0.28A NIDEC ?
Blue: Control (PWM), Green: Tach, Yellow: 12V, Black: Ground
Hi there, great video! I was wondering how you derived a pulse width of 320? I am assuming this was calculated assuming a duty cycle of 50 percent?
Thanks.
You can set it to different values. 320 just works well with the clock frequency.
You can lookup the formula in the datasheet of the ATmega uC: The timer use an I/O clock base that is half the main cpu clock frequency. In the arduino case the main cpu clock frequency is 16MHz, so the I/O clock is 8MHz. The CS* bits control the prescaler. It is set to 1 here. The PWM frequency formula is: f_PWM = f_IO / ( prescaler * ( 1 + ICR1 ). With a value of 320 for ICR1 you get around 25 kHz. With a value of 319 you would get exactly 25 kHz.
This is exactly what I need, How can I include the temperature controls in the void loop() as you did in your previous tutorial?
It has been so long since I looked at that code, but I imagine that it would be very similar. Best wishes.
Thank for this video . My fan (25 kHz) behaved exactly as you illustrated. I am however finding it a struggle to intergrate this high frenquency code with the code for the Lm 34 sensor. on the previous video..Any guidance would be very much appreciated.
Hmmm. Is it not giving you a reading? Or is it giving you a weird reading?
@@ScienceFunInnovations No the fan is working perfectly using the the circuit up as above. But I now wish to set up the circuit and code with the lm 34 thermistor controlling the fan.Do I still use pin 9 (instead of pin 3 as it was in your the June 1st video) for the pwm signal. Insofar as the code ,is it a case of inserting the code, here that set up the 25 khz, into the June 1st code.
Thanks
I came to learn about fan control and and this went just the right speed for me; and learned what I came to learn. It sparked my curiosity about the hovercraft design. Are these just fans you had available or are they specifically chosen because of their air movement physics per amp hours of power consumption say over a propeller, blower, etc. It looked like it was coming along well and never would have thought of a computer fan. I would have used the motor and propeller from quadcopter drones or centrifugal blowers; more than likely a common newbie mistake lol.
It really is just about airflow. These are high flow fans (approx 100 cubit feet per minute). A quad copter motor and propeller would work as well, but would probably drain the batteries a little faster. I had this on hand, so I used it. :-)
Great Video!! For configuring Timer 2 to do the same, how do we do that?
Does this help? www.arduino.cc/en/Tutorial/SecretsOfArduinoPWM
Hi! Thanks to the video. It is help-full when I learn arduino.
I have one question. 2:30 why *30 (or *60/2) to count RPM?
You said yellow-wire(pin2) make(?) 2 pulse, but I can't understand why interrupt pin receive two pulse in a second...
It depends on the fan, but most produce 2 pulses per revolution.
I am sending the hardware data from my PC to the Arduino ( CPU and GPU Load, Temperature, Frequency, etc) using C# and this is what I need to control the fans. The motherboard simply has very few fan outputs so the Arduino will take care of the rest. Thank you very very much.
Sounds great!
This is awesome, I have a few questions for you.
1. If I was using a 5v fan do I skip the resistor in the wiring diagram?
2. You are adjusting the frequency on pin 9 and 10 but appears you are only using pin 9. Is this a copy & paste issue?
1. Even with a 12V fan, some of my viewers have been successful without the resistor. You could definitely try without.
2. The configuration setup changes both pins 9 & 10 to high frequency PWM, but yes I only used one pin for this demo.
Thanks for watching!
It depends how the fan is wired internally I believe. I read something online saying the pull up is required for the transistor in the open collector... but I don’t recall why it’s so important.
Hi friend. I appreciate so much your time for sharing this code and the video to the community. Personally in my opinion is really valuable. I have 2 questions regarding to the code. The first is what's the purpose of the while sentence inside loop? [while ((millis() - start_time) < 1000) {}] because inside it it's empty and probably it can be deleted. My second question is how can revert the default pwm configuration on pins 9 and 10 of the arduino (490hz) after configuration of pins with 25khz. Thanks so much
1st question. The code sets a 1 second timer that allows void counter to keep running in the background. If I used delay(1000) I don't think it would work.
2nd question. Just load a blank sketch and it will revert to default.
Thanks for watching.
hi, thx for the video. i made it running on a silent fan. i have a question: how can I controll the fan to stop, if rpm=0 doesent make him?
The only way would be to use a relay, MOSFET, or transistor to completely shut off the power.
@@ScienceFunInnovations thx, tried it an works.
Thank you so much for this tutorial! Keep up the good work!
I have tried to reproduce it with 4 different 25khz pwm pc fans and 3 different arduino micro-controllers (2 uno and 1 nano) but the same strange things happened each time ..
1)I got funny tachometer values ( most of them are negative or very large values).
2)When i have disconnected the 10k ohm pull up resistor from the D2 port (Yellow wire), the produced pwm from the D9 port stops controlling the fan's speed ( the fans seem to run at max speed), even if the tach cable is not connected. ( I don't have an oscilloscope in order to measure the produced PWM from the arduino)
3)The fans doesn't seem to run at max speed when they are controlled from arduino. ( They produce more noise and wind when they run only with 12 volts from power supply ).
Check out some of the comments. Many other viewers have had the noise issue and were able to eliminate it with a low pass filter and/or Schmidt trigger. Good observations. Thanks for the feedback!
Thanks, man! With an Arduino, it worked perfectly. I really needed this info... :D Now, I must figure out, how I can do the same with an ESP32 safely... :D
Glad I could help!
Hi Hamidreza. I just saw this video by Gary Explains : ruclips.net/video/QMYhVqjBhKQ/видео.html where he uses a different program called PlatformIO for the programming. That program letts him program in arduino IDE language and export to a whole host of other devices like esp32. Just saw your comment and thought this might help you. Best of luck.
Thanks for the video, very helpfull
i have a question please.. Why is it important to connect the ground of the fan to the ground of the arduino ? otherwise PWM doesn't work
thanks in regards
Just so both have a common reference voltage.
Thank you for the tutorial. can I know how you wrote default commands like for TCCR1A and TCCR1B. can you please explain me. Because for my project I am looking for pwm frequency of 16KHz to 20KHz. I am very happy if you respond.
Thank you in advance.
I believe those are C commands, not C++. I found another code that used them. I am not too familiar myself...
Hello, I'm also using arduino to control the speed of my blower fan (delta - model: BFB1012VH-7P03). I am using your code (but changed some parts for the potentiometer) and same schematic (the only difference is that my power supply is connected to the arduino power jack and im accessing it through the Vin pin obviously). However, i cant control the speed with the potentiometer and the blower fan just goes to full speed. i also cant read the speed/rpm in the serial monitor. Why is that?
Are you able to see a pulse using a multimeter? Also try wiring your control wire to gnd and 5v to see if the fan responds to the signal. Hope you figure it out.
Hello, thanks for this tutorial.
I have a 24V 25kHz PWM 4-wire fan.
How should I control this fan through the Arduino Uno?
Thank you!
Same way, just use a 24V power supply and connect PWM to the Arduino.
Leaving as a suggestion... How would it be if you use the DBPF1238B8G cooler on the hovercraft?
I'm not familiar with that part. I'll have to check it out.
@@ScienceFunInnovations Check it out on my channel I have a recent video showing it, soon there will be a video of something I will do with it
and of course, my video is the only one on youtube about this fan
Grat video! I understand, that blue and yellow wires are PWM - and PWM +?
There should only be a PWM+, GND would act as PWM negative.
Hello! I have a little question. Does this code work the same for arduino DUE? If not, can you help me with it please? (I have a DUE)
I'm not sure. I've never used a DUE. It likely will work, but I am not sure if the pin numbers will be the same. I am not as familiar with the C code as the C++ code. Still learning myself... Thanks for watching.
I'm using a StarTech 4-wire PWM fan (FAN8025PWM), using the circuit provided here, but can't read the tachometer pin reliably because the PWM frequency (25kHz) noise is present in the square wave of the tach pin. Is there a way to filter the PWM frequency noise from the tach pin with either software or hardware?
Try a low pass RC (resistor capacitor) circuit. Set the frequency slightly higher than the max expected fan square wave frequency. ruclips.net/video/OBM5T5_kgdI/видео.html
@@ScienceFunInnovations Thanks for the quick response. I'll try that. The max rpm of the fan is ~2500. 2 pulses per revolution on the tach is 83Hz. I'll try adding a .15uF ceramic to the existing 10k resistor to make the low pass filter for a cutoff at 106Hz. Hopefully that will work for the default low frequency (490Hz) of the Arduino all the way to 25kHz.
That didn't work. I needed to add a schmitt trigger along with the low pass filter to gat an accurate RPM.
@@bbrown_sc how did that go? I’m having a similar issue.
I missing something with the 25kHz code, I'm getting 'TCCR1A' was not declared in this scope but I do not see where you are declaring their types. I was able to get the non-25kHz to work but my fan achieves full speed.
Hmmm. Not sure what's happening with that.
Thanks for the video...but how can I make pin 9 & 11 share 25khz with the same duty cycle and time.that is simutanius pwm...please am using it for my inverter charging on means...please helpp
Not sure on that one. Hopefully you figured it out?
Hi
I found it useful
Im working with battery fuel sensor IC bq34z100 that senses the charge of the battery and it must be on continuously to detect battery charge status. The supply im providing to FAN is same for IC Hence i keep ic on my fan must be off how it would be possible further pls help
Check out my other fan videos... I use a MOSFET to turn the fan off.
Hey Im having an issue where the PWM percentage doesn't affect the fan speed? Its always at full 1320rpm. Ive tried it with two fans and with both of your example codes in this video no luck :(
Is there anything that i could be missing? seems like the RPMs are reading and the code is running in the serial just the RPMs never change they go full speed as soon as i plug them in.
Weird. Try connecting the control wire straight to ground. The fan should drop to a very low speed. That would at least test that the fan is working. If the fan works, try putting a voltmeter on the Arduino PWM pin and see if that is working. Hope this helps. Let me know if you figure out the issue.
@@ScienceFunInnovations Ive found that when i unplug the arduino from the 12v ground the PWM works! but then the RPM stops working.
@@Trevor.Morrice are you using 3-wire or 4-wire fans?
Great help! Thx, any chance to tell me how to do it with ESP32 ? Thx!
Sorry, no. I haven't worked with ESP32 before.
Thanks for the video!
Very interesting.
Can I download your sketch from somewhere?
That one should be on my Facebook page: facebook.com/ScienceFun4u/
This circut works with a raspberry pi too right? I just wanna double check to make sure I don't break anything.
Should be fine with raspi.
Can you show me what the hardware connection would look like? I am trying to connect a 12 V 4 wire Fan to Arduino I understand Arduino only takes 5V wouldn’t the power supply fry the circuit?
Have you seen my other fan videos? I think those would answer your questions. The fan would need its own power supply.
Thank you very much for your interesting video's and explanation 😇. I wonder if you could share the models(link to purchase website) of the fans ? Additionally, I wonder if you have good websites for buying DC power supplies as I do not posess one yet. Thank you very much for your feedback!
Most of my components come from eBay, Amazon, or AliExpress. I don't remember where I got the fans as it was a very long time ago. Good luck, and thanks for watching!
Nice video. Why when the PWM is equal to 0, the fan cooler does not stop (rpm = 0)?
There is a minimum speed built in to the fan to protect it. They can be damaged if they go to slow.
@@ScienceFunInnovations Then it should not spin at all, normally PC fans starts spinning at around 15-20%, your fan or code is not up to spec.
Often the higher speed PWM is to get it just outside of audible range (whine otherwise at lower freq's)
Definitely! I have had many a motor buzz at me with low freq PWM. Better to drive the dog nuts instead with the high freq.
How i can made ir on my 24V noctua fan?
-24V Black
+24V Yellow
PWM Blue
RPM Green
Should work with 24v or 12v
is it safe to connect cpu fans to power supply or battery directly?
Yes.
Thank you for posting this. I'm using the 4_Wire_High_Speed_PWM code, and for some reason the Serial Monitor is showing PWM 0%, 25%, 50%, 75%, 100% AND 125%. Everything works fine until the PWM gets to 125% and the speed returns a negative value and the fan turns off. Then turns back on at PWM 0% and repeats the steps. What's causing the PWM to try 125%? Any way to make it stop at 100%? PWM 0% also shows 0 RPM but the fan is running (slowly) as expected. Thanks for your help!
EDIT - I fixed the problem with the map showing 125% (forgot to change 255 to 320), but now the same issue arises. The 100% shows a negative value and turns off the fan. 0% still shows a speed of 0 RPM as well.
Hmmm. Any luck figuring it out?
@@ScienceFunInnovations nope. Unfortunately I wasn't able to figure it out. I'm still in need of a solution if you can think of anything off the top of your head. Thank you!
How would it be possible to control 4-wire CPU fans using a PWM Speed Controller without using an Arduino ?
You can connect the red and black to a PWM Speed Control. Just don't take the PWM signal too low or you can ruin the fan. The internal PWM control on the fan prevents the fan from turning to slowly.
Thanks for the info! Really wish I could grab this code somewhere....
I have the code in the comments on my Facebook page @ScienceFun4u. Thanks for watching!
@@ScienceFunInnovations Thanks for the response! I just typed it out from looking at the video which was good practice. But that's great to know.
Sir Can You Pls help Me??
I just want to run the fan at the highest speed using an arduino
Waiting for your Reply
This video may help as well. ruclips.net/video/UJK2JF8wOu8/видео.html
For highest speed you can just use a digitalOut on a 4 wire fan. For a 2 or 3 wire fan, you would need a MOSFET, transistor, or relay as disguised in the other video. Good luck!
Sir how did you decide 360 pls can you tell me in detail
I did that a very long time ago and don't quite remember... but it is in the C code and you can change the number.
Can i use 3,5 and 6 no. pin to control 3 pwm fans?
You should be able to control multiple fans.
Was able to implement the code, but hit a snag. I seem to be getting PWM noise on the tach line as I’m controlling the fan.
The high frequency can do that. You may need a low pass filter and/or Schmidt trigger.
@@ScienceFunInnovations Yes it sure can. After a lot of experimentation with resistors and capacitors, I found that in my case, just a 220k ohm resistor was best. No capacitor at all. I could put a 3pf cap, but it made minimal difference to the scope. Now comes the fun of trying to understand why that was better than including a cap. I'm thinking it's because the cap modifies the square wave too much for the Arduino, or if it's just I had the wrong cap value.
The PWM controllers generate acoustic noises if the PWM frequency is within the acoustic spectrum (20Hz to 20KHz), that is why 25khz fan is more quiet
That makes sense.
How can I control the turning off of the fan? When PWM=0, the speed also maintains 1015RMP
In order to completely stop the fan you need to interrupt the power using a MOSFET, transistor, or relay. The fan will not drop to low/off RPM using PWM because turning at really low speeds will damage the motor on the fan. Thanks for watching!
@@ScienceFunInnovations Oh, I get it, Thank you for your reply.
thank you very much for this tutorial
can i get the link to the codes
I don't have that exact code posted, some of my other files are here. sciencefuninnovation.gumroad.com/
Thanks for the content!
can i control 5x FAN 12v 5A 47w 5000 maximum rpm(ea) (DELTA FAN (SERVER)) (i wanna use in maximum 3000rpm) with this solution?
One more time, thanks for sharing!
It really depends on the fan. If they are 4 wire, probably yes. But if they are 2 or 3 wire you may need to use MOSFETS.
can you change the code to control the fan with potentiometer?
Yes. Just use the map function to convert the 0 to 1023 input into a 0 to 255 output.
and can I also use low speed fan code for high speed fan?
Yes. The speed of fan should not matter.
niice
Thanks!
@@ScienceFunInnovations I made this, but i have a question regarding the 4 pin,
It's detailed here in this tweet
twitter.com/BwigMytch/status/1346411533824364545?s=19
Thanks
Ah it was you XD haha, ok I left you a question on the other video :D thanks!
No worries! Did all your questions get answered?
Link to the first video would be nice :P
Here it is ruclips.net/video/UJK2JF8wOu8/видео.html
if I want to maintain the RPM for 1200, how can I change the code?
If speed < 1200, increase PWM. If speed >1200, decrease PWM.
How can I remove the timer? Because I want the fan to run at a constant speed
For full speed, you can use a digitalWrite command or give any PWM signal for a constant speed.
@@ScienceFunInnovations Thanks for your answer. Can I control the speed of two fans at the same time with a single Arduino?
i mean great, it works, but the whole point of using interrupts, is to not block out huge sections of time waiting to readings.
oh and "count" should be a "volatile int" since you modify it inside an interrupt function.
Thanks for the tips.
This video gives me dejavu
?
Can you make Arduino code for specific frequency
Yes. Based on clock commands, but I am not that good writing in C...
// I tried that with mega 2560 and the bequiet Silent Wings 3 fan does not move , could you help me ? thanks
#define pinVentilateur 9 // La broche qui contrôle le ventilateur
void setup() {
pinMode(pinVentilateur, OUTPUT); // Définit la broche du ventilateur en mode sortie
TCCR1B = TCCR1B & 0b11111000 | 0x02; // Configure le Timer 1 pour un PWM à 25kHz
}
void loop() {
for (int i = 0; i
I haven't ever used a Mega. Not sure why it wouldn't work...
Will you share the code?
I just added it to my Facebook page @ScienceFun4u . Thanks!
@@ScienceFunInnovations thanks
Is this Arduino code available?
Not sure if I posted it here or not sciencefuninnovation.gumroad.com/?recommended_by=search
Is this code available?
That one should be on my Facebook page: facebook.com/ScienceFun4u/
Please data code Skript
The code is posted on my Facebook page @ScienceFun4u. Thanks for watching!
were are the source files please ?
facebook.com/ScienceFun4u/
can you leave the code you used here?
It should be on my Facebook page @sciencefun4u
@@ScienceFunInnovations Thank you so much
no copy and paste???
facebook.com/ScienceFun4u/
Something is not right when 0% gives 780 RPM. My guess is that the fan you are testing with does not follow PC-fan spec. 0% means no rotation, 0 rpm.
Some fans have minimum speeds so that the motors do not overheat.
Where is the code?
I have the code in the comments on my Facebook page @ScienceFun4u. Thanks for watching!
@@ScienceFunInnovations the link is your facebook page, not the proyect code, please upload the code
Since PWM controls 'on' and 'off' duration, I don't see how it matters if you use the low speed or the high speed PWM.
Unless you are changing that duty cycle very quickly, on is on and off is off, it won't make a difference.
I think the difference is how quickly you wish to change that duty cycle... 500 times a second or 25,000 times a second? Seems like overkill.
I guess it does allow you finer control of the duty cycle... so 4000 steps vs 500 steps? Also seems like overkill.
Good question... Not sure why some fans require the high frequency, but if you Google "cpu fan pwm frequency" you will find that many fans do require 25kHz to operate properly. My fan seems to work either way, so I'm going to stick with the low frequency PWM.
Another advantage to high frequency PWM is that it is out of the audible range. With many motors, you can hear the low frequency buzzing sound caused by the PWM signal. I've had stepper motors singing like a tweeter without even spinning the motor. The high frequency PWM makes it as quiet as a mouse to a human, but might annoy the dog instead. :-)
give me code
I may have posted it on my Facebook page @sciencefun4u
Just use a 555 timer. Why bother with all this unreliable nonsense???
Because a 555 timer does not have a brain. Let's see you vary the speed of a fan based on temperature using a 555. :-)
@@ScienceFunInnovations Are you kidding me? That is SO simple to do with a 555 timer. You obviously know nothing about the 555.