L298N Motor Driver: A Beginner's Guide to Motor Control

Introduction

Are you looking to add motor control to your Arduino projects? The L298N motor driver might be just what you need. This module is a popular choice for hobbyists and professionals alike, offering an easy way to control DC and stepper motors. From student projects to final year projects in engineering, the L298N is versatile and reliable. In this article, we’ll dive deep into the L298N, covering its description, pin configuration, uses, features, and more.

L298N motor driver module — labelled pins OUT1–OUT4, IN1–IN4, ENA, ENB, 5V, GND, 12V

What is the L298N Motor Driver?

The L298N motor driver is a dual H-bridge motor driver module that allows for the control of the speed and direction of two DC motors or one stepper motor.

The L298N motor driver is a powerful module capable of simultaneously driving two DC motors or one stepper motor. It uses the H-bridge configuration, allowing full control over the motor’s direction and speed. The module can be easily interfaced with Arduino and other microcontrollers, making it a popular choice for various robotics and automation projects.

Specifications and Features

Technical Specifications of L298N

Voltage Requirements

The L298N can handle motor supply voltages from 5V to 35V, making it suitable for various applications.

Current Rating

Each channel of the L298N can provide up to 2A continuous current, with a peak current of up to 3A. This allows it to drive most small to medium-sized motors efficiently.

Supported Motors

The L298N is compatible with both DC motors and stepper motors, providing flexibility for various types of projects.

One thing to know: the L298N drops about 2V inside the chip, so a 12V supply gives roughly 10V at the motor. That is normal for this module — if your motor runs slower than expected, that voltage drop is the reason, not a fault.

Key Features

  • Dual H-bridge configuration
  • Supports both DC and stepper motors
  • High current capability
  • PWM speed control
  • Easy interface with Arduino

Advantages

  1. Cost-effective
  2. Reliable performance
  3. Versatile for various applications

Configuration of the L298N

Overview of the Pins

The L298N has several pins and terminals for connecting power, control signals, and motors. Here’s a breakdown of the key pins:

  1. 12V — motor power supply input
  2. GND — ground (common ground with the Arduino)
  3. 5V — regulated 5V output (see below)
  4. IN1, IN2, IN3, IN4 — direction control inputs
  5. OUT1, OUT2, OUT3, OUT4 — motor outputs
  6. ENA, ENB — enable pins (speed control)

Detailed Pin Description

12V: This pin is for the motor power supply, connected to a power source that matches the voltage requirements of the motors (for example a 12V adapter or battery pack).

GND: This is the ground pin. The Arduino GND and the motor supply GND must be connected together (common ground) — without it, the control signals have no reference and the motors will not run properly.

5V: This is the regulated 5V output from the module’s onboard regulator. When the 5V jumper is fitted (the default), the module makes 5V from the motor supply and this pin can power the Arduino. When the motor supply is above 12V, remove the 5V jumper and feed 5V into this pin from a separate source instead — otherwise the regulator overheats.

IN1, IN2, IN3, IN4: These pins are used to control the direction of the motors. IN1 and IN2 control the first motor, while IN3 and IN4 control the second motor.

OUT1, OUT2, OUT3, OUT4: These are the output pins connected to the motors. OUT1 and OUT2 connect to the first motor, and OUT3 and OUT4 connect to the second motor.

ENA, ENB: These are the enable pins for the motors. ENA enables the first motor, and ENB enables the second motor. These pins can be used to control the speed of the motors via PWM (Pulse Width Modulation). With the jumpers fitted, the motors run at full speed; remove the jumpers and connect ENA/ENB to PWM pins on the Arduino for speed control.

How to Connect the L298N to an Arduino

Step-by-Step Guide

  1. Gather Components: You’ll need an L298N module, an Arduino board, jumper wires, and a power source for the motors.
  2. Connect Power: Attach the 12V pin of the L298N to the motor power supply, the GND pin to the Arduino’s ground (common ground), and — if the 5V jumper is fitted — the 5V pin to the Arduino’s 5V pin to power it.
  3. Connect Control Pins: Connect IN1, IN2, IN3, and IN4 to four digital pins on the Arduino (pins 8, 9, 10, 11 in the code below).
  4. Connect Motors: Connect the motors to the OUT1, OUT2, OUT3, and OUT4 pins of the L298N.
  5. Enable Pins: Connect ENA and ENB to two PWM pins on the Arduino (pins 5 and 6) to control motor speed — remove the ENA/ENB jumpers first.
