At 5:26 you mistakenly state that "the MOSFET doesn't need 12V for the gate; it only needs 0.7V". You've unfortunately confused the MOSFET with a bipolar junction transistor (BJT). The BJT does indeed need only 0.7V at its base (but requires several mA of current), but the IRF530 needs between 2V and 4V on its gate to begin to conduct, and rather more than that to turn it on fully (although it needs almost no current into the gate). Some samples of IRF530 may not even turn on properly with the output of the Arduino, and you are much better off using an IRL530. The 'L' indicates a logic-level MOSFET which will turn on fully when supplied with 5V. A lot of logic circuits use 5V as their high level, and the Arduino is one of them. It's worth also noting that you should add a series resistor of about 270R between the Arduino output pin and the gate of the MOSFET to limit the transient current into the MOSFET's gate capacitance as the Arduino switches its output from low to high. That value will ensure that any momentary current drawn is no more than 20mA, which is the maximum allowed from the I/O pin. Finally, the fan is an inductive load and should be bypassed by a reversed diode (e.g. a 1N4001), which is needed to absorb the transient spike that is generated when current is abruptly cut off from an inductor. This will prevent the possibility of damage to the MOSFET and reduce the radio-frequency interference generated by the switching.
Brilliant!!! Einstein once said if you can't explain something simply then you don't understand it. Well sir, you definitely understand it and I appreciate you sharing your knowledge as well as your delightful ''style''. It's fun to learn with a smile. Thank you.
What is that resistor that you've placed on the breadboard, when you've hooked up the Arduino? And why is it there? You don't mention anything about it in the video, nor within the project page that you've linked.
It should unsure that the Gate is pulled to LOW. Without the Arduino the Gate would stay open. But if you connect it to the Arduino and pull the pin to LOW, you don't have to use the resistor.
Silly question. Can i use this to PWM a DC fan then? Why can't any DC fan run PWM mode from a motherboard of fan controller then? They sell PWM fans and DC fans as separate models. Sorry, I'm quite new to this.
There is a corresponding project page to this video. rohling-de.blogspot.de/2017/10/controlling-fan-speed-with-your-arduino.html The resistor is a pull-down resistor for the PWM port of the Arduino. Although it is not really necessary because the Arduino should be capable to pull the pin internally to GND.
for the analogWrite, he used the values 300 and 1000. How come in the Arduino website, it says that the values should range only from 0 to 255? It still worked though.....??? for analogRead, he can get between 0 and 1023.
It depends on how much current the fan takes. You need current to drive the base of the 2N2222 and the Arduino can only supply 20mA maximum, which limits the available collector current to about 200mA for driving the fan. MOSFETs are much better for this particular job as they draw almost no current into their gate.
There was no talk of the 10h resistor of the gate connected to the source. But it was one of the best videos I saw because it helped me in the resistor. Loved your video. Thank you very much.
The resistor was original for the purpose to automatically closing the gate. With an Arduino connected it becomes obsolete. But I forgot to remove it ;-)
@@nenioc187 It's not a bad idea to leave it in place as it provides a fail-safe if the connection from the Arduino to the gate is accidentally disconnected.
for someone that is trying to use it with 3.3v operating board(like esp32),this will not work cause irf530m need at least 4v to drive the gate,use other with lower max VGS(th) instead like irl3713 ,this one needs 2.5v
I have a 12v 0.18a 3wire blower dc blower fan, I want to slow the speed down for long periods but need the full speed for initial start up for a couple of minutes. Can you advise me on which type of small speed controller I should buy for the well being of my blower. Have seen vids on transistor/ potentiometer methods but would rather buy the right tool for the right job so to speak. Thankyou. Great video.
@@theaurumtheory If you watched the video you would clearly see that he used analogWrite(Gate, 300) and analogWrite(Gate, 1000). My guess is that Arduino ignores the bits it cant use and reads them as 44 and 232 (300 mod 256 and 1000 mod 256 respectively).
@@theaurumtheory Still think Kjartan is right. Have a look at the definition of Arduinos "analogWrite" function: www.arduino.cc/en/Tutorial/PWM Quotation: "A call to analogWrite() is on a scale of 0 - 255, such that analogWrite(255) requests a 100% duty cycle (always on) [...]" Also, having a look at the source code reveals that for values (other than 0 or 255), a function named "sbi" is called which is defined as: "#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))" Soo now I was wondering bc. just using bitwise OR operations would not stop the actual "number" from being more than one byte. Then I found this interesting blog post: www.txplore.com/blog/16248/10-min-pwm-overflow Long story short, he tells that the Atmega used by the Arduino Uno has an 8 bit register for PWM. Using 8 bits (1 byte) the maximum number possible in decimal is 255 (= binary: 11111111) and more bits will just "overflow" and wont be used. In this video, he uses 1000 which is 1111101000. Taking the first 8 bits only, we get 11101000 which is equal to using the value 232.
It's a pull-down resistor. It was for the manual testing with the battery. Because the drain wouldn't close itself once opened. If you hook the MosFet to the Arduino, you won't need that resistor anymore.
if am use use 2 temperature sensor and 5 pc fan for cooling purpose is it possible to run at separate and whole fan at same time..? am lot of double actually is possible if not how did i done this project..?
perhaps you can tell me because i can't seem to figure it out and can't find anything or google, and nobody has answered the question. if you used a 5v fan, how would you wire it?
Understand clearly. Thanks. One question, in order to put temperature sensor (LM35DZ), just install its VCC to the 12V, GND to Ground and the Output to Arduino ANALOG IN. Is it correct?
I've read the datasheet of the LM35. It's operating range is from 4-20V. So you can even connect it's VCC to the VCC of the Arduino. GND to GND of the Arduino - of course. And the Output to an analog input of an Arduino, that's correct. But without a library for it, you won't get Celcius or Fahrenheit, but Voltage. You have to calculate the temperature for yourself. I've made 3 Vids about temperature sensors. Maybe there is one you would prefer to use ;-)
great tutorial but I think its a bit confusing as you used a 3 wired fan and I thought the yellow wire was for the PWM. I read more and see that the 3rd wire just reads the frequency of the fan. I also was wondering if the mosfet would overheat but I think in this example no as you not using too many W - But very nice tutorial
can you tell me please what transistor is needed and if it can be used with a 4 pin pwm 12 fan? What is the amps about in a transistor? I notiice mosfet transistors with wide range of amperage and the same volts. Thanks
4 pin fans work a little different. I'll put this topic on my video-bucket list. The amps on the transistor indicates the maximum current that the transistor can handle before blowing up ;-)
Could I get the same result if I used the 12V power supply of the UNO (Vin) and connected it to the + terminal of the fan and GND to the source of the transistor?
Corresponding to the datasheet of the mosfet, it can handle up to 33A @ 10V. So it still would suitable for your needs. Don't know your fan, but if 9V is max, you can use 10V as a source input. From there it is easy. To achieve 5.4Volts you need a duty cycle of bout 54%. For 9V a duty cycle of 90%. That's easy as that ;-)
My guess: you've connected accidentally to the 5V output of the PC power. Or, you've really used a 12V output that can't handle 3.3 amps. So the voltage drops.
Just tested - its from yellow (metered 11,8V from source). Tested fan straight from PC source - goes full. My schema is axweb3.info/jet/20180530-i41-91kb.png
My guess is that the output from the Arduino isn't enough to turn on your sample of the IRF540, which is normally used with 10V to drive the gate. Use an IRL540 instead, which is specified for logic-level use and will perform properly with gate voltages of 5V.
Very good video! I dont understand the last thing you do. I understand that we use mosfet like a switch , so when we give +voltage to Gate the circuit is closed and when we connect Gate to Ground the circuit is open (and the fan stops). If we give analogWrite(Gate,300) and analogWrite (Gate, 1000) we give a voltage bigger than the Vthreshold to the Gate. In both ways we activate the circuit. But the Gate is like a switch so what exactly increases the fan speed?
Since we are not using a analog pin, but a digital PWM pin, we don't change the voltage on the gate. It's always 5V. PWM turns the 5V on and off again, very fast. If we using analogWrite(Gate,300), means that 300/1024 of the time of a duty circle the 5 V is applied. The rest of the time, it is set to GND. It works like the part, where I connect and disconnect the 12V of the battery to to fan manually very fast ruclips.net/video/Pw1kSS_FIKk/видео.html .
@@nenioc187 Just to elaborate the my question.. in other videos the the code is explained as analogWrite(Pin, DutyCycle).. so Pin is the digital pin no. to which the Mosfet gate is connected(here, pin no 10).. and the dutyCycle should be max 255.. but in the code, it is written as 300 which you said 300/1024 of the time... now my question is if i write 255 instead of 300.. will it count as 255/1024 of the time or the highest dutyCycle value for the gate..? and why.. It will be a great help if you pls explain. Thanks.
The Arduino needs to be plugged in for: - Programming - Output to the serial monitor on your PC - Or just for powering the µC (you could also power the Arduino differently)
hello, I followed your tutorial, but the LED does not shine at 100%, and try the irfz44n, irf540n, irlz44n, irl540n and the tip120, but none makes the led shine 100%, but when connected directly to the 12v, it lights up a lot , I do not know what to do anymore, I'm thinking about giving up
The MOSFETs have a internal resistance. So you got a voltage drop depending on the level of resistance. You can check the values in the datasheet of the MOSFETs. If you have a 12V LED and want to archive the full brightness you can either calculate the voltage drop and add the missing voltage on the supply side, or you can use a relay. And: Never. Give. Up.
@@nenioc187 The IRL540 is specified to have a resistance (Rds_on) of 0.077 ohms maximum with 5V on the gate. You're going to be passing an awful lot of current to see a significant voltage drop in that case. If the LED isn't at 100%, then I would check the code used in the Arduino. Perhaps just set the digital pin HIGH as a test. I assume that everybody has figured out that the maximum duty cycle is obtained with a value of 255?
Great video thank you so much! Only that I did exactly the same circuit and used the same Mosfet but the analogWrite(..) does not work. While digitalWrite works and turns on off the fan, when I try to use slower speed by using analogWrite the fan goes OFF completely :( My problem is that the fan is quite loud and i want it to operate at slower speed and that is perfect with analogWrite.... I used also the GATE 10. Any ideas? For the moment with this code is quite silent but i need analogwrite to work, don't know... will check it more.... #define Gate 10 void setup() { pinMode(Gate,OUTPUT); } void loop() { digitalWrite (Gate, HIGH); delay (200); digitalWrite (Gate, LOW); delay (1200); }
Hi, nice explanation. I'm on a project and I use the IRF540N over which I shoot 12v, but the problem is that when the gate is open at the exit of the drain at 11.45v and the transistor heats up when it drops the voltage on the gate. How do I get rid of it?
You'll always get a voltage drop with a MOSFET. They have a inner resistance value. There are MOSFETs with lower resistance, but you won't get the exact same voltage you'll put in. That's also the reason the MOSFETs are heating up. You should use them with a heat sink. When the output voltage is essential, you should use a relay, if possible.
Instead of a MOSFET I have an L298N H-Bridge module. When I try to control the speed of the fan with PWM I can seem to achieve some speed control, but the PWM causes a squealing noise. If I use a MOSFET instead will I avoid this problem or is the issue with the fan itself?
hi nenioc187, Still need +12V battery supply? because i think the fan's positive terminal has to connect the +12V battery supply. Thank you for your video.
Hi! I tried building the same circuit but using a usb power supply cable instead. Would this circuit work if I used a 9v USB power supple cable and 8 amp transistor instead of the 17 amp transistor u used? Thanks so much
The reason I used this MosFet is, because it was the only one I had ;-). Well I also have a 12V computer-fan, which I power with only 9V. It works. But it won't rotate fast.
Thank you for the reply and . If I use a TIP102, should I be fine? I keep trying the circuit and it isn't working for me. When I touch the gate to the positive end of the power supply cable, nothing happens. Thanks!
Not in this test. The fan speed is controlled by supplying the voltage and removing it again with help of the mosfet, that is controlled by the Arduino. If you're interested in controlling it through the yellow cable, I'll put it on my bucket list.
Hey y’all Just started arduino and was curious as to how he input a value of 1000 in the analogWrite function. I thought this only took values from 0-255. Thank you!
Oops. My bad. Yes, there is a resistor between the gate and GND. Because if you open the gate by connecting it to positive, it will stay open ruclips.net/video/Pw1kSS_FIKk/видео.htmlm55s until you connect it to GND. The resistor between GND and Gate will automatically close the Gate if it is not connected to the positive. However, when the Arduino sends the LOW-value to a pin, it means that it is internally pulled to GND. So technically you don't need a resistor with an Arduino. I recommend to use a high value resistor anyway, because I noticed that some cheap Arduino clones don't always put out a good 0V- on LOW.
It should insure that the Gate is pulled to LOW. Without the Arduino the Gate would stay open. But if you connect it to the Arduino and pull the pin to LOW, you don't have to use the resistor.
Nice video Nenioc187, thanks for that. How can we control multiple fans, say 5-6 of them? Shall we use 5-6 mosfets on the breadboard? Anything else to control them via a temperature sensor? Appreciate your help
You could use one mosfet for all Fans, if they all should rotate in at the same speed. If you want to control them all differently, go for one mosfet/fan. And think about using a diode to prevent the fan inducting current to the controller.
@@santonio7283 The flyback diode is connected across the fans, but reverse biased, so that its anode is connected to the MOSFET drain and its cathode to the 12V supply.
First of all: Be careful! Mains power is very dangerous! You can use this videos technique the same way. But instead of a MOSFET, you should use a solid state relay.
I savaged it from an old computer. So it didn't really cost me anything. If you search for "12v pc fan" on eBay, you'll get many hits from 1€ up to 20€. But that one for 1€ will do.
Great Video. I made this exact circuit just as an experiment; however, my fans are turning very slow. Any suggestions - How could I draw more current into the fan? Or how could I decrease the overall resistance?
First of all, you need to discover why the fans are turning slowly. Try disconnecting the gate of the MOSFET from the Arduino and connecting it to a higher voltage, but no more than 10V. If that solves the problem, then it shows that your IRF530 isn't turning on fully with just 5V. It's not guaranteed to do so, and you are always better using an IRL530 when driving it from a microcontroller. The 'L' signifies a logic-level MOSFET and the IRL530 is guaranteed to turn on with a maximum resistance of 0.16 ohms and supply up to 15A when it has 5V on its gate.
No, Mosfets are DC Devices and besides that the Voltage is WAY too HIGH. If you want to switch AC devices you need to use a TRIAC instead of a MOSFET Transistor. Google Triacs and Arduino
Very nicely explained! -I might have something for your bucket list though :) -How would you control a device (a peltier for instance) that does not stand the PWM ripple well, while also introducing a lot of noise in sensitive devices around?.. -Is there a way to 'smooth' that ripple or simply use/create a continuous/proportional signal for control?..
Usually you can use a capacitor to smooth the PWM signal a little. I haven't tried it yet to control a peltier element - although I've laying them around for quite a while.
Yup, that could also work I guess... Thanx! -Since I see you've worked with several different temperature sensors, you might (also:)) want to try a peltier+fan based temperature control project; see how stable around the set point you can get ;) -Cheers!
Using peltier and fan to create a controlled environment? Hmm... sounds interesting. That will go to my bucket list. Damn, my bucket list is becoming huge.
@@nenioc187 If you use a capacitor on the MOSFET gate to smooth the PWM signal, then you must include a resistor between the I/O pin and the capacitor to prevent the initial charge current on switching from exceeding the rated 20mA for an Arduino pin. A minimum of 270R would be needed. However, once you've smoothed out the PWM signal, you're operating the MOSFET in its linear region, rather than switching it, so it will get hot and may need a heatsink. If you use a (much larger) capacitor across the load, you'll probably want to add some series resistance between the drain and load as well to limit current spikes as the MOSFET switches.
A PWM (pulse width modulation) dimmer is not suitable for a fan motor speed controller. They are typically used for LED dimming, but it causes the squealing many people are hearing on their fans when trying this circuit. This fan motor in this video seems to be okay with it, but almost all fans will not like it and will squeal LOUDLY. It's also hard on the fan motor. The MOSFET circuit here in the video is okay for on/off control, although it really should have a flyback diode on it as well to protect the MOSFET from back inductance when the fan shuts down: en.wikipedia.org/wiki/Flyback_diode To properly control the speed you need to convert the PWM square wave signal to a DC voltage using an RC filter coupled to an op amp driving an LM317 voltage regulator. You can find this circuit on the internet in various places, like this: www.edn.com/design/analog/4363990/Control-an-LM317T-with-a-PWM-signal
The problem with the LM741/LM317 circuit is that the output voltage range is limited to between around 1.25V to around 10V or perhaps less. You would be better off with a more modern opamp that can swing its output rail-to rail and a normal NPN medium power transistor like a BD135 or BD235 depending on how much current you need.
Could someone possibly right me a scriypt i'm wanting to use a arduino as a indicator relay on my old mans classic bike, so i would be using an arduino and 2 relays anyone able to help out? Thanks
Hi nenioc187, great video, thank you! Could I ask, what is the maximum voltage for a fan or any output for that matter that could be controlled using this sort of transistor? Could I use a fan that is 220-240V (100mA) to reduce its RPM? And if not, why not? :) Many thanks!
I assume that your fan is 220-240V AC, so this circuit is not suitable as it is intended for DC applications. Mixing mains voltage with microcontrollers is fraught with problems and usually requires the use of an opto-isolator and a triac to control AC mains devices along with many precautions in layout. That really isn't suitable for a beginner. For DC use, the IRL530 is rated at 100V and 15A (although not both at the same time), but again, high voltages are not suitable for beginners, and I'd strongly recommend investigating projects that require no more than 24V and a few amps while learning.
Hi neioc187, awesome work here. Ordered some IRF530N Mosfits and got it up and running just as you showed us. I have tried two different fans and both make a buzzing sound anything less then 1000. Is this a normal function of controlling the rpm with a Mosfit or is there a way to get rid of the buzz ?
I would suggest getting some IRL530s next time as they are made for interfacing with logic-levels of 5V or less (unlike the IRF530, which is intended for use with 10V gate voltages). A capacitor and a reversed diode across the fan to suppress the transients might reduce the buzzing. If that fails, then maybe try putting a resistor in series with the fan to reduce the maximum voltage across it. It will lower the maximum fan speed but should make lower speeds smoother. You'll have to determine the resistor value by trial-and-error, but you could perhaps start with a 33R 0.5W resistor and see what happens.
Out of millions of RUclips videos that ive seen, this is the only RUclips video where it explains what a transistor really is with great explanation
At 5:26 you mistakenly state that "the MOSFET doesn't need 12V for the gate; it only needs 0.7V". You've unfortunately confused the MOSFET with a bipolar junction transistor (BJT). The BJT does indeed need only 0.7V at its base (but requires several mA of current), but the IRF530 needs between 2V and 4V on its gate to begin to conduct, and rather more than that to turn it on fully (although it needs almost no current into the gate). Some samples of IRF530 may not even turn on properly with the output of the Arduino, and you are much better off using an IRL530. The 'L' indicates a logic-level MOSFET which will turn on fully when supplied with 5V. A lot of logic circuits use 5V as their high level, and the Arduino is one of them.
It's worth also noting that you should add a series resistor of about 270R between the Arduino output pin and the gate of the MOSFET to limit the transient current into the MOSFET's gate capacitance as the Arduino switches its output from low to high. That value will ensure that any momentary current drawn is no more than 20mA, which is the maximum allowed from the I/O pin.
Finally, the fan is an inductive load and should be bypassed by a reversed diode (e.g. a 1N4001), which is needed to absorb the transient spike that is generated when current is abruptly cut off from an inductor. This will prevent the possibility of damage to the MOSFET and reduce the radio-frequency interference generated by the switching.
Quite s simplification and conflation, EBC / SGD, PNP vs NPN etc.
Brilliant!!! Einstein once said if you can't explain something simply then you don't understand it. Well sir, you definitely understand it and I appreciate you sharing your knowledge as well as your delightful ''style''. It's fun to learn with a smile.
Thank you.
When this dude explains it better than teacher in school👏👏
True that
Your sense of humor is great. Continue making more movies please!
What is that resistor that you've placed on the breadboard, when you've hooked up the Arduino? And why is it there? You don't mention anything about it in the video, nor within the project page that you've linked.
It should unsure that the Gate is pulled to LOW. Without the Arduino the Gate would stay open. But if you connect it to the Arduino and pull the pin to LOW, you don't have to use the resistor.
plz make a video which uses potentiometer to set duty cycle of the pwm signal
I have been trying to figure this out all day. This is the clearest most complete answer I have been able to find.
Thx, could you please explain how to use third wire(yellow =hall sensor out put ) for feedback control
First you have a resistor above the mosfet? then it has dissepear? did you not need it anymore?
Silly question. Can i use this to PWM a DC fan then? Why can't any DC fan run PWM mode from a motherboard of fan controller then? They sell PWM fans and DC fans as separate models. Sorry, I'm quite new to this.
Excuse me, I'm a beginner, what resistor is that when you connected the gate to the arduino, how is it connected and why is it there?
"You don't know how it works? Well, I didn''t know it either so I had to look it up" this is the type of tutorial I like
Should I use data pin instead of pwm signal.
I am having a hard time seeing where you placed the resistor. Can you give a more detailed diagram also with the resistor specs?
There is a corresponding project page to this video. rohling-de.blogspot.de/2017/10/controlling-fan-speed-with-your-arduino.html
The resistor is a pull-down resistor for the PWM port of the Arduino. Although it is not really necessary because the Arduino should be capable to pull the pin internally to GND.
for the analogWrite, he used the values 300 and 1000.
How come in the Arduino website, it says that the values should range only from 0 to 255?
It still worked though.....???
for analogRead, he can get between 0 and 1023.
Can you use a bipolar juntion transistor instead of the mosfet? For example the PN2222 bjt to control a 12V pc fan
It depends on how much current the fan takes. You need current to drive the base of the 2N2222 and the Arduino can only supply 20mA maximum, which limits the available collector current to about 200mA for driving the fan. MOSFETs are much better for this particular job as they draw almost no current into their gate.
I think 0.7v is for most bipolar junction transistors, for irf530 gate threshold minimum is 2v.
spettacolare, volevo chiedere, si può controllare una ventola a 24v con lo stesso sistema???
There was no talk of the 10h resistor of the gate connected to the source. But it was one of the best videos I saw because it helped me in the resistor. Loved your video. Thank you very much.
The resistor was original for the purpose to automatically closing the gate. With an Arduino connected it becomes obsolete. But I forgot to remove it ;-)
@@nenioc187 It's not a bad idea to leave it in place as it provides a fail-safe if the connection from the Arduino to the gate is accidentally disconnected.
Great job! you did a wonderful job explaining and demonstrating the use of a MOSFET and PWM.
You seem to have a 3 wire fan. Isn’t the 3rd wire for speed control with a PWM? Or is it feedback?
Not sure. I needed a fan for demonstration and that one was the only one laying around.
In my country i can only find IRF540N. Can i do the same as this video?
Anyway 3rd wire (yellow) of the fan is not important right?
That depends on your needs. Check the datasheet. The IRF540N can handle a max. 100V @ 33A.
for someone that is trying to use it with 3.3v operating board(like esp32),this will not work cause irf530m need at least 4v to drive the gate,use other with lower max VGS(th) instead like irl3713 ,this one needs 2.5v
I'm getting a lot of whine from the fan when its not going full speed, is there a way to silence that?
I have a 12v 0.18a 3wire blower dc blower fan, I want to slow the speed down for long periods but need the full speed for initial start up for a couple of minutes. Can you advise me on which type of small speed controller I should buy for the well being of my blower. Have seen vids on transistor/ potentiometer methods but would rather buy the right tool for the right job so to speak. Thankyou. Great video.
How are you using 300 and 1000 in analog write? I thought it had to be 0 to 255?
@@theaurumtheory If you watched the video you would clearly see that he used analogWrite(Gate, 300) and analogWrite(Gate, 1000). My guess is that Arduino ignores the bits it cant use and reads them as 44 and 232 (300 mod 256 and 1000 mod 256 respectively).
@@theaurumtheory Still think Kjartan is right.
Have a look at the definition of Arduinos "analogWrite" function: www.arduino.cc/en/Tutorial/PWM
Quotation: "A call to analogWrite() is on a scale of 0 - 255, such that analogWrite(255) requests a 100% duty cycle (always on) [...]"
Also, having a look at the source code reveals that for values (other than 0 or 255), a function named "sbi" is called which is defined as:
"#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))"
Soo now I was wondering bc. just using bitwise OR operations would not stop the actual "number" from being more than one byte.
Then I found this interesting blog post: www.txplore.com/blog/16248/10-min-pwm-overflow
Long story short, he tells that the Atmega used by the Arduino Uno has an 8 bit register for PWM.
Using 8 bits (1 byte) the maximum number possible in decimal is 255 (= binary: 11111111) and more bits will just "overflow" and wont be used.
In this video, he uses 1000 which is 1111101000.
Taking the first 8 bits only, we get 11101000 which is equal to using the value 232.
is it pwm controller or voltage reducing?
can we control the direction of the motor? I'm trying with your circuit but unable to control direction
What you are looking for, is called a H-Bridge.
ruclips.net/video/97fj8j3fvfo/видео.html
@@nenioc187 I am trying to apply PID to control my DC motor, so we have to use H-bridge instead of just a single mosfet right?
how about 12v button with led ? connected to pc ?
you didn't tell about resistor on board ? can you explain it please why use resistor ?
It's a pull-down resistor. It was for the manual testing with the battery. Because the drain wouldn't close itself once opened. If you hook the MosFet to the Arduino, you won't need that resistor anymore.
What happen if we send signal by using yellow signal wire direcly to the fan from the arduino without using mosfet.
if am use use 2 temperature sensor and 5 pc fan for cooling purpose
is it possible to run at separate and whole fan at same time..?
am lot of double actually is possible if not
how did i done this project..?
Of course you can control multiple fans separately. You'll need a separate PWM pin and a mosfet for each fan.
perhaps you can tell me because i can't seem to figure it out and can't find anything or google, and nobody has answered the question. if you used a 5v fan, how would you wire it?
Exactly the same, except you'd need a 5V supply for the positive wire of the fan.
Understand clearly. Thanks.
One question, in order to put temperature sensor (LM35DZ), just install its VCC to the 12V, GND to Ground and the Output to Arduino ANALOG IN.
Is it correct?
I've read the datasheet of the LM35. It's operating range is from 4-20V. So you can even connect it's VCC to the VCC of the Arduino. GND to GND of the Arduino - of course. And the Output to an analog input of an Arduino, that's correct.
But without a library for it, you won't get Celcius or Fahrenheit, but Voltage. You have to calculate the temperature for yourself.
I've made 3 Vids about temperature sensors. Maybe there is one you would prefer to use ;-)
Thank you so much for the reply. Much appreciated. Will watch the videos later. Thanks.
I've seen some transistors have source, gate and drain and others have collector, base and emitter, is there a difference?
Usually you're using collector, base and emitter when referring to transistors and source, gate, drain when you're talking about MOS-FETs
great tutorial but I think its a bit confusing as you used a 3 wired fan and I thought the yellow wire was for the PWM. I read more and see that the 3rd wire just reads the frequency of the fan. I also was wondering if the mosfet would overheat but I think in this example no as you not using too many W - But very nice tutorial
Is the DC power supply necessary? Why? Could we use just the Vcc of Uno instead?
can you tell me please what transistor is needed and if it can be used with a 4 pin pwm 12 fan? What is the amps about in a transistor? I notiice mosfet transistors with wide range of amperage and the same volts. Thanks
4 pin fans work a little different. I'll put this topic on my video-bucket list. The amps on the transistor indicates the maximum current that the transistor can handle before blowing up ;-)
thanks man
Could I get the same result if I used the 12V power supply of the UNO (Vin) and connected it to the + terminal of the fan and GND to the source of the transistor?
Yes, assuming that the 12V supply you're using to power the UNO has enough current capacity to also power the fan.
or we have to attach another Arduino with it to perform another function?
Hi, great manual, but wont works with 3,3A fan. Need for start about 5,4V and controlling between 5,4V and 8-9V. Any idea? (using IRF540N mosfet)
Corresponding to the datasheet of the mosfet, it can handle up to 33A @ 10V. So it still would suitable for your needs. Don't know your fan, but if 9V is max, you can use 10V as a source input. From there it is easy. To achieve 5.4Volts you need a duty cycle of bout 54%. For 9V a duty cycle of 90%. That's easy as that ;-)
Hi, my fan is VA450DC model V34809-90 (12V DC 3,3A). analogWrite(Gate, 255) gives me now 5,7-5,8V max. Source is PC power source.
My guess: you've connected accidentally to the 5V output of the PC power. Or, you've really used a 12V output that can't handle 3.3 amps. So the voltage drops.
Just tested - its from yellow (metered 11,8V from source). Tested fan straight from PC source - goes full. My schema is axweb3.info/jet/20180530-i41-91kb.png
My guess is that the output from the Arduino isn't enough to turn on your sample of the IRF540, which is normally used with 10V to drive the gate. Use an IRL540 instead, which is specified for logic-level use and will perform properly with gate voltages of 5V.
finally a good tutorial for 3 pin fans, thank you!
My pleasure!
Very good video! I dont understand the last thing you do. I understand that we use mosfet like a switch , so when we give +voltage to Gate the circuit is closed and when we connect Gate to Ground the circuit is open (and the fan stops). If we give analogWrite(Gate,300) and analogWrite (Gate, 1000) we give a voltage bigger than the Vthreshold to the Gate. In both ways we activate the circuit. But the Gate is like a switch so what exactly increases the fan speed?
Since we are not using a analog pin, but a digital PWM pin, we don't change the voltage on the gate. It's always 5V. PWM turns the 5V on and off again, very fast. If we using analogWrite(Gate,300), means that 300/1024 of the time of a duty circle the 5 V is applied. The rest of the time, it is set to GND.
It works like the part, where I connect and disconnect the 12V of the battery to to fan manually very fast ruclips.net/video/Pw1kSS_FIKk/видео.html .
I understand , thank you very much.
@@nenioc187 Just to elaborate the my question.. in other videos the the code is explained as analogWrite(Pin, DutyCycle).. so Pin is the digital pin no. to which the Mosfet gate is connected(here, pin no 10).. and the dutyCycle should be max 255.. but in the code, it is written as 300 which you said 300/1024 of the time... now my question is if i write 255 instead of 300.. will it count as 255/1024 of the time or the highest dutyCycle value for the gate..? and why.. It will be a great help if you pls explain. Thanks.
Besides in programming, does the Arduino need to be plugged in for everything to function
The Arduino needs to be plugged in for:
- Programming
- Output to the serial monitor on your PC
- Or just for powering the µC (you could also power the Arduino differently)
hello, I followed your tutorial, but the LED does not shine at 100%, and try the irfz44n, irf540n, irlz44n, irl540n and the tip120, but none makes the led shine 100%, but when connected directly to the 12v, it lights up a lot , I do not know what to do anymore, I'm thinking about giving up
The MOSFETs have a internal resistance. So you got a voltage drop depending on the level of resistance. You can check the values in the datasheet of the MOSFETs. If you have a 12V LED and want to archive the full brightness you can either calculate the voltage drop and add the missing voltage on the supply side, or you can use a relay.
And: Never. Give. Up.
Alejandro Castiblanco for simple LEDs using a bjt would be better only high current application would be suitable for MOSFETs
@@nenioc187 The IRL540 is specified to have a resistance (Rds_on) of 0.077 ohms maximum with 5V on the gate. You're going to be passing an awful lot of current to see a significant voltage drop in that case. If the LED isn't at 100%, then I would check the code used in the Arduino. Perhaps just set the digital pin HIGH as a test. I assume that everybody has figured out that the maximum duty cycle is obtained with a value of 255?
And the motor drivers are too heavy...which mosfet would u recommend for a 3.7 v motor..
Thanks for help..😊
You have some resistor. What is the measure of it, and which pins is connected to do? Thx
huh he didn't have resistors
how to control the speed of an electric fan based on the temperature of the room using a 3 relay for speed? thanks for project purpose
Great video thank you so much! Only that I did exactly the same circuit and used the same Mosfet but the analogWrite(..) does not work. While digitalWrite works and turns on off the fan, when I try to use slower speed by using analogWrite the fan goes OFF completely :(
My problem is that the fan is quite loud and i want it to operate at slower speed and that is perfect with analogWrite.... I used also the GATE 10. Any ideas?
For the moment with this code is quite silent but i need analogwrite to work, don't know... will check it more....
#define Gate 10
void setup() {
pinMode(Gate,OUTPUT);
}
void loop() {
digitalWrite (Gate, HIGH);
delay (200);
digitalWrite (Gate, LOW);
delay (1200);
}
Have you tried using value range from 0-255?
Hi, nice explanation. I'm on a project and I use the IRF540N over which I shoot 12v, but the problem is that when the gate is open at the exit of the drain at 11.45v and the transistor heats up when it drops the voltage on the gate. How do I get rid of it?
You'll always get a voltage drop with a MOSFET. They have a inner resistance value. There are MOSFETs with lower resistance, but you won't get the exact same voltage you'll put in. That's also the reason the MOSFETs are heating up. You should use them with a heat sink.
When the output voltage is essential, you should use a relay, if possible.
Thanks for the reply, I will definitely put a cooler, I need to adjust the fan speed and adjust the voltage on the gate using the arduino PMW.
Usually a fan doesn't mind if it's 12V or 11.45V. Alternatively you could provide a little more than 12V on source.
Instead of a MOSFET I have an L298N H-Bridge module. When I try to control the speed of the fan with PWM I can seem to achieve some speed control, but the PWM causes a squealing noise. If I use a MOSFET instead will I avoid this problem or is the issue with the fan itself?
hi nenioc187,
Still need +12V battery supply? because i think the fan's positive terminal has to connect the +12V battery supply.
Thank you for your video.
Since the fan runs on 12 Volts, you'll probably need 12V to run it.. Unless you have a fan that runs on a different voltage
I see. Nenioc. Thank you for your reply.
Hi! I tried building the same circuit but using a usb power supply cable instead. Would this circuit work if I used a 9v USB power supple cable and 8 amp transistor instead of the 17 amp transistor u used? Thanks so much
The fan I am using is a 12 v 4 wire fan
The reason I used this MosFet is, because it was the only one I had ;-). Well I also have a 12V computer-fan, which I power with only 9V. It works. But it won't rotate fast.
Thank you for the reply and . If I use a TIP102, should I be fine? I keep trying the circuit and it isn't working for me. When I touch the gate to the positive end of the power supply cable, nothing happens. Thanks!
and the weird thing is when i connect the drain to the gate, the fan spins. Any suggestions? thanks
Oh god, thank you. Spend 3 days on this trying different transistors and mosfets :P
what about the pwm wire from fan (the yellow one), we dont need to use that?
Not in this test. The fan speed is controlled by supplying the voltage and removing it again with help of the mosfet, that is controlled by the Arduino. If you're interested in controlling it through the yellow cable, I'll put it on my bucket list.
Yes please do so, that would be very helpful, also i am using an NPN transistor with a 1n5408 diode across the motor, is that connection safe?
Thanks for the hint, Joe! I think, I also have one of those 4-wire fans somewhere.
Sir how do i insert the buttons to increase or decrease the speed of the fan???
Tnx...
You have very unique and calm approach. I like it.
Thanks!
Hey y’all
Just started arduino and was curious as to how he input a value of 1000 in the analogWrite function. I thought this only took values from 0-255. Thank you!
You're right. It's 0-255. A glitch in making this video.
how many processes a single Arduino UNO board can do at a time?
The Arduino Uno has six PWM pins. So six.
nenioc187 at what capacity these 6 pins can be used?
Each pin has a maximum output of 40 mA
nenioc187 thanks so much for your response.
please made video with clearly, i'm lil bit confused, such us the resistor, you use that? or not?
No resistor in the video. No resistor used.
Form 5:39 to 6:02 resistor next to the mostef
Oops. My bad.
Yes, there is a resistor between the gate and GND. Because if you open the gate by connecting it to positive, it will stay open ruclips.net/video/Pw1kSS_FIKk/видео.htmlm55s until you connect it to GND. The resistor between GND and Gate will automatically close the Gate if it is not connected to the positive.
However, when the Arduino sends the LOW-value to a pin, it means that it is internally pulled to GND. So technically you don't need a resistor with an Arduino.
I recommend to use a high value resistor anyway, because I noticed that some cheap Arduino clones don't always put out a good 0V- on LOW.
Why did u put resistor here and whch resistor u use?
It should insure that the Gate is pulled to LOW. Without the Arduino the Gate would stay open. But if you connect it to the Arduino and pull the pin to LOW, you don't have to use the resistor.
A value of 10K will be fine. it's not critical.
Nice video Nenioc187, thanks for that. How can we control multiple fans, say 5-6 of them? Shall we use 5-6 mosfets on the breadboard? Anything else to control them via a temperature sensor? Appreciate your help
You could use one mosfet for all Fans, if they all should rotate in at the same speed. If you want to control them all differently, go for one mosfet/fan. And think about using a diode to prevent the fan inducting current to the controller.
nenioc187 One mosfet and one diode will be enough to control 6*12V fans, right? What type mosfet and what type diode?
Depends on the fans, you're using. Check the current consumption of the fans in total and search for a mosfet/diode, that can handle these values.
@@nenioc187 My fans consuming 0.3*6=1.8Amps and my mosfet is IRFZ44. Where and how shall I connect the diode?
@@santonio7283 The flyback diode is connected across the fans, but reverse biased, so that its anode is connected to the MOSFET drain and its cathode to the 12V supply.
Can you do this with a npn bjt transistor? instead of a mosfet?
If it matches the requirements of your fan - sure.
Hello how are you? Could you send me the code if it's not too much trouble?
Great job on this! Well under 10mins and I learned exactly what I wanted. Thank you very much for this!
Thank you. This is the most simple explanation i have watched
Hi there, I want to make IR remote controlled regulator for my A.C. fan. Kindly give suggestion or links if you have.
First of all: Be careful! Mains power is very dangerous!
You can use this videos technique the same way. But instead of a MOSFET, you should use a solid state relay.
nenioc187 thanks a lot..i will ensure the safety and try this out.
can you please tell me the cost of the fan used in your experiment
I savaged it from an old computer. So it didn't really cost me anything. If you search for "12v pc fan" on eBay, you'll get many hits from 1€ up to 20€. But that one for 1€ will do.
nenioc187 thanks for the information
I thought analogwrite only went from 0-255, not to 1000
That's correct! It's a mistake in the video. Sorry.
is 300 and 1000 speed of RPM?
Good video, thank you! I don't have a mosfet but was able to do it with an NPN transistor
I loved this guy in the first 45 seconds. Rare wonderful exceptional person. Thank you for who you are. Top number 1 subscription.
On ... Off... On... Off... OnOffOnOffOnOff
Great Video. I made this exact circuit just as an experiment; however, my fans are turning very slow. Any suggestions - How could I draw more current into the fan? Or how could I decrease the overall resistance?
First of all, you need to discover why the fans are turning slowly. Try disconnecting the gate of the MOSFET from the Arduino and connecting it to a higher voltage, but no more than 10V. If that solves the problem, then it shows that your IRF530 isn't turning on fully with just 5V. It's not guaranteed to do so, and you are always better using an IRL530 when driving it from a microcontroller. The 'L' signifies a logic-level MOSFET and the IRL530 is guaranteed to turn on with a maximum resistance of 0.16 ohms and supply up to 15A when it has 5V on its gate.
Wish I had a teacher like you. It's never late anyway. You are my teacher now 😀
It would be an honor!
can we apply 220VAC across drain to source
No, Mosfets are DC Devices and besides that the Voltage is WAY too HIGH. If you want to switch AC devices you need to use a TRIAC instead of a MOSFET Transistor. Google Triacs and Arduino
Great video! Finally, I grasped this concept. Thank you!
Hi great video. Can you control 3 fans at different speeds with one arduino? Cheers
Yes. You need 3 PWM pins for the MosFets.
@@nenioc187 thanks!
Very nicely explained! -I might have something for your bucket list though :) -How would you control a device (a peltier for instance) that does not stand the PWM ripple well, while also introducing a lot of noise in sensitive devices around?.. -Is there a way to 'smooth' that ripple or simply use/create a continuous/proportional signal for control?..
Usually you can use a capacitor to smooth the PWM signal a little. I haven't tried it yet to control a peltier element - although I've laying them around for quite a while.
Yup, that could also work I guess... Thanx! -Since I see you've worked with several different temperature sensors, you might (also:)) want to try a peltier+fan based temperature control project; see how stable around the set point you can get ;) -Cheers!
Using peltier and fan to create a controlled environment? Hmm... sounds interesting. That will go to my bucket list. Damn, my bucket list is becoming huge.
:D
@@nenioc187 If you use a capacitor on the MOSFET gate to smooth the PWM signal, then you must include a resistor between the I/O pin and the capacitor to prevent the initial charge current on switching from exceeding the rated 20mA for an Arduino pin. A minimum of 270R would be needed. However, once you've smoothed out the PWM signal, you're operating the MOSFET in its linear region, rather than switching it, so it will get hot and may need a heatsink. If you use a (much larger) capacitor across the load, you'll probably want to add some series resistance between the drain and load as well to limit current spikes as the MOSFET switches.
A PWM (pulse width modulation) dimmer is not suitable for a fan motor speed controller. They are typically used for LED dimming, but it causes the squealing many people are hearing on their fans when trying this circuit. This fan motor in this video seems to be okay with it, but almost all fans will not like it and will squeal LOUDLY. It's also hard on the fan motor. The MOSFET circuit here in the video is okay for on/off control, although it really should have a flyback diode on it as well to protect the MOSFET from back inductance when the fan shuts down:
en.wikipedia.org/wiki/Flyback_diode
To properly control the speed you need to convert the PWM square wave signal to a DC voltage using an RC filter coupled to an op amp driving an LM317 voltage regulator. You can find this circuit on the internet in various places, like this:
www.edn.com/design/analog/4363990/Control-an-LM317T-with-a-PWM-signal
The problem with the LM741/LM317 circuit is that the output voltage range is limited to between around 1.25V to around 10V or perhaps less.
You would be better off with a more modern opamp that can swing its output rail-to rail and a normal NPN medium power transistor like a BD135 or BD235 depending on how much current you need.
I can't find code. Plz tell me the codes. Thanks
Do you talk about the transistor code or the code in the arduino, if it’s the transistor code, a link is in the description
Haben Sie sich schonmal an einem "automatischen Gewächshaus" versucht?
Schon mal darüber nachgedacht. Aber nie umgesetzt.
is it possible to scale this up with multiple fans?
+Jackson as long as you have free PWM pins available you can contol multiple fans at once
sweet so 6 on an UNO? can you make each one independently react to separate sensors? for example 6 thermos impacting 6 fans?
+Jackson Sure
Could someone possibly right me a scriypt i'm wanting to use a arduino as a indicator relay on my old mans classic bike, so i would be using an arduino and 2 relays anyone able to help out? Thanks
Thank God you explain so good , you are a life saver, a subscriber from now on
Hello where do you bought this blueprint ?
+NOUVELLE CHAÎNE ; TOBITHD Found it in eBay. They are available in green and blue
Very nice and enjoyable presentation. I'm going to save this for teaching my grandchildren!
Gutes Video. Kann man das nicht auch mit einem Relais machen?
Thanks! Sure you can do this with relays. But you should go for the solid state relays. They are more reliable, faster and more quite ;-)
Thank you so much, bro! You explained it so well, now I am able to control a motor with Arduino! All because of you. *brofists*
+aditya raj My pleasure. I'm glad to help!
Keep making videos your very good at it. This video helped me with my project
Uiiiiiuuuiiiiiuuuuiiiiiuuuu! Explains better than any other video
Hi nenioc187, great video, thank you! Could I ask, what is the maximum voltage for a fan or any output for that matter that could be controlled using this sort of transistor? Could I use a fan that is 220-240V (100mA) to reduce its RPM? And if not, why not? :) Many thanks!
I assume that your fan is 220-240V AC, so this circuit is not suitable as it is intended for DC applications. Mixing mains voltage with microcontrollers is fraught with problems and usually requires the use of an opto-isolator and a triac to control AC mains devices along with many precautions in layout. That really isn't suitable for a beginner.
For DC use, the IRL530 is rated at 100V and 15A (although not both at the same time), but again, high voltages are not suitable for beginners, and I'd strongly recommend investigating projects that require no more than 24V and a few amps while learning.
Hi neioc187, awesome work here. Ordered some IRF530N Mosfits and got it up and running just as you showed us. I have tried two different fans and both make a buzzing sound anything less then 1000. Is this a normal function of controlling the rpm with a Mosfit or is there a way to get rid of the buzz ?
I would suggest getting some IRL530s next time as they are made for interfacing with logic-levels of 5V or less (unlike the IRF530, which is intended for use with 10V gate voltages). A capacitor and a reversed diode across the fan to suppress the transients might reduce the buzzing. If that fails, then maybe try putting a resistor in series with the fan to reduce the maximum voltage across it. It will lower the maximum fan speed but should make lower speeds smoother. You'll have to determine the resistor value by trial-and-error, but you could perhaps start with a 33R 0.5W resistor and see what happens.
Can we control a micro motor with it
The fan is a motor. So yeah. But for motor controlling I would rather recommend using a PWM enabled H-bridge.
How to control ac fan speed with ir remote control system plse make a videos
Great !
I could relate the concept of the video to PWM chopper signal.
Listening to this as a mech e i appreciate the pipe analogy. Thanks!
i Love you so much i didnt understand the part of common ground in the third leg in other videos and you enlighted me
You are very good at teaching my friend. Keep going. Thanks for sharing this.
This Can control our ceiling big fans?
I don't know your ceiling fans. But I guess it'll be a little more complex.