To use PWM to control DC motor speed and direction, you must route a microcontroller's 3.3V or 5V PWM signal (typically 1kHz to 20kHz) into a dedicated H-bridge motor driver, which then switches the high-current motor supply. Never wire a motor directly to an Arduino or ESP32 GPIO pin; the inrush current will instantly fry the microcontroller's logic traces. The direct answer for 90% of 12V hobbyist and light-industrial projects is to pair a 12V brushed planetary gear motor with a logic-level MOSFET H-bridge driver like the Cytron MD10C or Texas Instruments DRV8873, driven by a 5kHz PWM signal.
Motor Type Comparison: Which DC Motor Fits Your Load Profile?
Before writing a single line of PWM code, you must match the motor topology to your mechanical load. Treating a stepper, servo, and brushed DC motor as interchangeable is a fast track to burned-out drivers and stalled mechanisms. Here is how the primary DC motor types compare when driven via PWM.
| Motor Type | Torque Curve | PWM Control Needs | Cost (Approx.) | Best Use Case |
|---|---|---|---|---|
| Brushed DC (BDC) | Max torque at 0 RPM (stall), drops linearly as speed increases. | Simple. 1 PWM pin for speed, 1 GPIO for direction (via H-bridge). | $5 - $25 | Wheels, conveyors, linear actuators, winches. |
| Brushless DC (BLDC) | High torque across a wide RPM band; requires active commutation. | Complex. Requires 3-phase ESC (Electronic Speed Controller) accepting PWM or telemetry. | $30 - $100+ | Drones, high-speed RC vehicles, CNC spindles. |
| Coreless DC | Extremely low rotor inertia; rapid acceleration and deceleration. | Simple PWM, but requires high-frequency switching (20kHz+) to avoid cogging. | $15 - $40 | Robotics joints, precision gimbals, medical devices. |
If your application requires holding a heavy static load at a precise angle without continuous power, you actually need a stepper motor or a servo, not a standard DC motor. For continuous rotation under varying loads—like driving a chassis or winding a cable—a Brushed DC motor is your target.
Wiring, Terminals, and Driver Topologies
An H-bridge driver acts as the muscle between your microcontroller's brain and the motor's high-current demands. When selecting a driver module, you will encounter specific terminal identifications. Miswiring these is the most common cause of dead drivers.
- VM / VCC / B+: The main motor power supply (e.g., 12V or 24V). This must be capable of delivering the motor's peak stall current.
- GND: The ground for the motor supply. Critical: This must be tied to the microcontroller's GND to establish a common logic reference.
- VDD / VLOGIC: The logic power supply (usually 3.3V or 5V). On many modern drivers, this is internally regulated from VM, but on modules like the TB6612FNG, you must supply it externally from your ESP32's 3V3 pin.
- PWM / IN1: The speed control input. Receives the PWM signal from the microcontroller.
- DIR / IN2: The direction control input. A standard HIGH/LOW GPIO signal.
- OUT1 / OUT2 / A / B: The high-current outputs that connect directly to the motor terminals.
DC motors are massive inductors. When the H-bridge switches off, the collapsing magnetic field generates a high-voltage reverse spike. Modern integrated drivers (like the TI DRV8873 or Cytron MD10C) include internal Schottky flyback diodes to clamp this spike. If you are building a bare-MOSFET H-bridge on a breadboard, you must add external flyback diodes across the motor terminals, or the voltage spike will punch through your MOSFETs and destroy your ESP32.
Sizing Rule of Thumb: A Worked 12V Load Example
The most frequent mistake in motor drive selection is sizing the driver for the motor's continuous current rating. When a DC motor starts from a dead stop, or when it hits a mechanical bind, it draws stall current—which is typically 3x to 5x higher than the continuous running current. If your driver cannot handle this inrush, it will trigger thermal shutdown or melt.
The Sizing Rule of Thumb: Select a motor driver with a peak current rating of at least 1.5x to 2x the motor's published stall current, or 3x the continuous current, whichever is higher.
Worked Load Example
Let's say you are building an automated heavy-duty curtain track using a 12V brushed planetary gear motor. You check the manufacturer's datasheet and find the following specs:
- Nominal Voltage: 12V DC
- Continuous Running Current: 4A
- Stall Current: 14A
The Calculation:
Stall Current (14A) × 1.5 Safety Margin = 21A Minimum Peak Driver Rating.
Continuous Current (4A) × 3 = 12A Minimum Continuous Driver Rating.
If you chose a popular L298N driver (which maxes out at 2A continuous and 3A peak), the motor would barely move, and the L298N would overheat in seconds due to its massive 2V internal voltage drop. If you chose a TB6612FNG (1.2A continuous, 3.2A peak), it would instantly trip its overcurrent protection.
The Correct Pick: You need a driver like the Cytron MD10C, which handles 10A continuous and up to 30A peak for 10 seconds, or a high-power BTS7960 module (43A peak). The MD10C uses MOSFETs instead of BJTs, meaning it has a near-zero voltage drop and runs cool even at 10A continuous.
Failure Signatures: Diagnosing Hum, Overheat, and Stall
When your PWM-controlled motor misbehaves, the physical symptoms tell you exactly what is failing in the circuit. Here is how to diagnose the three most common failure modes on the bench.
| Symptom | Root Cause | The Fix |
|---|---|---|
| Audible Hum / Whine | PWM frequency is too low (typically under 1kHz), causing the motor coils to physically vibrate at the switching frequency. Alternatively, the motor is stalled under a heavy load. | Increase your microcontroller's PWM frequency to 5kHz - 15kHz. If the hum persists and the shaft isn't turning, your load is mechanically jammed or your gear ratio is too high. |
| Driver Overheat | Continuous current exceeds the driver's thermal limits, or switching losses are too high due to poor logic-level MOSFET gate drive. | Verify your actual current draw with a multimeter. Add a heatsink, increase airflow, or upgrade to a driver with a lower Rds(on) MOSFET specification. |
| Microcontroller Brownout / Reset | Motor startup inrush causes a massive voltage sag on the shared power rail, dropping the ESP32's 3.3V regulator below its threshold. | Separate the motor power supply from the logic power supply (tie grounds only). Add a large bulk electrolytic capacitor (1000µF to 4700µF) directly across the driver's VM and GND terminals. |
For a deeper understanding of how PWM duty cycles interact with inductive loads and switching losses, refer to the All About Circuits guide on DC motor PWM drive. Understanding the electrical physics prevents you from chasing software bugs when the issue is actually hardware.
The Decision Path: Picking Your Exact Motor and Driver
Stop guessing and use this decision tree to select your hardware. Follow the logic down to your specific load requirement.
| If Your Load Profile Is... | And You Need... | Then Choose This Driver | Estimated Cost |
|---|---|---|---|
| Under 1A continuous (small wheels, light sensors) | Bidirectional control | Toshiba TB6612FNG (Dual H-Bridge) | $4 - $8 |
| 1A to 3.5A continuous (medium actuators, winches) | Unidirectional control | Texas Instruments DRV8871 | $5 - $10 |
| 1A to 10A continuous (chassis drive, heavy curtains) | Bidirectional control | Cytron MD10C (or TI DRV8873) | $12 - $20 |
| 10A to 30A continuous (e-bikes, large robotics) | Bidirectional control | BTS7960 (IBT-2 Module) or Cytron MD30C | $15 - $35 |
The Default Recommendation
If you are building a standard 12V embedded project—such as a motorized camera slider, an automated pet feeder, or a small rover—and you want a setup that will not require endless troubleshooting, here is your concrete pick:
Motor: Buy a 12V Brushed Planetary Gear Motor rated for 60 to 100 RPM with a continuous draw under 5A (e.g., a generic 775 motor with a 100:1 planetary gearbox, approx. $18).
Driver: Pair it with the Cytron MD10C ($15). It accepts 3.3V logic directly from an ESP32, handles 30A peaks without flinching, requires no external flyback diodes, and features screw terminals that accept up to 12 AWG wire.
PWM Setup: Configure your ESP32's LEDC (LED Control) peripheral to output a 5kHz PWM signal. This frequency sits perfectly above the audible range (eliminating motor whine) while keeping MOSFET switching losses low enough that the MD10C won't need a heatsink for loads under 8A.
By sizing for the stall current rather than the continuous current, and keeping your logic and motor grounds properly bonded, your PWM motor control will be silent, reliable, and ready for deployment.