L298N motor driver wiring diagram — Arduino Nano, two DC gear motors and 12V battery
Wiring diagram: Arduino Nano + L298N + two DC gear motors + 12V battery (the joystick is optional — the post’s code uses an UNO with the same L298N connections).

Setting Up the L298N Module

Configuring the ENA and ENB Pins

The ENA and ENB pins are used to enable the motors and control their speed using PWM signals from the Arduino. These pins must be connected to PWM-capable digital pins on the Arduino.

Connecting Power and Ground

Ensure that the power supply for the motors is adequate and that the GND pins of the L298N and Arduino are connected to a common ground.

Wiring the Motors

Connect your motors to the OUT1, OUT2, OUT3, and OUT4 pins. Ensure the connections are secure to prevent any loose connections.

Required Components

ComponentPurposePrice / link
L298N motor driverMotor driver (dual H-bridge)Rs 375
Arduino UnoMain controllerArduino UNO R3 DIP — Rs 1,200
DC gear motorWheels (×2)Rs 165 each
NEMA 17 stepper motorStepper option (bipolar, 4-wire)Rs 670
12V 2A adapterMotor power supplyRs 275
Jumper wiresConnectionsRs 180
BreadboardPrototypingMB102 — Rs 250

Programming the Arduino for L298N Motor Control

Sample Code

// L298N motor driver — two DC motors with speed control
const int in1 = 8;   // Motor A direction
const int in2 = 9;   // Motor A direction
const int in3 = 10;  // Motor B direction
const int in4 = 11;  // Motor B direction
const int ena = 5;   // Motor A speed (PWM)
const int enb = 6;   // Motor B speed (PWM)

void setup() {
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
  pinMode(ena, OUTPUT);
  pinMode(enb, OUTPUT);
}

void loop() {
  // Both motors forward at 200/255 speed
  digitalWrite(in1, HIGH); digitalWrite(in2, LOW);
  digitalWrite(in3, HIGH); digitalWrite(in4, LOW);
  analogWrite(ena, 200);   analogWrite(enb, 200);
  delay(2000);

  // Both motors backward
  digitalWrite(in1, LOW);  digitalWrite(in2, HIGH);
  digitalWrite(in3, LOW);  digitalWrite(in4, HIGH);
  analogWrite(ena, 200);   analogWrite(enb, 200);
  delay(2000);

  // Stop
  digitalWrite(in1, LOW);  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);  digitalWrite(in4, LOW);
  delay(1000);
}

How the code works: IN1/IN2 set motor A’s direction (HIGH/LOW = forward, LOW/HIGH = backward, LOW/LOW = stop) and IN3/IN4 do the same for motor B. ENA and ENB take a PWM value (0–255) that sets the speed. Remove the ENA/ENB jumpers on the module first, otherwise the PWM signal has no effect and the motors run at full speed.

For a complete robot car that uses this driver, see our obstacle-avoidance robot car guide — it uses the same L298N wiring with an HC-SR04 ultrasonic sensor.

Common Uses of the L298N Motor Driver

Controlling DC Motors

The L298N is perfect for controlling the speed and direction of DC motors in various projects.

Controlling Stepper Motors

The L298N can drive one bipolar stepper motor (4-wire, two coils) — one coil on OUT1/OUT2 and the other on OUT3/OUT4. Use the Arduino Stepper library with the four IN pins. Note: the common 28BYJ-48 stepper is unipolar (5-wire) and is normally driven by its own ULN2003 driver board, not by the L298N. For an L298N stepper, use a bipolar motor such as the NEMA 17.

Robotics Projects

Use the L298N to control the movement of robots, providing precise control over speed and direction.

Student Projects

Ideal for student projects, the L298N motor driver helps in learning about motor control and electronics.

Final Year Projects

For final-year projects, the L298N offers a robust solution for complex motor control applications.

L298N Motor Driver Troubleshooting Common Issues

Motor Not Running

Check the power connections and ensure that the control pins are correctly connected and programmed. The most common cause is a missing common ground between the Arduino and the motor supply.

Overheating Problems

