The L298N Arduino motor driver is one of the most essential modules for any robotics or automation project. It allows your Arduino to control DC motors and stepper motors with variable speed and direction — something an Arduino cannot do on its own since its I/O pins can only supply 40mA, far too little to drive a motor. This step-by-step guide covers everything from the L298N’s pin diagram to working code examples for forward, reverse, and PWM speed control.
Table of Contents
What is the L298N Motor Driver?
The L298N is a dual H-bridge motor driver IC (Integrated Circuit) manufactured by STMicroelectronics. An H-bridge is an electronic circuit that allows current to flow in either direction through a load (motor), enabling forward and reverse rotation. The “dual” designation means a single L298N IC can independently control two DC motors or one bipolar stepper motor.
Key Specifications of the L298N module:
- Driver IC: L298N (dual H-bridge)
- Motor supply voltage: 5V–35V DC
- Maximum output current: 2A per channel (4A peak)
- Logic voltage (control): 5V (compatible with Arduino directly)
- Number of motors: 2 DC motors OR 1 bipolar stepper motor
- Built-in 5V regulator: Provides 5V output when motor supply is 7V–35V (can power Arduino)
- Protection: Integrated flyback diodes protect against motor back-EMF
The L298N module is by far the most popular motor driver for beginner Arduino robotics projects in India, thanks to its ease of use, low cost (₹70–₹150), and compatibility with the Arduino’s 5V logic levels.
L298N Pin Diagram and Functions
Understanding the L298N module’s pinout is crucial before connecting anything. Here is a breakdown of every connector and pin on a standard L298N module:
| Pin / Terminal | Function | Connect To |
|---|---|---|
| VMS / +12V | Motor power supply (+) | 7V–12V DC (battery or adapter) |
| GND | Ground (power + logic) | Arduino GND and supply GND |
| 5V (output) | 5V regulated output (when jumper on) | Can power Arduino 5V pin |
| ENA (Enable A) | Enables Motor A. PWM input for speed control | Arduino PWM pin (e.g., pin 9) |
| IN1 | Direction control for Motor A (input 1) | Arduino digital pin |
| IN2 | Direction control for Motor A (input 2) | Arduino digital pin |
| OUT1 / OUT2 | Motor A terminals | DC Motor A wires |
| IN3 | Direction control for Motor B (input 1) | Arduino digital pin |
| IN4 | Direction control for Motor B (input 2) | Arduino digital pin |
| OUT3 / OUT4 | Motor B terminals | DC Motor B wires |
| ENB (Enable B) | Enables Motor B. PWM input for speed control | Arduino PWM pin (e.g., pin 10) |
The 5V jumper: Most L298N modules have a small jumper near the 5V output. When the motor supply voltage is between 7V and 35V, leave the jumper ON — the module’s built-in voltage regulator will output 5V which can power your Arduino. If the motor supply is exactly 5V, remove the jumper to bypass the regulator.
ENA/ENB jumpers: On the L298N module, ENA and ENB often have a jumper installed by default that connects them directly to 5V. This enables the motors at full speed always. Remove these jumpers when you want PWM speed control and connect ENA/ENB to Arduino PWM pins.
Wiring L298N to Arduino
For a single DC motor speed and direction control project, use the following wiring:
| L298N Pin | Connect To |
|---|---|
| VMS (+12V) | 9V or 12V battery / adapter (+) |
| GND | Battery GND and Arduino GND |
| 5V output | Arduino 5V pin (if using module’s regulator) |
| ENA (jumper removed) | Arduino Pin 9 (PWM) |
| IN1 | Arduino Pin 3 |
| IN2 | Arduino Pin 4 |
| OUT1 / OUT2 | DC Motor terminals |
Important wiring tips:
- Always connect Arduino GND to L298N GND. Without a common ground, the direction signals (IN1, IN2) will not work reliably.
- Use a separate power source for the motor (9V battery or 12V adapter). Do NOT try to power the motor from Arduino’s 5V pin — it cannot supply enough current and will damage the board.
- If your motor spins the wrong direction, swap the two wires connected to OUT1 and OUT2 (no code change needed).
Controlling DC Motor Direction
The L298N H-bridge controls motor direction by setting IN1 and IN2 HIGH or LOW in opposite states. Here is the truth table:
| IN1 | IN2 | Motor Action |
|---|---|---|
| HIGH | LOW | Forward |
| LOW | HIGH | Reverse |
| LOW | LOW | Stop (coast) |
| HIGH | HIGH | Brake (motor locked) |
// L298N Direction Control — No PWM (ENA jumper ON = full speed)
const int IN1 = 3;
const int IN2 = 4;
void setup() {
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
Serial.begin(9600);
}
void motorForward() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
Serial.println("Motor: FORWARD");
}
void motorReverse() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
Serial.println("Motor: REVERSE");
}
void motorStop() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
Serial.println("Motor: STOP");
}
void loop() {
motorForward(); delay(3000);
motorStop(); delay(1000);
motorReverse(); delay(3000);
motorStop(); delay(1000);
}
Speed Control with PWM
PWM (Pulse Width Modulation) controls motor speed by rapidly switching the enable pin (ENA) between HIGH and LOW. The analogWrite() function generates a PWM signal with a value from 0 (always off = stop) to 255 (always on = full speed). This gives smooth, proportional speed control.
To use PWM speed control: Remove the ENA jumper and connect ENA to Arduino pin 9 (or any other PWM pin marked with ~).
// L298N PWM Speed Control
// ENA connected to Pin 9 (PWM)
const int ENA = 9; // PWM pin for Motor A
const int IN1 = 3;
const int IN2 = 4;
void setup() {
pinMode(ENA, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
Serial.begin(9600);
}
void setMotor(int speed, bool forward) {
// speed: 0-255, forward: true/false
analogWrite(ENA, speed);
if (forward) {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
} else {
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
}
}
void loop() {
Serial.println("Accelerating forward...");
for (int s = 0; s = 0; s -= 5) {
setMotor(s, true);
delay(50);
}
delay(1000);
Serial.println("Running reverse at 50% speed...");
setMotor(128, false);
delay(3000);
setMotor(0, true); // Stop
delay(2000);
}
Controlling Two Motors Simultaneously
The L298N can drive two DC motors independently. This is the configuration used in most 2-wheeled Arduino robots (like line followers and obstacle avoiders). Here is the full wiring and code for a simple robot car:
Additional connections for Motor B: ENB → Arduino Pin 10, IN3 → Arduino Pin 5, IN4 → Arduino Pin 6, OUT3/OUT4 → Motor B terminals.
// Two-Motor Robot Car with L298N
const int ENA=9, IN1=3, IN2=4; // Motor A (Left)
const int ENB=10, IN3=5, IN4=6; // Motor B (Right)
void setup() {
pinMode(ENA,OUTPUT); pinMode(IN1,OUTPUT); pinMode(IN2,OUTPUT);
pinMode(ENB,OUTPUT); pinMode(IN3,OUTPUT); pinMode(IN4,OUTPUT);
}
void moveForward(int spd) {
analogWrite(ENA, spd); analogWrite(ENB, spd);
digitalWrite(IN1,HIGH); digitalWrite(IN2,LOW);
digitalWrite(IN3,HIGH); digitalWrite(IN4,LOW);
}
void moveBackward(int spd) {
analogWrite(ENA, spd); analogWrite(ENB, spd);
digitalWrite(IN1,LOW); digitalWrite(IN2,HIGH);
digitalWrite(IN3,LOW); digitalWrite(IN4,HIGH);
}
void turnLeft(int spd) {
analogWrite(ENA, 0); // Stop left motor
analogWrite(ENB, spd); // Right motor forward
digitalWrite(IN3,HIGH); digitalWrite(IN4,LOW);
}
void stopMotors() {
analogWrite(ENA,0); analogWrite(ENB,0);
digitalWrite(IN1,LOW); digitalWrite(IN2,LOW);
digitalWrite(IN3,LOW); digitalWrite(IN4,LOW);
}
void loop() {
moveForward(200); delay(2000);
turnLeft(150); delay(500);
moveForward(200); delay(2000);
moveBackward(180); delay(1500);
stopMotors(); delay(2000);
}
Using L298N with a Stepper Motor
The L298N can also drive a 4-wire (bipolar) stepper motor by using both motor channels together. Stepper motors move in precise angular steps (typically 1.8° per step = 200 steps per revolution), making them ideal for CNC machines, 3D printers, and precise positioning applications.
Wiring for stepper: Connect stepper coil A+ to OUT1, A- to OUT2, B+ to OUT3, B- to OUT4. Remove ENA and ENB jumpers and hold them HIGH (or connect to 5V permanently for full-current stepping).
#include <Stepper.h>
const int STEPS_PER_REV = 200; // 1.8 degree step motor
// IN1, IN3, IN2, IN4 order is important for Stepper library with L298N
Stepper stepper(STEPS_PER_REV, 3, 5, 4, 6);
void setup() {
stepper.setSpeed(60); // 60 RPM
Serial.begin(9600);
Serial.println("Stepper motor demo");
}
void loop() {
Serial.println("One full revolution clockwise");
stepper.step(STEPS_PER_REV);
delay(500);
Serial.println("One full revolution counter-clockwise");
stepper.step(-STEPS_PER_REV);
delay(500);
}
Troubleshooting Common Issues
If your L298N + Arduino motor project is not working as expected, check these common issues:
- Motor not spinning at all: Check that VMS has power, GND is common between Arduino and L298N, and ENA is either jumpered to 5V or receiving a non-zero PWM signal. Check IN1/IN2 are not both LOW.
- Motor spins in only one direction: Verify IN1 and IN2 are connected to separate Arduino pins. If both pins read the same state, check your code logic.
- Motor runs but very slowly at full code speed: If ENA is jumpered but motor is slow, check motor supply voltage. A 9V battery under load may drop to 6–7V. Use a fresh battery or a proper 12V adapter.
- L298N module gets very hot: The L298N has about 2V of voltage drop per H-bridge at full current. At 2A load it dissipates around 4W — this is normal. If the module shuts down from heat, add a heatsink to the L298N chip or reduce motor current by using a lower supply voltage.
- Arduino resets when motor starts: The motor’s startup current spike is causing the Arduino’s power supply to momentarily drop. Use separate power supplies for the Arduino and the motor (with shared GND), or add a large capacitor (470–1000µF, 16V) across VMS and GND.
- Motor spins freely without stopping (brake mode not working): Brake mode (IN1=HIGH, IN2=HIGH) requires ENA to be HIGH. If ENA is PWM-controlled and set to 0, the motor will coast instead of braking. Set ENA HIGH then set both IN pins HIGH to brake.
Frequently Asked Questions
Q: What is the maximum motor voltage and current the L298N can handle?
The L298N IC supports motor supply voltages from 5V to 46V and can deliver up to 2A continuous per channel (4A peak for brief intervals). The module version typically limits practical operation to 5V–35V due to PCB trace ratings and the onboard voltage regulator. For motors drawing more than 2A, consider using the L298N in parallel mode or switching to a higher-current driver like the BTS7960 (43A) or DRV8833 (1.5A, more efficient).
Q: Why is the L298N not recommended for small motors?
The L298N has a significant voltage drop of approximately 2V per H-bridge due to its bipolar transistor design. This means if you supply 5V to the motor terminals, the motor only receives about 3V. For small 3V–5V motors, this is a critical efficiency loss. For small motors, use more modern MOSFET-based drivers like the L9110S, TB6612FNG, or DRV8833, which have much lower voltage drop and higher efficiency.
Q: Can I control servo motors with the L298N?
No. Servo motors use a specific PWM control signal (50Hz, 1–2ms pulse width) that is incompatible with the L298N’s H-bridge control scheme. Servo motors should be connected directly to Arduino PWM pins and controlled with the Servo library. The L298N is designed for brushed DC motors and bipolar stepper motors only.
Q: How many L298N modules can I connect to one Arduino?
There is no hard limit from the L298N side — you can stack multiple modules. Each L298N module needs 3 Arduino pins per motor channel (ENA/ENB + IN1/IN2 or IN3/IN4). Two L298N modules controlling 4 motors would need 12 digital/PWM pins. An Arduino Uno with 14 digital pins can handle 2 modules; an Arduino Mega with 54 pins can control many more. All modules must share the Arduino’s GND connection.
Ready to Start Your Arduino Journey?
Shop all Arduino boards, sensors, and starter kits at Zbotic.in — India’s trusted electronics component store with fast shipping across India.
Add comment