Sub topic 2
Powering motors separately and sharing a ground
This chapter covers where a motor's power should come from and how to connect that supply to your Arduino so the control signals still work. It assumes you know what voltage, current and ground mean, can wire a breadboard, and have read the previous chapter on why an I/O pin cannot drive a motor. Later chapters on servos, MOSFETs and H-bridges all rely on the wiring rules here.
The rule in one sentence
Power the motor from its own supply, send control signals from the Arduino, and connect the ground of the two so the signals have a shared reference.
Two separate ideas are involved, and beginners often mix them up:
- Power path. The motor's current flows from the external supply, through the motor, and back to the same supply. The Arduino is not in this loop.
- Signal reference. The Arduino's control signal is a voltage, and a voltage only means something relative to another point. That point is ground.
Why not use the Arduino's own 5V pin?
An Arduino Uno has several places you could try to take power from. None of them suits a motor.
| Source | Typical limit | Problem for motors |
|---|---|---|
| I/O pin | 20 mA recommended, 40 mA absolute maximum | A small motor wants 100 mA to over 1 A. The pin's output stage is damaged or the voltage sags. |
| 5V pin, board powered by USB | About 500 mA for the whole board (USB limit, and a resettable fuse on the Uno) | A stalled motor can pull more than this, and the computer's port may shut down or the board may reset. |
| 5V pin, board powered through the barrel jack or Vin | Limited by the on-board regulator, which turns the extra voltage into heat | A linear regulator gets hot at a few hundred milliamps and shuts down to protect itself. |
The 5V pin is meant for the microcontroller, a few sensors and some LEDs. A motor changes its current demand suddenly. It draws a surge when it starts and a very large current when it stalls. Those surges pull down the 5V rail that your microcontroller also runs from. Chapter 11 returns to this as brownouts and resets.
Choosing a motor supply
Pick the supply from the motor's datasheet, not from what you have lying around.
- Voltage. Match the rated voltage of the motor or servo. Most hobby servos are rated for roughly 4.8 to 6 V. Small hobby DC motors are often rated for 3 to 6 V, but check yours.
- Current. The supply must handle the stall current of every motor connected at once, with margin. A rule of thumb is to size it at about twice the stall current. A 9 g micro servo can draw several hundred milliamps under load, and a standard-size servo can draw more than an amp.
- Regulation. A regulated wall adapter gives a steady voltage. A battery pack sags as it drains and as current rises, which is acceptable for motors but makes the speed drift.
Common choices:
- 4 AA cells. Four NiMH cells give about 4.8 V and suit servos well. Four alkaline cells start near 6 V, at the top of many servos' range.
- A regulated 5 V or 6 V adapter or module. Check that its current rating covers the stall current.
- A LiPo battery. A single cell is 3.7 V nominal and up to 4.2 V fully charged, which is below many servos' range. Packs with more cells give a voltage that is too high for most small servos unless a regulator, often called a BEC, steps it down.
A phone USB charger is a convenient 5 V source if it can supply the current. A USB port on a computer is not, because of its 500 mA limit.
Why the grounds must be joined
Suppose a servo has its own battery, and the Arduino is powered over USB, and the only connection between them is the signal wire. The Arduino sets pin 9 to 5 V relative to the Arduino's ground. The servo's electronics see the signal wire relative to the servo's ground. Because the two grounds are not connected, the servo has no way to relate its signal to its own ground. The reading floats, and the servo twitches, ignores commands or behaves randomly.
Connecting the grounds gives both devices the same zero-volt point. The signal then reads as intended.
Notice what is not in the diagram. The supply's plus terminal goes only to the servo. It does not touch the Arduino's 5V pin.
Wiring a servo with external power
A hobby servo has three wires. The colors vary by brand, but the usual layout is:
| Wire color | Function | Connect to |
|---|---|---|
| Red | Power | External supply plus |
| Brown or black | Ground | External supply minus, and Arduino GND |
| Orange, yellow or white | Signal | Arduino pin 9 |
Steps:
- Power off everything, including USB.
- Connect the external supply's minus to the Arduino GND pin, and to the servo's ground wire.
- Connect the servo's signal wire to pin 9.
- Connect the external supply's plus to the servo's red wire. Leave the Arduino 5V pin unconnected from this wire.
- Plug in USB, then switch on the motor supply.
Here is a sketch to test the wiring. It uses the Servo library, which a later chapter explains in detail. For now it only proves that signal and power both work.
#include <Servo.h>
Servo myServo;
const int SERVO_PIN = 9;
void setup() {
Serial.begin(9600);
myServo.attach(SERVO_PIN);
}
void loop() {
Serial.println("Moving to 10 degrees");
myServo.write(10);
delay(1500);
Serial.println("Moving to 170 degrees");
myServo.write(170);
delay(1500);
}If the servo swings between both ends, power and ground are correct. The test also tells you something when it fails. If the Arduino runs but the servo stays still, check the supply and the ground wire first.
Where the ground connection should be made
A shared ground is necessary, but where you make the connection matters. The motor's current returns to the supply through ground. If that return current passes through the same thin wire or breadboard rail that the Arduino uses as its reference, the wire's small resistance turns that current into a voltage. By Ohm's law, V = I × R. A 2 A surge through 0.1 ohm of rail and jumper resistance is 0.2 V. The Arduino's ground then moves by 0.2 V relative to the motor's ground, every time the motor draws current.
Good habits:
- Use short, thick wires for the motor's power and ground.
- Join the Arduino ground to the supply ground at one point, close to where the supply's minus terminal enters your circuit. This arrangement is called a star ground, because every ground wire runs back to a single central point.
- Keep the motor's high current return path separate from the thin ground wire that serves the Arduino and sensors.
- Do not rely on one long, shared breadboard rail for motor and logic ground when the motor draws an amp or more.
Powering the Arduino and the motor from one supply
Using one supply for both is possible, but it needs care.
- Supply of 7 to 12 V into the barrel jack or Vin. The Uno's regulator produces the 5 V for the logic. If your motor needs the full supply voltage, it can run straight from that supply. If the motor needs a lower voltage, give it its own regulator. Do not take the motor's power from the 5V pin.
- Regulated 5 V supply wired to the 5V pin. This bypasses the on-board regulator. It works only if the supply is a clean, regulated 5 V, and never when USB is also connected. Otherwise two sources feed the same rail.
For a first project, keep two supplies: USB for the Arduino and a separate supply for the motor. It is the easiest layout to reason about and to debug.
Common mistakes
| Symptom | Likely cause | Fix |
|---|---|---|
| Servo twitches or moves randomly | No common ground | Connect the supply's minus to the Arduino GND |
| Arduino resets when the servo moves | Servo powered from the 5V pin | Move the servo power to the external supply |
| Servo does nothing, Arduino runs normally | Supply off, wrong polarity, or red wire not connected | Check the supply voltage with a multimeter |
| Servo stalls or buzzes under load | Supply cannot deliver enough current | Use a supply with a higher current rating |
| Works with the Arduino on USB, fails on battery | Battery voltage sags under load | Use fresh cells or a larger pack |
A quick multimeter check
Before blaming the code, measure:
- With everything off, set the meter to continuity mode. Touch one probe to the Arduino GND pin and the other to the supply's minus terminal. A beep confirms the grounds are joined.
- Switch on the supply. Measure between the servo's red and brown wires. The reading should match the supply voltage.
- Run the sketch. If the voltage across the servo falls well below the supply voltage when it moves, the supply or its wiring cannot deliver enough current.
Exercise
A servo is powered from a 4-AA battery pack. Its signal wire is connected to Arduino pin 9, and the Arduino is powered over USB. The battery's minus terminal is not connected to anything else. The servo jitters and ignores commands. What is wrong, and what is the fix?
Show answer
The battery ground and the Arduino ground are not connected, so the servo has no common reference for the signal on pin 9. Connect the battery pack's minus terminal to an Arduino GND pin (and keep it joined to the servo's ground wire). The battery's plus should still go only to the servo's red wire.
Exercise
A motor supply is rated 5 V and 1 A. Your servo's stall current is 0.8 A, and you add a second identical servo. Is the supply adequate if both servos can stall at once? What would you choose instead?
Show answer
No. Two servos stalling together would need about 1.6 A, which exceeds the supply's 1 A. Choose a supply that provides at least about twice the combined stall current, so a 5 V supply rated for 3 A or more would be a reasonable choice.