Ensure adequate cooling and heat dissipation for the L298N module. Consider using a heatsink if necessary. The module’s large black heatsink is there for a reason — at 2A per channel it gets hot.

Power Issues

Verify that the power supply is sufficient for the motors being used. Check for loose connections. Remember the ~2V drop: a 12V supply gives about 10V at the motor.

Tips for Optimizing L298N Performance

Proper Heat Dissipation

Use heatsinks and ensure proper ventilation to prevent the module from overheating.

Ensuring Adequate Power Supply

Make sure your power supply meets the voltage and current requirements of the motors and the L298N module. A 12V 2A adapter is enough for two small DC gear motors; bigger motors need a bigger supply.

Security Considerations for L298N Motor Driver

Protecting Your Electronics

Use proper fuses and protection circuits to prevent damage to your electronics.

Ensuring Safe Operation

Follow safety guidelines to avoid short circuits and other hazards. Never connect or disconnect motors while the power is on.

Comparing L298N with Other Motor Drivers

L293D vs. L298N

The L298N can handle higher currents compared to the L293D, making it more suitable for larger motors. The L293D (used on the L293D motor shield) is limited to about 600 mA per channel, while the L298N handles up to 2A per channel. The L293D shield is easier to use (it plugs straight onto the Arduino); the L298N is the choice when the motors need more current.

Other Alternatives

Consider alternatives like the DRV8833 or the BTS7960 for more advanced features and higher-power applications. Both are available on order — message us on WhatsApp.

Advanced Configurations and Hacks of L298N Motor Driver

Controlling Multiple Motors

You can control more than two motors by cascading multiple L298N modules.

Customizing Firmware

Advanced users can modify the firmware to unlock additional features and optimize performance.

Where to Buy the Parts

The L298N motor driver (Rs 375), Arduino UNO R3 DIP (Rs 1,200), DC gear motor (Rs 165 each), NEMA 17 stepper motor (Rs 670), 12V 2A adapter (Rs 275), jumper wires (Rs 180) and MB102 breadboard (Rs 250) are available at QKZEE Technologies, Shop 20, 1st Floor, Al-Khalil Center, Hall Road, Lahore, and online at qkzeetech.com with delivery all over Pakistan — see the links above. The DRV8833 and BTS7960 drivers are available on order — message us on WhatsApp.

Still Stuck?

If the motors do not move, or only one motor runs, message us — tell us whether the 12V supply is connected, whether the Arduino GND and the L298N GND are joined, and whether the ENA/ENB jumpers are removed, and we will help you find the fault.

Chat on WhatsApp Watch on YouTube

FAQs

Why do the motors not move even though the code uploaded?

The most common cause is a missing common ground: the Arduino GND and the L298N GND must be joined. The second most common cause is no motor power — check the 12V supply is connected and switched on.

Why do the motors run at full speed even though I set a PWM value?

The ENA/ENB jumpers are still fitted. Remove them and connect ENA/ENB to PWM pins (5 and 6 in the code) — with the jumpers on, the enable pins are tied to 5V and the motors run at full speed regardless of the code.

Why is the motor slower than I expected?

The L298N drops about 2V inside the chip, so a 12V supply gives roughly 10V at the motor. That is normal for this module.

Why does the L298N get hot?

At 2A per channel it dissipates several watts as heat — that is what the big black heatsink is for. Make sure air can flow around it, and do not run it at full current for long without ventilation.

Can the L298N drive a 28BYJ-48 stepper motor?

Not directly — the 28BYJ-48 is a unipolar (5-wire) stepper and is normally driven by its own ULN2003 driver board. The L298N drives bipolar steppers (4-wire, two coils), such as the NEMA 17.

Can I power the Arduino from the L298N?

Yes, when the 5V jumper is fitted and the motor supply is 12V or less — the module’s onboard regulator makes 5V that can power the Arduino. Above 12V, remove the jumper and feed 5V separately.

Conclusion

The L298N motor driver is a versatile and reliable component for adding motor control to your Arduino projects. Its ease of use, affordability, and robust performance make it a favorite among hobbyists and professionals alike. Whether you’re working on home automation, robotics, or simple motor control, the L298N is an excellent choice. Plus, if you’re in Lahore or shopping at Hall Road, you’ll find it to be one of Pakistan’s best solutions for motor control.