DC Fan Control (Switching on/off)
There are plenty of ways, Here's two: -



Note the diode across the motor - this is needed to protect the BJT (or MOSFET) when the transistor is switched-off - this circuit will be OK for low-power fans. Rate the transistor in accordance with the current the fan needs.

Or...



This circuit will run from 5V or a lot higher should your fan be (say) 24V or 12V. Not shown is the reverse connected diode which you must have.

Pick a P-channel MOSFET with low "Vgs(threshold)" to ensure it turns on properly