L298N Dual H-Bridge Motor Driver
What is the L298N Dual H-Bridge Motor Driver?
The L298N is a classic dual H-bridge motor driver IC that lets you control the speed and direction of two DC motors (or one stepper motor) using a microcontroller like an Arduino. Think of it as a smart switch that can handle much higher currents than your microcontroller's pins can provide — up to 2 amps per channel. It takes low-voltage logic signals from your board and translates them into the higher voltage and current needed to spin motors in either direction, or even stop them.
Inside the L298N are two independent H-bridge circuits. Each bridge can drive a DC motor forward or backward, or you can combine both to drive a single bipolar stepper motor. You control everything through simple logic inputs: set a logic HIGH on one input and LOW on the other to spin a motor one way, then reverse the pins to go the other way. A separate enable pin lets you turn each motor on or off, and you can feed a PWM signal to that enable pin to adjust motor speed.
Key Specifications
| Specification | Value |
|---|---|
| Supply Voltage (logic) | 5V (from microcontroller or external 5V regulator) |
| Supply Voltage (motor) | 5V to 35V |
| Output Current per Channel | 2A max (peak) |
| Total Output Current | 4A max |
| Output Voltage | Same as motor supply voltage (minus drop) |
| Logic Input Voltage Level | 5V TTL compatible |
| Operating Temperature | -25°C to +130°C |
| Package Type | Multiwatt-15 (15-pin through-hole) |
| Interface/Protocol | Direct logic input (IN1, IN2, IN3, IN4, ENA, ENB) |
Pinout
| Pin | Name | Type | Description |
|---|---|---|---|
| 1 | CS (Current Sensing A) | NC | Current sense pin for channel A; usually left unconnected or connected to ground via a sense resistor. |
| 2 | OUT1 | OUT | Motor A output terminal 1; connects to one lead of DC motor A. |
| 3 | OUT2 | OUT | Motor A output terminal 2; connects to the other lead of DC motor A. |
| 4 | VS (Motor Supply) | PWR | Motor power supply input (5V to 35V); powers the motors. |
| 5 | IN1 | IN | Logic input for motor A; used with IN2 to set direction and braking. |
| 6 | ENABLE A (ENA) | IN | Enables motor A; PWM input for speed control. Connect to 5V to always enable. |
| 7 | IN2 | IN | Logic input for motor A; used with IN1 to set direction and braking. |
| 8 | GND | GND | Common ground for logic and motor supply; must be connected to your power supply and microcontroller ground. |
| 9 | VSS (Logic Supply) | PWR | Logic power supply input (5V); powers the internal logic circuitry. |
| 10 | IN3 | IN | Logic input for motor B; used with IN4 to set direction and braking. |
| 11 | ENABLE B (ENB) | IN | Enables motor B; PWM input for speed control. Connect to 5V to always enable. |
| 12 | IN4 | IN | Logic input for motor B; used with IN3 to set direction and braking. |
| 13 | OUT3 | OUT | Motor B output terminal 1; connects to one lead of DC motor B. |
| 14 | OUT4 | OUT | Motor B output terminal 2; connects to the other lead of DC motor B. |
| 15 | CS (Current Sensing B) | NC | Current sense pin for channel B; usually left unconnected or connected to ground via a sense resistor. |
Always double-check pin assignments against the manufacturer datasheet for your specific revision, as some third-party breakout boards may reorder pins slightly.
Common Use Cases
- Controlling two independent DC motors in a robot chassis (differential drive)
- Driving a single bipolar stepper motor (e.g., NEMA 17) for precise positioning
- Controlling a conveyor belt motor or small linear actuator
- Building a homemade RC car or tank with tank-style steering
- Controlling high-power solenoids or relays (using one H-bridge channel)
Wiring Example
For the most common use case — controlling two DC motors with an Arduino — connect the motor power supply (7-12V) to the VS pin (pin 4) and GND of the L298N. Connect the Arduino's 5V output to VSS (pin 9) and common GND. For motor A, connect one motor lead to OUT1 (pin 2) and the other to OUT2 (pin 3). For motor B, connect its leads to OUT3 (pin 13) and OUT4 (pin 14). Connect ENA (pin 6) to Arduino pin 9 for PWM speed control, IN1 (pin 5) to Arduino pin 8, and IN2 (pin 7) to Arduino pin 7. For motor B, connect ENB (pin 11) to Arduino pin 10, IN3 (pin 10) to Arduino pin 11, and IN4 (pin 12) to Arduino pin 12. Finally, connect a large electrolytic capacitor (100µF to 1000µF) across VS and GND near the IC to smooth out power spikes from the motors.
Tips and Gotchas
- Never forget the common ground! The L298N's GND (pin 8) must be connected to your microcontroller's GND and your motor power supply's GND — otherwise the logic signals won't work and the chip may behave erratically.
- The L298N can get hot under load. If you're running motors near 1A or more, add a heatsink to the Multiwatt-15 package. The thermal pad on the back is the heat path — don't block it.
- If your motors don't spin, check the enable pins (ENA and ENB). They must be pulled HIGH (5V) or receive a PWM signal. Leaving them floating usually keeps the motors disabled.
- The L298N has a voltage drop of about 1.5-2V per channel, so a 12V motor supply will only deliver about 10-10.5V to the motors. Factor this into your design if speed or torque is critical.
Happy building — you've got the power to drive some serious motors now!
Tutorial
Control two DC motors or one stepper motor with this classic dual H‑bridge driver — add direction and PWM speed control to any robot or motor project.
Wiring
| Component Pin | Board Pin | Notes |
|---|---|---|
| VCC | 5V | Supply for logic (5V) |
| GND | GND | Common ground |
| ENA | D9 | PWM speed control, Motor A |
| IN1 | D2 | Direction control Motor A |
| IN2 | D3 | Direction control Motor A |
| IN3 | D4 | Direction control Motor B |
| IN4 | D5 | Direction control Motor B |
| ENB | D10 | PWM speed control, Motor B |
| 12V | (external) | Motor supply (up to 12V) |
Steps
- Connect the L298N to the Arduino as shown in the table. Use an external power supply (e.g. 9‑12V) for the motor supply; connect its ground to Arduino GND.
- Connect the two motors to OUT1/OUT2 (Motor A) and OUT3/OUT4 (Motor B).
- Upload the sketch below. The motors will run forward, reverse, and stop in sequence.
- Remove the jumper caps from ENA and ENB to enable PWM speed control; otherwise motors run at full speed.
- For higher currents, attach a heatsink to the L298N chip.
Code
// L298N Dual Motor Control - Arduino Uno/Nano
// Motor A: ENA=9, IN1=2, IN2=3
// Motor B: ENB=10, IN3=4, IN4=5
int enA = 9;
int in1 = 2;
int in2 = 3;
int enB = 10;
int in3 = 4;
int in4 = 5;
void setup() {
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
// Set initial PWM to off
digitalWrite(enA, LOW);
digitalWrite(enB, LOW);
}
void loop() {
// Motor A forward at 75% speed
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
analogWrite(enA, 191); // ~75% of 255
// Motor B forward at 75% speed
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
analogWrite(enB, 191);
delay(2000);
// Stop motors
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
digitalWrite(enA, LOW);
digitalWrite(enB, LOW);
delay(1000);
// Motor A reverse at full speed
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
analogWrite(enA, 255);
// Motor B reverse at full speed
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
analogWrite(enB, 255);
delay(2000);
// Stop
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
digitalWrite(enA, LOW);
digitalWrite(enB, LOW);
delay(1000);
}
PlatformIO config platformio.ini
[env:uno]
platform = atmelavr
board = uno
framework = arduinoThe L298N logic supply (VCC) can be taken from the 5V pin of the Arduino, but the motor supply (12V) must be external. Remove the ENA/ENB jumpers if you want PWM speed control; with jumpers in place the motors run at full speed.
Wiring
| Component Pin | Board Pin | Notes |
|---|---|---|
| VCC | 3.3V (or 5V if board offers) | ESP32 logic is 3.3V, but L298N VCC is 5V tolerant — use 5V supply or 3.3V if motor supply is separate |
| GND | GND | Common ground |
| ENA | GPIO13 | PWM speed control, Motor A |
| IN1 | GPIO12 | Direction control Motor A |
| IN2 | GPIO14 | Direction control Motor A |
| IN3 | GPIO27 | Direction control Motor B |
| IN4 | GPIO26 | Direction control Motor B |
| ENB | GPIO25 | PWM speed control, Motor B |
| 12V | (external) | Motor supply |
Steps
- Connect the L298N to the ESP32 as shown. Note: the L298N logic inputs are 5V‑tolerant, but the ESP32 GPIOs are 3.3V. This works because the L298N interprets anything above ~2.3V as HIGH — no level shifting needed.
- Provide an external 5V supply for the L298N VCC pin (not from the ESP32 3.3V pin).
- Provide an external motor supply (7‑12V) to the L298N 12V terminal.
- Connect ESP32 GND to L298N GND.
- Upload the code. It uses the LEDC PWM peripheral for smooth motor control.
Code
// L298N Dual Motor Control - ESP32
// Uses LEDC PWM on GPIO13 (ENA) and GPIO25 (ENB)
// Motor A: ENA=GPIO13, IN1=GPIO12, IN2=GPIO14
// Motor B: ENB=GPIO25, IN3=GPIO27, IN4=GPIO26
const int enA = 13;
const int in1 = 12;
const int in2 = 14;
const int enB = 25;
const int in3 = 27;
const int in4 = 26;
const int freq = 5000;
const int pwmChannelA = 0;
const int pwmChannelB = 1;
const int resolution = 8;
void setup() {
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
ledcSetup(pwmChannelA, freq, resolution);
ledcSetup(pwmChannelB, freq, resolution);
ledcAttachPin(enA, pwmChannelA);
ledcAttachPin(enB, pwmChannelB);
// Start with motors stopped
ledcWrite(pwmChannelA, 0);
ledcWrite(pwmChannelB, 0);
}
void loop() {
// Motor A forward 75%
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
ledcWrite(pwmChannelA, 191);
// Motor B forward 75%
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
ledcWrite(pwmChannelB, 191);
delay(2000);
// Stop
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
ledcWrite(pwmChannelA, 0);
ledcWrite(pwmChannelB, 0);
delay(1000);
// Motor A reverse full speed
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
ledcWrite(pwmChannelA, 255);
// Motor B reverse full speed
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
ledcWrite(pwmChannelB, 255);
delay(2000);
// Stop
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
ledcWrite(pwmChannelA, 0);
ledcWrite(pwmChannelB, 0);
delay(1000);
}
PlatformIO config platformio.ini
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduinoESP32 is a 3.3V device; the L298N interprets 3.3V as logic HIGH, so level shifting is not required. However, do not power the L298N VCC from the ESP32's 3.3V pin — use a separate 5V supply. The LEDC library handles PWM via hardware channels.
Where to Buy
| Component | Mouser |
|---|---|
| 101277 | $6.41 |
| L298N | $9.92 |
| DRI0002 | $11.09 |
Join the Community on Discord
Ask questions, share your builds, and hang out with fellow makers.