As far as I know, the digitalWrite command outputs 5v.
If a fan has an operating voltage of 5v, that means I can connect its negative wire to GND and positive wire to an Arduino port with digitalWrite(HIGH); and it will work without a relay?
Make a WWW scan and you find a lot of PC Fan tutorials
Please don't give advice on the forum until you are more experienced. The advice you give, while correct in some ways, would destroy the Arduino.
Actually the problem is surely that if the fan needs more current than the pin can provide the pin will be overloaded and damaged.
Datasheet of the first 5V pc fan I found with Google says its current is almost 200mA, that's 10x the current you can safely draw through an i/o pin.
These are the fan specifications:
Max. input power: 0,85 W
Max. input current: 0,17 A
Operating voltage: 5 V
The Arduino cannot provide enough current to drive that fan... you will likely kill the Arduino.
You need some kind of electronic switch... triggered by the Arduino. Some kind of relay or transistor circuit... Google is you friend.
And Arduino forum is also my friend.
Yes.. but most of the people here aren't interest in doing the work for you. If you demonstrate you have tried, and are still stuck - then you will get a lot more support.
That's not strictly true: an Arduino i/o pin cannot supply the current, and while yes that's what the OP was asking about, that answer's too general. It would be feasible* to use the 5V output as the supply, and switch that with a transistor controlled by the i/o pin provided the total power to be dissipated by the Arduino regulator is not too much. I can't find that number right now... 500mA rings a bell but don't quote me.
*that said, it goes against the grain to use a microcontroller as a power supply even if it's in its limits.
Yes, but in some situations (like this one) it is better to ask before trying something to avoid burning your board.
Pedantic reply... that's obviously what I meant, and was what the OP was doing.
Almost any small, general purpose, NPN transistor will be able to switch this, for example bc337. But there are 2 other components you MUST use. You must use a resistor to limit the current flowing from the Arduino pin to the base pin of the transistor, for example 330R. This will protect the Arduino pin from damage by too much current. You must connect a diode across the wires from the fan, with its cathode to the + fan wire and anode to the - fan wire. This diode will protect the circuit from the negative voltage that is created when you switch the fan off. 1N4004 or similar will be suitable.
We most certainly will not.
Best advice - do not attempt to power the Arduino via "Vin" or the "barrel jack" for any "real world" project. May be OK for just the Arduino board itself and a couple of indicator LEDs drawing 20 mA each, but how useful a project does just that make?
The USB connection from a PC can generally provide 500 mA through to the "5V" pin but the voltage tend to drop significantly at that level. While not connected to a PC (on a UNO/ Leonardo/ Mega 2560; it does not matter on a Nano) you can and in fact should power the Arduino with regulated 5 V to the "5V" pin.