

The L298N is a dual H-bridge motor driver designed to control the direction and speed of DC motors and stepper motors. It is a versatile and robust component capable of driving two motors simultaneously, with each channel supporting up to 2A of current. The L298N is widely used in robotics, automation, and other motor control applications due to its ease of use and compatibility with microcontrollers like Arduino.








The L298N module typically has the following pins:
| Pin Name | Type | Description |
|---|---|---|
IN1 |
Input | Motor A control input 1. Used to set the direction of Motor A. |
IN2 |
Input | Motor A control input 2. Used to set the direction of Motor A. |
IN3 |
Input | Motor B control input 1. Used to set the direction of Motor B. |
IN4 |
Input | Motor B control input 2. Used to set the direction of Motor B. |
ENA |
Input (PWM) | Enable pin for Motor A. Can be used for speed control via PWM signal. |
ENB |
Input (PWM) | Enable pin for Motor B. Can be used for speed control via PWM signal. |
OUT1 |
Output | Motor A output 1. Connects to one terminal of Motor A. |
OUT2 |
Output | Motor A output 2. Connects to the other terminal of Motor A. |
OUT3 |
Output | Motor B output 1. Connects to one terminal of Motor B. |
OUT4 |
Output | Motor B output 2. Connects to the other terminal of Motor B. |
12V |
Power Input | External power supply for the motors (5V to 46V). |
5V |
Power Output | Regulated 5V output (can power a microcontroller if the jumper is in place). |
GND |
Ground | Common ground for the module and external power supply. |
Note: The module often includes a jumper for the
ENAandENBpins. If the jumper is in place, the motors will run at full speed by default.
Power Connections:
12V pin to an external power source (e.g., a battery or power supply) that matches the voltage requirements of your motors.GND pin to the ground of your power source and microcontroller.5V pin on the L298N module to power it (ensure the jumper is in place).Motor Connections:
OUT1 and OUT2.OUT3 and OUT4.Control Connections:
IN1, IN2, IN3, and IN4 pins to the digital output pins of your microcontroller.ENA and ENB pins to PWM-capable pins on your microcontroller.Programming:
IN pins to control the direction of the motors.ENA and ENB pins to control the speed of the motors.The following example demonstrates how to control two DC motors using the L298N and an Arduino UNO:
// Define motor control pins
const int IN1 = 7; // Motor A direction control pin 1
const int IN2 = 6; // Motor A direction control pin 2
const int ENA = 5; // Motor A speed control (PWM)
const int IN3 = 4; // Motor B direction control pin 1
const int IN4 = 3; // Motor B direction control pin 2
const int ENB = 2; // Motor B speed control (PWM)
void setup() {
// Set motor control pins as outputs
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(ENA, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
pinMode(ENB, OUTPUT);
}
void loop() {
// Motor A: Forward at 50% speed
digitalWrite(IN1, HIGH); // Set IN1 HIGH
digitalWrite(IN2, LOW); // Set IN2 LOW
analogWrite(ENA, 128); // Set ENA to 50% duty cycle (128/255)
// Motor B: Backward at 75% speed
digitalWrite(IN3, LOW); // Set IN3 LOW
digitalWrite(IN4, HIGH); // Set IN4 HIGH
analogWrite(ENB, 192); // Set ENB to 75% duty cycle (192/255)
delay(2000); // Run motors for 2 seconds
// Stop both motors
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
analogWrite(ENA, 0);
analogWrite(ENB, 0);
delay(2000); // Wait for 2 seconds before repeating
}
ENA and ENB pins.Motors Not Running:
IN pins are receiving the correct HIGH/LOW signals.ENA and ENB pins are properly connected or the jumpers are in place.Motors Running in the Wrong Direction:
OUT1/OUT2 or OUT3/OUT4).IN pins.Overheating:
Microcontroller Resetting:
Can the L298N drive stepper motors? Yes, the L298N can control stepper motors by energizing the coils in the correct sequence. This requires additional programming.
What is the purpose of the 5V pin? The 5V pin provides a regulated 5V output that can power a microcontroller. However, it should not be used if the motor supply voltage exceeds 12V.
Can I use the L298N with a 3.3V microcontroller? Yes, but you may need level shifters to ensure proper logic levels for the control pins.