Projects / DC motor speed and direction

DC motor speed and direction

Intermediate55 minGuided buildReviewed
Arduino UnoD5D7D8A0D2GNDSpeed knobTB6612FNG72°Motor shaftReversespeed 40%Serial
Serial at 9600 baud

Tap a part to see what it does.

Tap the parts to see what each one does. A teaching simulation, not a circuit simulator.

Build it step by step

0 of 5 done
  1. UNO

    Place the driver

    TB6612 breakout across the centre gap.

  2. UNO

    Two supplies, one ground

    Battery to VM, Uno 5V to VCC and STBY, and join every ground.

  3. UNO

    Motor and capacitor

    Motor to AO1 and AO2 with a 100 nF capacitor across its terminals.

  4. UNO

    Knob and button

    Pot wiper to A0, button from D2 to GND.

  5. UNO

    Upload and turn

    Turn the knob slowly, then press the button.

In short

How do you build a DC motor speed and direction?

A knob sets the speed of a TT gear motor through a TB6612FNG driver and a button reverses it, with a gentle stop before every change of direction. You need Arduino Uno R3, TB6612FNG Motor Driver, TT gear motor 3 to 6 V, Potentiometer 10 kΩ, Tactile push button 6 mm, Ceramic Capacitor 100 nF and Breadboard 830 Tie Points. It takes 5 steps and about 55 minutes.

Level
Intermediate
Time
About 55 min
Parts
7

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
4 × AA pack +TB6612 VMMotor supply (about 6 V)
Pack −TB6612 GND and Uno GNDShared ground
Uno 5VTB6612 VCC and STBYLogic power, driver enabled
Uno D5 / D7 / D8PWMA / AIN1 / AIN2Speed and direction
AO1 / AO2Motor terminalsMotor A
Pot wiperUno A0 (ends to 5V and GND)Speed knob
ButtonUno D2 to GNDReverse

Code

No libraries. Pin 5 gives about 980 Hz PWM on the Uno, fine for TT motors.

Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

const int PWMA = 5, AIN1 = 7, AIN2 = 8, BTN = 2;
bool forward = true, last = HIGH;

void drive(int speed) {
  digitalWrite(AIN1, forward); digitalWrite(AIN2, !forward);
  analogWrite(PWMA, speed);
}

void setup() {
  pinMode(PWMA, OUTPUT); pinMode(AIN1, OUTPUT); pinMode(AIN2, OUTPUT);
  pinMode(BTN, INPUT_PULLUP);
  Serial.begin(9600);
}

void loop() {
  int speed = map(analogRead(A0), 0, 1023, 0, 255);
  bool now = digitalRead(BTN);
  if (last == HIGH && now == LOW) {
    for (int s = speed; s >= 0; s -= 15) { drive(s); delay(20); }  // ease to a stop
    forward = !forward;
    Serial.println(forward ? "Forward" : "Reverse");
  }
  last = now;
  drive(speed);
  delay(20);
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Knob at zeroMotor stops completely
Knob at fullMotor runs at full speed, driver barely warm
Press the buttonMotor slows to a stop, then runs the other way

If it does not work

Nothing moves

STBY must be HIGH and VM must have battery voltage.

Uno resets when the motor starts

Motor powered from the Uno: use the battery pack for VM.

Motor hums at low speed

Normal below about 20 %: the motor needs a minimum push.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the DC motor speed and direction?

Arduino Uno R3, TB6612FNG Motor Driver, TT gear motor 3 to 6 V, Potentiometer 10 kΩ, Tactile push button 6 mm, Ceramic Capacitor 100 nF and Breadboard 830 Tie Points. Ceramic Capacitor 100 nF: Across the motor terminals.

How long does the DC motor speed and direction take to build?

About 55 minutes for a intermediate maker, in 5 steps.

How do I know the DC motor speed and direction works?

Knob at zero: Motor stops completely. Knob at full: Motor runs at full speed, driver barely warm. Press the button: Motor slows to a stop, then runs the other way.

Nothing moves: what should I check?

STBY must be HIGH and VM must have battery voltage.

Uno resets when the motor starts: what should I check?

Motor powered from the Uno: use the battery pack for VM.

Motor hums at low speed: what should I check?

Normal below about 20 %: the motor needs a minimum push.