How do I (easily) power a 5 V 3-pin fan?
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):


  


Source: Driving a PC fan - transistor with or without an optocoupler?1

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&nbsp;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;
  fanSpeed = analogRead(potPin)/4;
  analogWrite(fan, fanSpeed);


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

  int potPin = A0;
  analogWrite(fan,analogRead(potPin)/4);




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.