L298N Dual H-Bridge Motor Driver Board – DC Motor & Stepper Controller for Arduino ESP32

L298N Dual H-Bridge Motor Driver Board — DC Motors & Bipolar Stepper Controller (Arduino / ESP32)

L298N dual H-bridge driver board for controlling two DC motors or one bipolar stepper. Breadboard-friendly mounting, onboard heat-sink and 5V regulator (on many modules). Works with Arduino, ESP32, ESP8266, Raspberry Pi and other microcontrollers.

Condition: New Type: L298N Dual H-Bridge Drive: 2 × DC motors or 1 × bipolar stepper Compatible: Arduino / ESP32 / Raspberry Pi

What's Included

Key Features

Specifications (typical)

DriverL298N dual H-bridge
Supply Voltage (Motor)Typically 5V – 35V (check your module / motors)
Logic Voltage5V logic (some modules accept 3.3V logic levels when powered appropriately)
Output CurrentUp to ~2A per channel (peaks higher; check datasheet & heat dissipation)
ControlIN1/IN2/ENA (Motor A), IN3/IN4/ENB (Motor B)
MountingScrew terminals + header pins

Why choose L298N?

Wiring Quick Reference (ESP32 / Arduino)

Important safety: Motor supply (VM) and logic supply must share a common ground. Use proper power rating for motors and fuses where applicable. Ensure motor voltage within module rating.

Typical connections (two DC motors)

Wiring: L298N to ESP32 / Arduino (example)

Possible Uses

Item Specifics 

BrandUnbranded / Generic
ModelL298N Dual H-Bridge Motor Driver Module
TypeMotor Driver / Controller
Compatible WithArduino, ESP32, ESP8266, Raspberry Pi
Operating Voltage5V (logic) / 5V–35V (motor supply) — check module
Channels2 (dual H-bridge)
ConditionNew
Country/Region of ManufactureChina

ESPHome Example — DC Motor Control (ESP32)

Click to expand — ESPHome YAML (two DC motors: speed + direction)
# ESPHome example (ESP32) — L298N DC motor control (basic)
esphome:
  name: l298n_node
  platform: ESP32
  board: esp32dev

wifi:
  ssid: "YOUR_SSID"
  password: "YOUR_PASS"

logger:
api:
ota:

# PWM outputs for ENA / ENB (ESP32 uses ledc)
output:
  - platform: ledc
    id: motor_a_pwm
    pin: 17
    frequency: 2000 Hz
  - platform: ledc
    id: motor_b_pwm
    pin: 18
    frequency: 2000 Hz

# Direction pins as switches
switch:
  - platform: gpio
    id: motor_a_dir1
    pin: 16
  - platform: gpio
    id: motor_a_dir2
    pin: 4
  - platform: gpio
    id: motor_b_dir1
    pin: 19
  - platform: gpio
    id: motor_b_dir2
    pin: 21

# Expose simple motor controls to Home Assistant
number:
  - platform: template
    name: "Motor A Speed"
    id: motor_a_speed
    min_value: 0
    max_value: 100
    step: 1
    optimistic: true
    update_interval: never
    on_value:
      then:
        - lambda: |-
            float duty = x / 100.0;
            id(motor_a_pwm).set_level(duty);
  - platform: template
    name: "Motor B Speed"
    id: motor_b_speed
    min_value: 0
    max_value: 100
    step: 1
    optimistic: true
    update_interval: never
    on_value:
      then:
        - lambda: |-
            float duty = x / 100.0;
            id(motor_b_pwm).set_level(duty);

# Example scripts to run a motor forward/backwards
script:
  - id: motor_a_forward
    then:
      - switch.turn_on: motor_a_dir1
      - switch.turn_off: motor_a_dir2
      - component.update: motor_a_speed
  - id: motor_a_backward
    then:
      - switch.turn_off: motor_a_dir1
      - switch.turn_on: motor_a_dir2
      - component.update: motor_a_speed

# Note: This is a basic control layout. Add safety limits, current sensing and
# ensure motor supply and logic voltages are correct for your setup.

Notes: adjust pins to match wiring. Use the ENA/ENB PWM outputs to control motor speed (0–100%). For heavy motors use separate motor supply and add flyback protection and adequate cooling.

Arduino Example — DC motors + Bipolar Stepper (ESP32 & Arduino)

Click to expand — Arduino sketch (supports Uno/ESP32)
// Arduino/ESP32 example for L298N
// Controls two DC motors (speed + direction) and a bipolar stepper (4-wire)
// For ESP32 PWM use ledc; for Arduino Uno use analogWrite on PWM pins.
// Adjust pins and motor supply accordingly.

#if defined(ESP32)
  // ESP32 PWM setup helpers
  const int PWMA_PIN = 17; // ENA
  const int PWMB_PIN = 18; // ENB
  const int PWMA_CH = 0;
  const int PWMB_CH = 1;
  const int PWM_FREQ = 2000;
  const int PWM_RES = 8; // 8-bit resolution -> 0..255
