Blog

L298N Motor Driver Module – 2A Dual Channel

🔌 ARDUINO TUTORIAL

L298N Motor Driver Module for DC & Stepper Motors

2A Dual Channel H-Bridge for bidirectionally controlling inductive loads.

⚡ High Power (2A)
🔄 Bidirectional
🔌 5V-35V Range
📶 PWM Control

🔍 Introduction

The L298N is a high-voltage, high-current dual full-bridge driver designed to control inductive loads like DC motors and stepper motors. This module can drive two DC motors bidirectionally or one stepper motor with up to 2A continuous current per channel.

💡 Why L298N? Unlike using single transistors, it provides a full H-bridge setup for easy bidirectional control, handles high current loads, and allows for precise speed control via PWM logic.

📊 Technical Specifications

Voltage

5V – 35V DC

Current

2A per channel (3A Peak)

Driver IC

L298N Dual H-Bridge

Control

PWM & Direction

🔌 Wiring Instructions

⚠️ IMPORTANT: Keep the jumper on the +5V terminal ONLY if your supply is 12V or less and you want to use the onboard regulator. Remove the jumper if supplying more than 12V to avoid damaging the regulator.

⚡ Connection Summary

Terminal Function Connection
+12V Motor Power (5-35V) Battery positive
GND Ground Battery negative
+5V Logic Power 5V (if jumper removed)
ENA / ENB Channel A/B Enable PWM capable pins (e.g., D9/D10)
IN1 / IN2 Channel A Control Digital pins (e.g., D8/D7)
IN3 / IN4 Channel B Control Digital pins (e.g., D6/D5)
OUT1/2 & OUT3/4 Motor A & B Motor Terminals

💻 Arduino Code Examples

📚 Required Library: No special library is required for basic DC motor control. For Stepper motors, the AccelStepper library is highly recommended for better performance.

L298N Motor Driver Module – 2A Dual Channel arduino code
🔌
Pin Connections
1 Table
Pin Connections Table 1
Arduino PinL298n Driver motor module
GNDGND
--12V VCC External power supplay
D10inA
D9in1
D8in2
D5inB
D6in3
D7in4
📟
L298N Motor Driver Module – 2A Dual Channel arduino code
1 Example • C/C++
L298N Motor Driver Module Dual Channel
📄File: l298n_motor_driver_module_dual_channel.ino
1876 characters
1// Motor A connections
2int enA = 10;
3int in1 = 9;
4int in2 = 8;
5
6// Motor B connections
7int enB = 5;
8int in3 = 7;
9int in4 = 6;
10
11void setup() {
12 // Set all the motor control pins to outputs
13 pinMode(enA, OUTPUT);
14 pinMode(in1, OUTPUT);
15 pinMode(in2, OUTPUT);
16
17 pinMode(enB, OUTPUT);
18 pinMode(in3, OUTPUT);
19 pinMode(in4, OUTPUT);
20
21 // Turn off motors - Initial state
22 digitalWrite(in1, LOW);
23 digitalWrite(in2, LOW);
24 digitalWrite(in3, LOW);
25 digitalWrite(in4, LOW);
26}
27
28void loop() {
29 directionControl();
30 delay(1000);
31 speedControl();
32 delay(1000);
33}
34
35// Function to demonstrate moving forward and backward
36void directionControl() {
37 // Set motors to maximum speed
38 // For PWM, possible values are 0 to 255
39 analogWrite(enA, 255);
40 analogWrite(enB, 255);
41
42 // Turn on motor A & B - Forward
43 digitalWrite(in1, HIGH);
44 digitalWrite(in2, LOW);
45 digitalWrite(in3, HIGH);
46 digitalWrite(in4, LOW);
47 delay(2000);
48
49 // Turn on motor A & B - Reverse
50 digitalWrite(in1, LOW);
51 digitalWrite(in2, HIGH);
52 digitalWrite(in3, LOW);
53 digitalWrite(in4, HIGH);
54 delay(2000);
55
56 // Stop motors
57 digitalWrite(in1, LOW);
58 digitalWrite(in2, LOW);
59 digitalWrite(in3, LOW);
60 digitalWrite(in4, LOW);
61}
62
63// Function to demonstrate controlling the speed of the motors
64void speedControl() {
65 // Turn on motors - Forward
66 digitalWrite(in1, HIGH);
67 digitalWrite(in2, LOW);
68 digitalWrite(in3, HIGH);
69 digitalWrite(in4, LOW);
70
71 // Accelerate from zero to maximum speed
72 for (int i = 0; i < 256; i++) {
73 analogWrite(enA, i);
74 analogWrite(enB, i);
75 delay(20);
76 }
77
78 // Decelerate from maximum speed to zero
79 for (int i = 255; i >= 0; --i) {
80 analogWrite(enA, i);
81 analogWrite(enB, i);
82 delay(20);
83 }
84
85 // Stop motors completely
86 digitalWrite(in1, LOW);
87 digitalWrite(in2, LOW);
88 digitalWrite(in3, LOW);
89 digitalWrite(in4, LOW);
90}
Arduino Board (Uno, Nano, or similar) L298N Dual Channel Motor Driver Module 2x DC Motors Motor Power Supply (e.g., 6V - 12V battery pack) Jumper wires

🚀 Project Ideas

The L298N is highly versatile. Here are some exciting projects you can build:

Robot Platform

Differential drive mobile robot for obstacle avoidance.

CNC Controller

Stepper motor control for DIY CNC machines.

Camera Slider

Smooth motorized motion control for videography.

⚖️ Advantages & Disadvantages

✅ Advantages

  • High Power Capacity – 2A continuous current per channel.
  • Bidirectional Control – Full forward and reverse control of two DC motors.
  • Wide Operating Range – Operates smoothly from 5V to 35V DC.
  • Speed Control – Hardware support for PWM speed modulation.
  • Built-in Regulator – Can power 5V logic systems when the source is under 12V.

❌ Disadvantages

  • Voltage Drop – BJT architecture causes a ~1.5V-2V drop delivered to the motors.
  • Heat Generation – Highly inefficient compared to modern drivers, practically requiring the bulky heatsink.
  • Older Technology – Superseded by more efficient MOSFET drivers (like TB6612FNG) for low-power builds.
  • Bulky Footprint – Takes up considerable space in tight enclosures.

🔧 Troubleshooting

  • Motor Not Moving: Check if enable jumpers are securely in place (if you are not using PWM pins). Verify the motor power supply provides adequate voltage/current and test with a direct battery connection.
  • Overheating: Ensure the heatsink is properly attached. Reduce the current draw (by using smaller motors) or add a cooling fan if you are driving near the 2A continuous limit.
  • Erratic Behavior: Add a 100μF ceramic capacitor across your motor terminals to reduce electrical noise. Always ensure your logic and motor power supplies share a common ground (GND).