# How do I (easily) power a 5 V 3-pin fan?

I have a 5 V 3-pin fan. I want to be able to:

1. power it from an Arduino Uno or a Seeeduino Lotus board, and, ideally;
2. be able to change its speed.

Most resources I can find on the web explain how to connect a standard 12 V fan and moreover complicate the thing by explaining how to get the speed of a fan or to control multiple fans. This is way too complex for me.

If my understanding is correct, I can't just connect a fan to analog output pins, because the absolute max power per pin is 40 mA (recommended: 20 mA), while the fan uses 100 mA.

Instead, I have to somehow connect two of the three pins of the fan to an external power, and use the third pin to control the speed. Am I supposed to use the ground and 5 V pins situated on the left side of the board above ANALOG IN?

If not, what are my other options? The board is powered by an USB cable, and I see no way to split the power at this level between the board and another device without running a risk of damaging the board.

You are correct in your assumption that you can not power a fan from an Arduino directly.

Use a transistor, for example 2N2222 or BC548, which is switched by the Arduino, using a single pin, in order to provide sufficient current to the fan.

Such as this simple circuit (note that the 12V supply would be 5V in your case):

However, as chrisl has pointed out, you fan has three pins and not two. The above circuit will only work for a two pin fan. In your case, for the reasons stated in Chrisl's answer, one pin goes to 5 V supply, one to GND and then third goes directly to the Arduino - let's say pin 3. Then you can use the code below.

Assuming that the fan is connected to pin 3, then the code will look like this:

const int fan = 3;

void setup() {
pinMode(fan, OUTPUT);
}

void loop() {
int fanSpeed = 255;
analogWrite(fan, fanSpeed);
}

This will run the fan at full blast. However, you can thereafter modify your code to vary the value of fanSpeed.

Furthermore, by reading an analog input pin (let's assume that you have a potentiometer hanging off A0), using analogRead(), you can use the read value to modify the value of fanSpeed directly (by dividing the value returned from analogRead() by four2 and then sending to analogWrite(), like so:

int potPin = A0;
analogWrite(fan, fanSpeed);

or even more succinctly, do away with fanSpeed completely and use:

int potPin = A0;

1 Note that the code in the link in incorrect as it attempts to write values greater than 255 using analogWrite(). As stated here, Arduino reference - analogWrite(), analogWrite() takes values of 0-255, whereas analogRead() returns values of 0-1023

2 See the loop() function in Arduino reference - analogWrite() for another example.

• The OP has a 3 pin fan for 5V, not 12V. The third pin is already connected internally to a driver (propably a MOSFET), which can be driven with PWM. So the extra MOSFET is not needed here. Commented Jun 29, 2018 at 21:43
• @chrisl - ah yes, you are quite right. I read the question in too much of a hurry. Your answer is more correct. I shall modify mine to make note that the voltage is 5 and not 12V. Thanks Commented Jun 29, 2018 at 21:47
• Sorry, but command back >.< As VE7JRO pointed out these fans are different than the normal stock fans in that the third pin is actually the pin, which reports back the RPM. Didn't knew that, but we are always learning. I will delete my answer, since it is false. Yours is correct. Commented Jun 29, 2018 at 22:19
• @chrisl - eh? Oh dear. I am a bit busy now to understand. Please undelete your answer, as it is probably useful, and I want to read it again anyway. You can always delete it later - if need be. You were right about outputting 255 and not 1023 anyway. :-) Commented Jun 29, 2018 at 22:22
• Yes they control their own speed by having hall sensors to detect the position of the rotor and apply voltage to a specific coil just at the right time. If your pwm signal is low at that moment, it doesn't work. The speed can be controlled by the analogue voltage in these motors. Commented Jun 30, 2018 at 12:34

EDIT:

As VE7JRO pointed out the fan you are using does not have a native PWM pin. The third pin is actually reporting back the RPMs of the fan. So you need to follow Greenonline's answer by using a MOSFET. For now I will leave my answer here for reference. If wanted I will delete it later.

A 3-pin fan is controlled like a servo. The current for actually driving the motor flows through the power pins (5V and Ground). The third pin takes a PWM (pulse width modulation) signal to determine the wanted fan speed. This is just a signal line, there is only very little current flow, so that the Arduinos pin will not be damaged. So the motor driver is already included.

From the programming side you can use analogWrite(), which outputs a PWM signal at one of the PWM-capable pins. The speed of the fan is controlled via the duty cycle of the signal. 100% (value of 255 for UNO) means full speed, 0% (value of 0) stops the motor.

About the power supply: Since your fan uses 100mA at full speed (I assume), it is still possible to power it over the 5V pin of the Arduino. You can source about 500mA over it (including the current for the Arduino itself). When sourcing higher currents over the USB plug, the polyfuse will be fried. This is the value for the UNO r3. A Nano can source only 200mA, because the diode will be fried.

So be carefull how much current you draw from the 5V pin of the Arduino. Or, if you have greater current requirements you have to supply an extra voltage to drive the fan.