DC Motor Speed

W. Durfee, Last update:

For an overview on controlling the speed of a small DC motor, see the Controlling Motors lecture notes (PDF file).

ITP Physical Computing has a good tutorial on using an Arduino to control motor speed.

There are three ways to slow down a motor: (1) reduce the drive voltage, (2) insert a series power resistor that has about the same resistance as the motor, and (3) pulse the motor with PWM control.

For PWM control, use the Arduino analogWrite() command (see the Arduino Language Reference page) to drive the pin that controls the on-off of the motor. Only use for a transistor or h-bridge switch, not for a relay switch.

PWM using analogWrite() will only work on pins 3, 5, 6, 9, 10 and 11.

Here is a program that runs the motor at three different speeds, each for two seconds. The argument in analogWrite() ranges from 0 to 255 with 255 representing full on.

#define MOTOR 9

void setup()
  pinMode(MOTOR, OUTPUT);
  analogWrite(MOTOR,64);  //slow
  analogWrite(MOTOR,128);  //medium
  analogWrite(MOTOR,255);  //fast
void loop()