A digital pin's output voltage on an UNO board is 5V, which is equal to the output from the VCC. I read that the DC current limits of those pins are 40mA and 200mA respectively, and that a higher current could damage the board. Now, since V=RI, I expect to get the same current whether I connect a DC motor to the VCC or to a digital pin. But, the motor spins slower when connected to the digital pin. Therefore, I'm not getting the same current, and the only thing I could think of in order to explain this apparent contradiction with ohm's law is that there must be some mechanism to keep the current flowing through a digital pin inferior to 40mA. But I also read somewhere (can't find/remember the source) that there are no such mechanisms (except for a fuse concerning the USB)... So as you see, I can't understand what's going on. It will be really nice if someone could explain that to me... thanks in advance!
The ATmega (or any other processor that could reasonably be used on an Arduino) output pins consist of a
Totem Pole driver with a PMOS transistor which can drive the output towards Vdd and an NMOS transistor which can drive it towards ground. Each of these can be modeled as a switch which has a small resistance when "on", and due to device physics the PMOS transistor has a higher resistance than the NMOS.
The 40ma figure is an "Absolute Maximum" rating - a limit above which damage could be possible. At some current less than that, it is likely the voltage drop across the PMOS transistor will start to be great enough that the output voltage can only marginally be considered a logic "high" - it will be notably less than the supply.
Connecting your motor to an ATmega pin is an extreme, far out of spec. When you do that, the voltage drop across the PMOS transistor is much larger, making the output voltage quite low. Additionally, the current flowing through the resistance produces heat within the chip, which can (at least as a rule-of-thumb concern) lead to damage. Finally, your motor will produce
inductive kickback, "spike" voltage possibly high enough to pierce the gate oxide of the MOS gates in the chip, destroying it.
Latchup is another possibility - a sometimes temporary condition where the bulk of the die ends up biased to conduct in the wrong direction and the chip effectively shorts out its power supply, turning it into a miniature space heater.
There really are no components on your typical Arduino board designed to directly control a motor.
Instead, for unidirectional control you should use a circuit with an
NPN bipolar transistor,
NMOS FET, magnetic relay, or solid state relay. The latter are commonly available pre-assembled on shields. With a transistor solution driving the motor in only one direction, it is generally advisable to pick an NPN transistor or NFET and place it in the negative lead of the motor, as the N devices work better due to the greater mobility of electrons than electron-holes.
For bidirectional control, look for a
motor shield based on an
H bridge IC such as the
TB6612FNG or the less efficient bipolar
SN754410. This basically puts a high current
Totem Pole driver on each lead of the motor, allowing you to drive them high & low for one direction or low & high for the other.