All tutorials

3 · Outputs & actuators

DC motor: speed and direction

Advanced22 min

Goal

Control a DC motor in speed (PWM) and direction (H-bridge).

Why it matters

A motor is never wired straight to a pin: it needs a power stage.

Steps

  1. 01Add the DC motor and its driver.
  2. 02Two direction pins (IN1/IN2) + one PWM pin (ENA).
  3. 03Write a motor(speed) function that accepts negative values.
  4. 04Test forward, stop, reverse.

This tutorial runs inside the Circuitly simulator: your wiring and your code are checked automatically at every step.

Next tutorials