The L298N is a dual H-bridge motor driver that enables control of the direction and speed of DC motors using Pulse Width Modulation (PWM) signals. It is capable of driving two DC motors simultaneously, making it a versatile and widely used component in robotics, automation, and motor control projects. The L298N is designed to handle motors with operating voltages between 5V and 35V and can deliver up to 2A of current per channel.
The L298N module has several pins and terminals for motor control and power input. Below is a detailed description:
Pin/Terminal | Description |
---|---|
VCC |
Motor power supply (5V to 35V). Connect to the motor's power source. |
GND |
Ground connection. Common ground for logic and motor power. |
5V |
Logic power supply (5V). Can also be used as a 5V output if VCC > 7V . |
OUT1 |
Output for Motor 1 (connect to one terminal of Motor 1). |
OUT2 |
Output for Motor 1 (connect to the other terminal of Motor 1). |
OUT3 |
Output for Motor 2 (connect to one terminal of Motor 2). |
OUT4 |
Output for Motor 2 (connect to the other terminal of Motor 2). |
Pin | Description |
---|---|
ENA |
Enable pin for Motor 1. Use PWM signal to control speed. |
ENB |
Enable pin for Motor 2. Use PWM signal to control speed. |
IN1 |
Input pin for Motor 1. Logic HIGH/LOW controls direction. |
IN2 |
Input pin for Motor 1. Logic HIGH/LOW controls direction. |
IN3 |
Input pin for Motor 2. Logic HIGH/LOW controls direction. |
IN4 |
Input pin for Motor 2. Logic HIGH/LOW controls direction. |
Power Connections:
VCC
terminal (5V to 35V).GND
terminal.5V
pin can be used as a 5V output to power external logic circuits.Motor Connections:
OUT1
and OUT2
.OUT3
and OUT4
.Control Connections:
ENA
and ENB
pins to PWM-capable pins on your microcontroller to control motor speed.IN1
, IN2
, IN3
, and IN4
to digital pins on your microcontroller to control motor direction.Logic Power:
5V
pin on the L298N module.Below is an example of how to control two DC motors using the L298N and an Arduino UNO:
ENA
→ Arduino Pin 9 (PWM)ENB
→ Arduino Pin 10 (PWM)IN1
→ Arduino Pin 7IN2
→ Arduino Pin 6IN3
→ Arduino Pin 5IN4
→ Arduino Pin 4VCC
→ External Motor Power Supply (e.g., 12V)GND
→ Common Ground (Arduino and Motor Power Supply)// Define control pins for Motor 1
#define ENA 9 // PWM pin for speed control
#define IN1 7 // Direction control pin
#define IN2 6 // Direction control pin
// Define control pins for Motor 2
#define ENB 10 // PWM pin for speed control
#define IN3 5 // Direction control pin
#define IN4 4 // Direction control pin
void setup() {
// Set motor control pins as outputs
pinMode(ENA, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
}
void loop() {
// Motor 1: Forward at 50% speed
analogWrite(ENA, 128); // Set speed (0-255)
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
// Motor 2: Backward at 75% speed
analogWrite(ENB, 192); // Set speed (0-255)
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
delay(2000); // Run motors for 2 seconds
// Stop both motors
analogWrite(ENA, 0);
analogWrite(ENB, 0);
delay(2000); // Wait for 2 seconds
}
Motors Not Running:
ENA
and ENB
pins are receiving PWM signals.OUT1
, OUT2
, OUT3
, OUT4
).Motors Running in the Wrong Direction:
IN1
and IN2
(or IN3
and IN4
) to reverse the motor direction.Overheating:
No 5V Output:
Can the L298N drive stepper motors? Yes, the L298N can drive stepper motors by controlling the sequence of the H-bridge outputs.
What is the maximum motor current the L298N can handle? The L298N can handle up to 2A per channel, but a heat sink is recommended for high currents.
Can I use the L298N with a 3.3V microcontroller? The L298N is designed for 5V logic. Use a level shifter or ensure the control signals are compatible.