#else
  // Arduino Uno PWM pins (example)
  const int PWMA_PIN = 5; // ENA (D5)
  const int PWMB_PIN = 6; // ENB (D6)
#endif

// Motor A direction pins (IN1, IN2)
const int A_IN1 = 16;
const int A_IN2 = 4;

// Motor B direction pins (IN3, IN4)
const int B_IN1 = 19;
const int B_IN2 = 21;

// Bipolar stepper wiring (connect coils to OUT1/OUT2 and OUT3/OUT4)
const int S1 = 16; // coil A+
const int S2 = 4;  // coil A-
const int S3 = 19; // coil B+
const int S4 = 21; // coil B-

void setup() {
  Serial.begin(115200);

  pinMode(A_IN1, OUTPUT);
  pinMode(A_IN2, OUTPUT);
  pinMode(B_IN1, OUTPUT);
  pinMode(B_IN2, OUTPUT);

#if defined(ESP32)
  ledcSetup(PWMA_CH, PWM_FREQ, PWM_RES);
  ledcAttachPin(PWMA_PIN, PWMA_CH);
  ledcSetup(PWMB_CH, PWM_FREQ, PWM_RES);
  ledcAttachPin(PWMB_PIN, PWMB_CH);
#else
  pinMode(PWMA_PIN, OUTPUT);
  pinMode(PWMB_PIN, OUTPUT);
#endif

  // Ensure motors off
  stopMotors();
}

void loop() {
  // Example: run Motor A forward at 60% for 3s
  motorA_forward(0.6);
  delay(3000);
  stopMotors();
  delay(1000);

  // Example: run Motor B backward at 40% for 2s
  motorB_backward(0.4);
  delay(2000);
  stopMotors();
  delay(1000);

  // Example: rotate a small bipolar stepper one full revolution (assumes 200 steps/rev)
  stepper_rotate(200, 5); // 200 steps, 5 ms step delay
  delay(2000);
}

void motorA_forward(float duty) {
  digitalWrite(A_IN1, HIGH);
  digitalWrite(A_IN2, LOW);
  setPWMA(duty);
}
void motorA_backward(float duty) {
  digitalWrite(A_IN1, LOW);
  digitalWrite(A_IN2, HIGH);
  setPWMA(duty);
}
void motorB_forward(float duty) {
  digitalWrite(B_IN1, HIGH);
  digitalWrite(B_IN2, LOW);
  setPWMB(duty);
}
void motorB_backward(float duty) {
  digitalWrite(B_IN1, LOW);
  digitalWrite(B_IN2, HIGH);
  setPWMB(duty);
}

void stopMotors() {
  digitalWrite(A_IN1, LOW);
  digitalWrite(A_IN2, LOW);
  digitalWrite(B_IN1, LOW);
  digitalWrite(B_IN2, LOW);
  setPWMA(0);
  setPWMB(0);
}

void setPWMA(float duty) {
#if defined(ESP32)
  int value = (int)(duty * 255.0);
  ledcWrite(PWMA_CH, value);
#else
  int value = (int)(duty * 255.0);
  analogWrite(PWMA_PIN, value);
#endif
}

void setPWMB(float duty) {
#if defined(ESP32)
  int value = (int)(duty * 255.0);
  ledcWrite(PWMB_CH, value);
#else
  int value = (int)(duty * 255.0);
  analogWrite(PWMB_PIN, value);
#endif
}

// Simple full-step sequence for bipolar stepper (4-step)
void stepper_step(int step) {
  // step: 0..3
  switch (step & 3) {
    case 0: digitalWrite(S1, HIGH); digitalWrite(S2, LOW);  digitalWrite(S3, HIGH); digitalWrite(S4, LOW);  break;
    case 1: digitalWrite(S1, LOW);  digitalWrite(S2, HIGH); digitalWrite(S3, HIGH); digitalWrite(S4, LOW);  break;
    case 2: digitalWrite(S1, LOW);  digitalWrite(S2, HIGH); digitalWrite(S3, LOW);  digitalWrite(S4, HIGH); break;
    case 3: digitalWrite(S1, HIGH); digitalWrite(S2, LOW);  digitalWrite(S3, LOW);  digitalWrite(S4, HIGH); break;
  }
}

void stepper_rotate(int steps, int delayMs) {
  for (int i = 0; i < steps; i++) {
    stepper_step(i % 4);
    delay(delayMs);
  }
  // turn coils off
  digitalWrite(S1, LOW); digitalWrite(S2, LOW); digitalWrite(S3, LOW); digitalWrite(S4, LOW);
}

Notes: set pins to match your wiring. For bipolar steppers confirm coil pairs and current rating — L298N is suitable for small steppers; for higher-current steppers use a dedicated driver (e.g., TB6600, DRV8825).

Practical Tips & Safety