HOME / COMPONENTS / L298N DUAL H-BRIDGE MOTOR DRIVER
L298N Dual H-Bridge Motor Driver

L298N Dual H-Bridge Motor Driver

L298N Motor Driver STMicroelectronics

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

SpecificationValue
Supply Voltage (logic)5V (from microcontroller or external 5V regulator)
Supply Voltage (motor)5V to 35V
Output Current per Channel2A max (peak)
Total Output Current4A max
Output VoltageSame as motor supply voltage (minus drop)
Logic Input Voltage Level5V TTL compatible
Operating Temperature-25°C to +130°C
Package TypeMultiwatt-15 (15-pin through-hole)
Interface/ProtocolDirect logic input (IN1, IN2, IN3, IN4, ENA, ENB)

Pinout

PinNameTypeDescription
1CS (Current Sensing A)NCCurrent sense pin for channel A; usually left unconnected or connected to ground via a sense resistor.
2OUT1OUTMotor A output terminal 1; connects to one lead of DC motor A.
3OUT2OUTMotor A output terminal 2; connects to the other lead of DC motor A.
4VS (Motor Supply)PWRMotor power supply input (5V to 35V); powers the motors.
5IN1INLogic input for motor A; used with IN2 to set direction and braking.
6ENABLE A (ENA)INEnables motor A; PWM input for speed control. Connect to 5V to always enable.
7IN2INLogic input for motor A; used with IN1 to set direction and braking.
8GNDGNDCommon ground for logic and motor supply; must be connected to your power supply and microcontroller ground.
9VSS (Logic Supply)PWRLogic power supply input (5V); powers the internal logic circuitry.
10IN3INLogic input for motor B; used with IN4 to set direction and braking.
11ENABLE B (ENB)INEnables motor B; PWM input for speed control. Connect to 5V to always enable.
12IN4INLogic input for motor B; used with IN3 to set direction and braking.
13OUT3OUTMotor B output terminal 1; connects to one lead of DC motor B.
14OUT4OUTMotor B output terminal 2; connects to the other lead of DC motor B.
15CS (Current Sensing B)NCCurrent 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

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

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 PinBoard PinNotes
VCC5VSupply for logic (5V)
GNDGNDCommon ground
ENAD9PWM speed control, Motor A
IN1D2Direction control Motor A
IN2D3Direction control Motor A
IN3D4Direction control Motor B
IN4D5Direction control Motor B
ENBD10PWM speed control, Motor B
12V(external)Motor supply (up to 12V)

Steps

  1. 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.
  2. Connect the two motors to OUT1/OUT2 (Motor A) and OUT3/OUT4 (Motor B).
  3. Upload the sketch below. The motors will run forward, reverse, and stop in sequence.
  4. Remove the jumper caps from ENA and ENB to enable PWM speed control; otherwise motors run at full speed.
  5. 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 = arduino

The 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 PinBoard PinNotes
VCC3.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
GNDGNDCommon ground
ENAGPIO13PWM speed control, Motor A
IN1GPIO12Direction control Motor A
IN2GPIO14Direction control Motor A
IN3GPIO27Direction control Motor B
IN4GPIO26Direction control Motor B
ENBGPIO25PWM speed control, Motor B
12V(external)Motor supply

Steps

  1. 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.
  2. Provide an external 5V supply for the L298N VCC pin (not from the ESP32 3.3V pin).
  3. Provide an external motor supply (7‑12V) to the L298N 12V terminal.
  4. Connect ESP32 GND to L298N GND.
  5. 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 = arduino

ESP32 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

ComponentMouser
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.

discord.banner_cta