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
- 01Add the DC motor and its driver.
- 02Two direction pins (IN1/IN2) + one PWM pin (ENA).
- 03Write a motor(speed) function that accepts negative values.
- 04Test forward, stop, reverse.
This tutorial runs inside the Circuitly simulator: your wiring and your code are checked automatically at every step.