Skip to content
E

Motor

Controlling DC Motor L298N with ESP32

What is the DC Motor L298N?

DC Motor L298N practical reference

A geared DC motor paired with the ubiquitous L298N dual H-bridge driver — the standard starting point for wheeled robots.

Key specifications

  • Motor: Brushed DC gear motor — the common yellow "TT motor" spec is ~200 RPM at 6V, ~1:48 gear ratio
  • Driver: L298N dual H-bridge, 2A per channel
  • Control: One direction pair (IN1/IN2) plus one PWM speed pin (ENA) per motor
  • Supply: Motor voltage 5V-35V DC on the driver's VMS terminal, separate from the MCU's own power

Pinout and connection notes

This entry covers the motor + L298N pairing as a unit — see the L298N Driver page for the full breakdown of every driver pin if you're wiring more than one motor.

  • OUT1 / OUT2: Motor leads — connect directly to the L298N's motor A output terminal, polarity sets default spin direction
  • ENA: PWM input on the driver — controls motor speed
  • IN1 / IN2: Direction inputs on the driver — set which way current flows through the motor
  • 12V / GND: Motor supply voltage and ground, into the driver's VMS/GND terminal

Integration checklist

  1. Confirm the exact part number and breakout-board revision.
  2. Verify supply voltage, current demand, logic levels, and signal direction against the datasheet.
  3. Check controller pin assignments and bus address or interface mode against the example code.
  4. Power up with external loads disconnected, then test signals before full integration.
  5. If readings or communication fail, check power and ground first, then pin mapping, interface settings, and library initialization.

Troubleshooting and reproducibility

Record the board used, wiring, library/version, supply arrangement, and measured behavior. Use the selected board-specific wiring example as the source of truth. Never assume visually similar modules share identical voltage tolerance or pin order.

Setting Up DC Motor L298N with ESP32

Wiring

Component pinESP32 pinNote
ENAGPIO25 (PWM via ledc)ESP32 has no analogWrite by default in older cores — use the ledc PWM API (or analogWrite if your core version supports the compatibility wrapper)
IN1GPIO26
IN2GPIO27
12V / GNDSeparate motor power supply — GND shared with the ESP32Never power the motor rail from the ESP32's 3.3V/5V pins

Swipe sideways to see every column →

C++

ESP32's ledc PWM API needs a channel set up once in setup() (ledcSetup/ledcAttachPin) rather than a plain analogWrite call — the logic is otherwise identical to the Uno version.

Related Components

Related Guides & Projects