Sub topic 1
Why an Arduino Pin Cannot Power a Motor
An Arduino pin can tell a motor what to do, but it cannot supply the current the motor needs. This chapter explains the electrical limits of the pin, what a motor demands, and why a driver circuit and a separate power source are required. The later chapters build those circuits.
Prerequisites
This chapter assumes you can do the following:
- Upload a sketch with the Arduino IDE.
- Write basic Arduino C++:
setup(),loop(), variables, and functions. - Use
pinMode()anddigitalWrite(). - Read basic circuit ideas: voltage, current, and ground. You should know Ohm's law, V = I × R.
- Build a simple circuit on a breadboard.
The core problem: signal versus power
An I/O pin is a signal source. It is designed to drive the input of another chip, light an LED through a resistor, or switch a transistor. These loads draw milliamps. A motor is a power load. Even a small hobby motor draws hundreds of milliamps in normal running and more than an amp when it is blocked.
Think of the pin as a light switch's wire rather than the mains supply. The pin should decide when and how much power flows. It should not be the path the power flows through.
Pin current limits
Each pin on the output side is a pair of small transistors inside the microcontroller. One connects the pin to the supply (to make it HIGH). The other connects the pin to ground (to make it LOW). These transistors are tiny, so the current through them is limited.
The numbers below are for the ATmega328P used on the Uno and Nano. Check the datasheet for your board, because other chips differ.
| Limit | Value (ATmega328P) | Meaning |
|---|---|---|
| Recommended per pin | about 20 mA | Continuous current you should plan for |
| Absolute maximum per pin | 40 mA | Damage can start above this |
| Total across all I/O pins | 200 mA | Sum of every pin's current |
| Per port group (VCC or GND side) | 100 mA to 150 mA | Depends on which pins; see the datasheet |
A small hobby DC motor commonly draws 100 mA to 500 mA while running freely, and the stall current can be several times higher. Even the lightest motor exceeds the recommended pin current. A typical micro servo draws around 100 mA to 250 mA while moving and can pull 500 mA to 1 A or more under load.
What happens when you exceed the limit
Overloading a pin does not always fail at once, which makes it a dangerous habit. Possible outcomes include:
- The pin voltage sags. A HIGH output that should read 5 V drops to 3 V or lower, so the motor runs weakly or erratically.
- The output transistors overheat. The chip gets warm, and the pin may stop working.
- The damage spreads. A burned pin can leave the whole chip unreliable, not only that one pin.
- The board resets or behaves oddly, because the pin load pulls on the chip's internal supply.
A pin that "works" when you test it can still have been degraded. Treat the limits as design rules and not as suggestions.
What a motor demands
A motor differs from a resistor or an LED in three ways that matter here.
- Running current is large. The motor does mechanical work, so it needs real power. A 6 V motor drawing 300 mA uses 1.8 W. A pin at 5 V and 20 mA delivers 0.1 W.
- Starting and stall current is larger still. When a motor is stopped, nothing opposes the current except the winding's small resistance. The current at the moment of start, or when the shaft is blocked, can be five to ten times the running current. A later chapter covers this stall current in detail.
- It is an inductive load. A motor's windings store energy in a magnetic field. When you switch the current off, the field collapses and produces a voltage spike that can be much higher than the supply. That spike can damage a pin or a transistor. A later chapter covers the flyback diode that handles it.
Any one of these makes direct connection a poor idea. Together they rule it out.
A worked example
Suppose you have a small 5 V hobby DC motor. The datasheet says it draws 250 mA free-running and 1.2 A stalled. You connect it between pin 9 and GND and call digitalWrite(9, HIGH).
- The motor tries to draw 250 mA. That is more than 12 times the recommended 20 mA, and six times the 40 mA absolute maximum.
- The pin cannot deliver this. Its voltage collapses, and the output transistor heats up.
- If the motor starts from rest, the initial surge is higher still.
- When you later set the pin LOW, the collapsing magnetic field sends a spike back into the pin.
The motor might twitch, or the board might reset, or the pin might burn out. None of these outcomes is acceptable.
The solution: a driver and a separate supply
The fix has two parts, and each solves a different part of the problem.
- A driver is a component that switches a large current when it receives a small control signal. Examples are a transistor, a MOSFET, or an H-bridge chip. The Arduino pin sends only the tiny control signal. The driver carries the motor current.
- A separate power source supplies that motor current. This can be a battery pack or a regulated supply rated for the motor. The Arduino's own power path is not used for this current.
The dotted line in the diagram matters. The control signal is a voltage measured relative to ground. The driver can only interpret it correctly if the Arduino and the motor supply share the same ground reference. The next chapter covers this common ground and why leaving it out is a frequent cause of "it does nothing."
Why not use the 5 V pin on the board?
It is tempting to connect the motor to the Arduino's 5 V pin and use a transistor to switch it. This avoids the I/O pin limit, but a different limit takes its place.
- When the board is powered by USB, the 5 V rail is limited by the USB port, typically 500 mA, and shared with the rest of the board. A computer port may also shut down or reset when overloaded.
- When the board is powered through the barrel jack or VIN, the 5 V comes from an onboard linear regulator. That regulator turns surplus voltage into heat, and it overheats quickly with a motor load.
- Motor current spikes pull the 5 V rail down and add noise. The microcontroller then browns out and resets.
For a very small, lightly loaded motor, some people do this and it can work. For anything that stalls, starts under load, or runs a servo that moves a mechanism, use a separate supply.
Servos are motors too
A hobby servo looks like a small module with three wires, so it is easy to think of it as a signal device. It is not. Inside the case are a DC motor, a gearbox, and a control circuit. The control wire carries only a low-current signal, which is fine for an I/O pin. The red and brown wires carry the motor's power, and they do not belong on an I/O pin.
A single micro servo on the 5 V pin often works for short tests, since the load is light. Moving several servos, or one under load, can exceed what the board's 5 V supply can deliver. The result is a reset, jitter, or a servo that twitches. Chapter 2 covers the wiring for this case.
A quick way to check a load
Before connecting any new part to a pin, run through these steps.
- Find the current the part draws, in the datasheet or on the product page. Look for the maximum or stall figure, and not only the typical one.
- Compare it with 20 mA for a pin. If it is higher, the part needs a driver.
- If the part needs more than a few tens of milliamps in total, give it a separate supply and do not draw it from the 5 V pin.
- If the part is a coil (motor, relay, solenoid), plan for a flyback diode.
The same check works for relays, solenoids, buzzers, and strips of LEDs.
// A load check you can run on paper, written as code.
// Replace the numbers with your part's datasheet values.
const float PIN_SAFE_MA = 20.0;
const float PIN_MAX_MA = 40.0;
void setup() {
Serial.begin(9600);
float runningMa = 250.0; // free-running current
float stallMa = 1200.0; // blocked-shaft current
Serial.print("Running vs safe pin limit: ");
Serial.print(runningMa / PIN_SAFE_MA);
Serial.println("x");
Serial.print("Stall vs absolute pin limit: ");
Serial.print(stallMa / PIN_MAX_MA);
Serial.println("x");
if (runningMa > PIN_SAFE_MA) {
Serial.println("Use a driver. Do not connect directly to a pin.");
} else {
Serial.println("A pin may drive this load directly.");
}
}
void loop() {
}With these values the sketch prints a ratio of 12.5 for the running current and 30 for the stall current. It then tells you to use a driver.
Common mistakes
- Trusting a short test. A motor that spins for ten seconds from a pin has not shown the pin is safe. The damage may be cumulative.
- Summing the wrong thing. The 200 mA total limit applies to all pins together. Four pins at 20 mA each are fine, but ten pins at 40 mA each are not.
- Using the datasheet's typical current. Size for stall current, because that is what the supply and driver meet when a mechanism jams.
- Forgetting the diode. A driver handles the current, but the inductive spike still needs a flyback diode.
- Skipping the common ground. The motor supply and the Arduino must be tied together at ground.
Summary
An I/O pin supplies about 20 mA safely and 40 mA at most. Motors draw hundreds of milliamps when running and more when starting or stalled, and they produce voltage spikes when switched off. A driver carries the motor current under the control of a small signal from the pin. A separate supply provides that current, with its ground tied to the Arduino's ground. The following chapters build each part of that design.
Exercise
A small DC motor draws 180 mA free-running and 900 mA stalled. A student connects it directly between an Arduino Uno pin and GND. By what factor does the running current exceed the recommended 20 mA pin current, and why is this wiring unsafe even if the motor spins in a short test?
Show answer
The running current is 180 / 20 = 9 times the recommended pin current. The stall current of 900 mA is 22.5 times the absolute maximum of 40 mA. The pin cannot supply this without its output voltage sagging and its output transistors overheating. A short test may succeed while still degrading the pin. The motor is also an inductive load, so switching it off sends a voltage spike into the pin. The motor should be switched by a driver such as a MOSFET or H-bridge from a separate supply with a common ground.
Exercise
Why is connecting a motor to the Arduino's 5 V pin, switched by a transistor, still often a poor design?
Show answer
The transistor avoids the I/O pin limit, but the 5 V rail has its own limits. Over USB it is capped at about 500 mA and shared with the board. Through VIN or the barrel jack it comes from a linear regulator that overheats under motor load. Motor current surges also pull the rail down and add noise, which can brown out and reset the microcontroller. A separate motor supply with a common ground avoids these problems.