

The L298N is a dual H-bridge motor driver that enables control of both the direction and speed of DC motors and stepper motors. It is capable of driving two motors simultaneously, making it a versatile and widely used component in robotics, automation, and motor control projects. The L298N is particularly popular in applications such as robotic vehicles, conveyor belts, and CNC machines due to its ability to handle high currents and its ease of integration with microcontrollers like Arduino.








The L298N module typically includes the following pins and terminals:
| Pin/Terminal | Description |
|---|---|
| IN1 | Input pin to control the direction of Motor A (logic HIGH or LOW). |
| IN2 | Input pin to control the direction of Motor A (logic HIGH or LOW). |
| IN3 | Input pin to control the direction of Motor B (logic HIGH or LOW). |
| IN4 | Input pin to control the direction of Motor B (logic HIGH or LOW). |
| ENA | Enable pin for Motor A. PWM signal can be applied here to control speed. |
| ENB | Enable pin for Motor B. PWM signal can be applied here to control speed. |
| OUT1 | Output terminal connected to one lead of Motor A. |
| OUT2 | Output terminal connected to the other lead of Motor A. |
| OUT3 | Output terminal connected to one lead of Motor B. |
| OUT4 | Output terminal connected to the other lead of Motor B. |
| 12V | Power supply input for the motors (typically 7V to 12V). |
| 5V | Logic voltage input/output. Can be used to power the module or as a 5V output. |
| GND | Ground connection. |
Power Connections:
12V terminal to the motor power supply (e.g., 7V to 12V).GND terminal to the ground of the power supply and the microcontroller.5V pin as a logic power supply.Motor Connections:
OUT1 and OUT2 terminals for Motor A, and OUT3 and OUT4 for Motor B.Control Connections:
IN1, IN2, IN3, and IN4 pins to the microcontroller's digital output pins.ENA and ENB pins to control the speed of Motor A and Motor B, respectively, by applying a PWM signal.Direction Control:
IN1 and IN2 pins to HIGH/LOW or LOW/HIGH to control the direction of Motor A.IN3 and IN4 pins to HIGH/LOW or LOW/HIGH to control the direction of Motor B.Speed Control:
ENA pin to control the speed of Motor A.ENB pin to control the speed of Motor B.// 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)
// Setup function to initialize pins
void setup() {
pinMode(IN1, OUTPUT); // Set IN1 as output
pinMode(IN2, OUTPUT); // Set IN2 as output
pinMode(ENA, OUTPUT); // Set ENA as output
}
// Loop function to control motor
void loop() {
// Rotate 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)
delay(2000); // Run motor for 2 seconds
// Rotate motor A backward at 75% speed
digitalWrite(IN1, LOW); // Set IN1 LOW
digitalWrite(IN2, HIGH); // Set IN2 HIGH
analogWrite(ENA, 192); // Set ENA to 75% duty cycle (192/255)
delay(2000); // Run motor for 2 seconds
// Stop motor A
digitalWrite(IN1, LOW); // Set IN1 LOW
digitalWrite(IN2, LOW); // Set IN2 LOW
analogWrite(ENA, 0); // Set ENA to 0% duty cycle (motor off)
delay(2000); // Wait for 2 seconds before repeating
}
Motors Not Running:
ENA and ENB pins are enabled (HIGH or receiving a PWM signal).Motor Running in the Wrong Direction:
IN1 and IN2 pins (or IN3 and IN4 for Motor B).Overheating:
Noisy Operation:
Can the L298N drive stepper motors?
Yes, the L298N can drive stepper motors by controlling the sequence of the IN pins. Use a stepper motor library for easier implementation.
Can I use the L298N with a 3.3V microcontroller? The L298N is designed for 5V logic levels. Use a level shifter or ensure the control signals are compatible.
What is the maximum motor voltage supported? The L298N supports motor voltages up to 46V, but ensure your motor and power supply are compatible.