Unit C - Actuators & Displays

14. DC Motors & H-Bridges

Control motor direction, speed and stopping safely.

Estimated time 4 hours

Learning outcomes

  • Explain back EMF and motor starting current
  • Use an H-bridge truth table
  • Control direction and PWM speed
  • Sequence direction changes safely

Parts and preparation

Uno, L298N/TB6612-style module, low-voltage DC motor and suitable motor supply.

Before power: inspect wiring, confirm supply voltage and ensure all connected circuits share GND.

DC Motors & H-Bridges instructional connection diagram
Open the diagram for a larger view. Trace every connection before building.

DC motor

Applied voltage produces torque and rotation. Starting/stall current can be several times running current. The motor is inductive and generates electrical noise.

H-bridge

Four switches reverse current through the motor. Driver inputs select forward, reverse, coast or brake; consult the exact module truth table.

Speed

PWM on an enable/PWM input controls average motor voltage. Direction should not reverse instantly at high speedstop briefly first.

Wiring and safe build sequence

Breadboard wiring for lesson 14: DC Motors & H-Bridges
Breadboard layout for this lesson. Match colours and pins before powering the circuit. Click the image for a larger view.
  1. D7 -> IN1
  2. D8 -> IN2
  3. D9/PWM -> ENA/PWMA
  4. Motor -> driver outputs
  5. Motor supply -> driver VM/GND
  6. Driver GND -> Uno GND
Power rule: switch off before moving wires. Arduino I/O pins are control signals; high-current loads require a driver and suitable external supply.
const byte in1 = 7;
const byte in2 = 8;
const byte pwmPin = 9;

void driveMotor(int speedValue) {
  speedValue = constrain(speedValue, -255, 255);
  digitalWrite(in1, speedValue > 0);
  digitalWrite(in2, speedValue < 0);
  analogWrite(pwmPin, abs(speedValue));
}

void setup() {
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(pwmPin, OUTPUT);
}

void loop() {
  driveMotor(180);
  delay(1500);
  driveMotor(0);
  delay(500);
  driveMotor(-180);
  delay(1500);
  driveMotor(0);
  delay(1000);
}

How the code works

  1. Positive/negative signed speed combines direction and magnitude.
  2. A stop interval reduces mechanical and electrical stress.

Test and record evidence

Expected result: The motor runs forward, stops, reverses, then stops.

Practical evidence checklist

Common faults and checks
  • Use a motor supply able to provide stall current.
  • Never power the motor from an Arduino I/O or 5 V pin.
  • If only one direction works, inspect both logic inputs.
Extension challenge: Use a potentiometer for signed speed: centre stop, left reverse, right forward.

Check your understanding

Q1. What does an H-bridge change?

Show answer

The direction of current through the motor.

Q2. Why stop before reversing?

Show answer

To reduce current, mechanical shock and driver stress.