Brushed DC Motor Tutorial

Motor Control

If the driver board looks familiar - it should. It is the one from the stepper motor tutorial. It can drive two brushed DC motors at the same time. Each brushed motor requires two PWM outputs, so the Uno can drive a maximum of two brushed motors at once, if speed control is required.

Brushed Motor

A brushed motor, or mechanically commutated motor, is one with electrical windings on the rotating shaft. Because the windings are rotating, the motor must have a commutator and brushes to deliver current to the windings.

Contrast this with a "brushless" motor, which has permanent magnets on the rotor and windings in the stator, or stationary part of the motor. This type of motor needs no brushes, but must be "electronically commutated", by providing the windings with alternating currrent.

The schematic with two brushed motors. We only used one in the tutorial. If you should decide to use both, make sure the power supply can provide the required current.


#define MTR_POS 10
#define MTR_NEG 11

void setup() {

  // Motor stopped.
  analogWrite(MTR_POS, 0);
  analogWrite(MTR_NEG, 0);
}

void loop() {
  int x;
  // Ramp the motor to full speed CW.
  for (x = 0; x < 255; ++x)
  {
    analogWrite(MTR_POS, x);
    delay(10);
  }
  // Ramp the motor to stop.
  for (x = 255; x > 0; --x)
  {
    analogWrite(MTR_POS, x);
    delay(10);
  }
  delay(500);
  // Ramp the motor to full speed CCW.
  for (x = 0; x < 255; ++x)
  {
    analogWrite(MTR_NEG, x);
    delay(10);
  }
  // Ramp the motor to stop.
  for (x = 255; x > 0; --x)
  {
    analogWrite(MTR_NEG, x);
    delay(10);
  }
  delay(500);
}
    

What it Does

The motor starts out with 0, corresponding to 0 Volts, on both terminals. Every 10mS the program increases the voltage by increasing the pulse width on the positive terminal. When the positive terminal has 255, or 12V on it, the program then starts slowly decreasing the voltage back to zero. The effect of this is the motor speed, which starts at zero, is ramped up to full speed in 2.55 seconds, then back to stopped in another 2.55 seconds.

Then, after a half-second delay, the negative terminal is driven from zero up to 12V in 2.55 seconds. This ramps the motor speed up to full again, but this time in the opposite direction (counterclockwise). The program then ramps the speed down to a full stop, waits half of a second and repeats the whole process.

Motor Speed

The motor in this tutorial operates "open-loop", meaning there is no feedback telling the program how fast the motor is actually turning. We assume that since we have applied 1/2 the supply voltage that the motor is turning at 1/2 its maximum speed. This is certainly not true. For some applications it doesn't matter that much, and for others it is a critical shortfall. The solution is an optical encoder.

Arduino Board Logo

 

Arduino-Board is the go-to source for information on many available Arduino and Arduino-like boards, tutorials and projects.

Help and Support

Arduino-Board

Stay updated

Sign up if you would like to receive our once monthly newsletter.