Learn Arduino Tutorials Open the 3D lab

Beginner · 5 min read

DC motor explained: how it spins and how to drive it with Arduino

Magnets, a coil and two tiny brushes — that's all it takes to turn electricity into spin. Learn what's inside a hobby motor and how an Arduino controls its speed without frying a pin.

A small 130-size DC hobby motor with its two connections, shown alone in the 3D lab
Build it yourself in 3DFree, in your browser — no board, no wires, nothing to buy.Open the 3D lab →

What you need

  • Arduino UNO R3 (or a compatible board)
  • USB cable (A to B)
  • Half-size breadboard
  • Jumper wires (male–male)
  • Small DC motor
  • TIP120 transistor
  • 1 kΩ resistor
  • 1N4001 diode

Don't have the parts? Build it in 3D first.

What it is

A DC motor spins when current flows through it. The one in our lab is a 130-size hobby motor, the kind inside toy cars and handheld fans. It runs on 3–6 V and draws about 0.5 A at full speed on 5 V. It has just two connections, + and −. Swap them and it spins the other way.

That half an amp is the catch: an Arduino pin can give only about 20 mA. So a motor is never wired straight to a pin — a transistor switches it, and the pin only tells the transistor what to do. See it in 3D.

How it works

Inside the metal can are two curved magnets. In the middle sits a spinning part (the armature) wound with coils of thin copper wire. When current flows through a coil, it becomes an electromagnet: it is pushed away by one magnet and pulled towards the other, so it turns.

Just as it would stop, two springy brushes rubbing on a split ring (the commutator) swap the current to the next coil. The push starts again, and again — thousands of times a minute. That is the whole trick.

The numbers our lab uses

Value
Winding resistance8 Ω
Transistor when onabout 2 Ω
Full-speed current5 V ÷ (8 Ω + 2 Ω) = 0.5 A
Pin limit20 mA (40 mA absolute)

In the 3D lab the motor's speed follows its current: 0.5 A is full speed, 0.25 A is half speed. Watch the current dots flow through it.

Speed: PWM

A pin is either 5 V or 0 V — there is no "half". So analogWrite() cheats: it switches the pin on and off about a thousand times a second, and the number (0–255) sets how much of each moment it is on. The motor is too heavy to follow each flick; it feels the average.

analogWrite valueOn forAverageThe motor
00 %0 VStopped
6425 %≈ 1.25 VSlow (a real motor may not start)
12850 %≈ 2.5 VAbout half speed
255100 %5 VFull speed

More in PWM explained.

Pins

PinGoes toWhat it does
+5VPower in
−The TIP120's collectorThe transistor completes the path to GND

How to wire it to an Arduino

  1. Motor + → 5V.
  2. Motor − → the collector of a TIP120 transistor.
  3. TIP120 emitter → GND; its base → 1 kΩ → pin 6.
  4. A 1N4001 diode across the motor, band towards 5 V, to catch the spike when it stops — see what a diode does.
Press Play: the fan speeds up, holds full speed, then stops
Press Play: the fan speeds up, holds full speed, then stops · open it full screen

Example code

From the motor project:

const int MOTOR = 6;   // a ~ pin, through the transistor

void setup() {
  pinMode(MOTOR, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  for (int speed = 0; speed <= 255; speed += 15) {
    analogWrite(MOTOR, speed);
    Serial.print("speed ");
    Serial.println(speed);
    delay(150);
  }
  delay(1500);
  analogWrite(MOTOR, 0);
  Serial.println("stop");
  delay(1500);
}
  • for (int speed = 0; speed <= 255; speed += 15) climbs from stopped to full speed in 18 steps.
  • analogWrite(MOTOR, speed) sets the share of time the transistor is on.
  • delay(1500) holds full speed, then analogWrite(MOTOR, 0) stops it.

Common mistakes

  • Motor straight on a pin. 5 V through the pin and 8 Ω is about 150 mA — the pin burns (it does in the 3D lab). Always use the transistor.
  • It hums but doesn't turn at low values. Small motors need a push to start. Start at 255 for a moment, then slow down, or find the lowest value your motor still turns at and stay above it.
  • The board resets when the motor starts. The motor's starting current makes the 5 V dip. Use a separate battery for the motor (sharing GND with the Arduino) for bigger motors.
  • Spins the wrong way. Swap the two motor wires.

Check yourself

  1. Why can't you connect a DC motor straight to an Arduino pin?

  2. What does analogWrite(6, 128) do to the motor?

  3. How do you make a DC motor spin the other way?

Questions people ask

How do I reverse a DC motor with Arduino code?

A single transistor can only switch it on and off. To choose the direction from code you need an H-bridge — four switches in one chip, such as the L298N or L9110 modules.

Can I power a DC motor from the Arduino's 5V pin?

A small 130 motor at about 0.5 A works from USB in short tests, as in our project. For bigger motors or several motors, use a separate battery and join its minus to the Arduino's GND.

Why does my motor need a diode?

When the transistor switches off, the motor's coil makes a voltage spike that can kill the transistor. A diode across the motor gives that spike a safe loop.

Where it is used

The motor turns the fan in the motor project and cools things down in the thermostat. For moving to an exact angle instead of spinning, meet the servo.

Build it yourself in 3DFree, in your browser — no board, no wires, nothing to buy.Open the 3D lab →
Next: How a servo works: SG90 pulses, angles and Arduino code explained →

Your progress stays on this device — no account, nothing sent anywhere.

Last updated 2026-10-29

Read next