Wawa:
Quick and dirty lesson of how a mosfet works.
A mosfet can be "on" or "off" when you leave the gate floating.
Depending on the charge (voltage) that happens to be on the gate.
Touch GROUND with one finger, and the gate with another finger, and the mosfet (motor) will turn off.
Touch POSITIVE supply with one finger, and the gate with the other, and the mosfet (motor) turns on.
Yes, that's all a mosfet needs.
Don't touch the gate first though. You might have a body charge that can zap the mosfet to silicon heaven.
Same with connecting a mosfet to the Arduino.
Make sure the common grounds are connected.
Then plug the gate wire in the Arduino first, and then connect it to the gate.
Generally two resistors are used on the gate.
One to ground 10k,100k, whatever.
This is not needed when the Arduino is working, but it keeps the gate nicely at ground potential during off and startup.
One 220ohm current limiting resistor between Arduino and gate, to limit Arduino pin current during switching.
Not strictly needed, but it makes it easier for the Arduino.
Because the gate is a (2nF in this case) capacitor that has to be charged/discharged.
If you switch inductive loads like a relay or a motor, a flyback diode on the drain is also needed.
Leo..
Although in theory what you said in red is correct, in reality it's completely not necessary.
The mosfets in the output pin drivers can be damaged by HEAT (such as shorting a "high" pin to ground for an extended period of time). The point is it takes TIME (milliseconds to seconds) for a damaging amount of heat to build up.
That's why, for example, you can PWM light emitting diodes that are directly connected to output pins safely. Although the current at a particular instant can be "too high", the average current (and therefore the power dissipation and heat) are low enough to not damage the chip.
With the mosfet, the microsecond-range current spike caused by charging or discharging the gate will dissipate so little power it's probably almost impossible to measure. It certainly will never hurt the AVR output pin driver.
In fact, a series resistor, along with the gate capacitance of the mosfet (AND the Miller effect) will cause the mosfet to turn on and off much more slowly than it could and, if it's being used as a high current PWM controller, the slow switching times will keep it in the linear region longer and raise IT'S power dissipation and heat.
Since a series resistor between the gate of a mosfet and an output pin:
- Doesn't do any good
- Costs money
- Consumes PCB real estate
- Makes the mosfet work much harder
....I see little reason to use one. 