L298N dual H-bridge
DC motor driver
Lets the ESP32 control two DC motors (direction and speed) that need far more current than one pin can give.
Open the course →How it works
An H-bridge is 4 transistors around the motor. With IN1/IN2 you choose which two are on → current flows left-right or right-left → the motor turns forward or backward. PWM on ENA → speed. The module is powered with 7–12 V for the motors, and an internal regulator gives 5 V (it can also power the ESP32 via VIN if you leave the jumper on).
Pins and wiring
| Pin | What it is | Where it connects / why |
|---|---|---|
| 12V (VCC) | Motor power | 6 – 12 V from a battery/adapter. |
| GND | Ground | Must be common with the ESP32 GND. |
| 5V | 5 V output (with jumper) / input | Can → VIN on the ESP32 if the input is 7–12 V. |
| ENA / ENB | Enable (speed) for motor A / B | → PWM GPIO. With the jumper = always full speed. |
| IN1, IN2 | Direction motor A | → 2 GPIO. 10 = forward, 01 = backward, 00/11 = stop. |
| IN3, IN4 | Direction motor B | → 2 GPIO. |
| OUT1, OUT2 | Motor A | The two motor terminals. |
| OUT3, OUT4 | Motor B | The two motor terminals. |
Specifications
Motor voltage5 – 35 V
Current2 A per channel (continuous)
Voltage drop~2 V (the motor gets less)
Logic input3.3 V OK
Tips and typical mistakes
- The L298N is old and "wastes" 2 V. Modern alternative: TB6612FNG or DRV8833 — more efficient and smaller.
- Motors make noise on the supply — add a 100 µF capacitor and never power them from the ESP32's USB.