If you are planning on assembling your new robot, you will eventually want to learn how to control stepper motors. The easiest and inexpensive way to control stepper motors is to use the L298N motor driver. It can control both the speed and the spinning direction of any small to medium sized bipolar stepper motor such as the NEMA 17.
If you wish to control multiple stepper motors, it is recommended that you use a self-contained dedicated stepper motor driver such as the A4988. If you want to know more about it, check this tutorial out.
Controlling a Stepper Motor With an H-Bridge
The L298N module has two H-Bridges. Each H-bridge drives one of the electromagnetic coils of a stepper motor.
By energizing these electromagnetic coils in a specific sequence, the shaft of the stepper can be moved forward or backward precisely in small steps.
However, the speed of the motor is determined by how frequently these coils are energized.
The following animation shows how H-bridges drive a stepper motor.

L298N Motor Driver Chip
At the center of the module is a big, black chip with a chunky heat sink – the L298N, from ST Semiconductor.

Inside the L298N chip, you’ll find two standard H-bridges capable of driving a pair of DC motors or a single stepper motor.
The L298N motor driver has a supply range of 5V to 35V and is capable of supplying 2A continuous current per coil, so it works very well with most of our stepper motors.
Technical Specifications
Here are the specifications:
Motor output voltage | 5V – 35V |
Motor output voltage (Recommended) | 7V – 12V |
Logic input voltage | 5V – 7V |
Continuous current per channel | 2A |
Max Power Dissipation | 25W |
For more details, please refer below datasheet.
L298N Motor Driver Module Pinout
The L298N module has a total of 11 pins that connect it to the outside world. The pins are as follows:

Let’s get acquainted with all the pins one by one.
Power Pins
The L298N motor driver module is powered through 3-pin 3.5mm-pitch screw terminal.

The L298N motor driver actually has two input power pins – VS and VSS.
VS pin gives power to the internal H-Bridges of the IC to drive the motor. You can connect an input voltage anywhere between 5 to 12V to this pin.
VSS is used to drive the logic circuitry inside the L298N IC which can be 5 to 7V.
GND is the common ground pin.
Output Pins
The L298N motor driver’s output channels OUT1, OUT2, OUT3 and OUT4 are broken out to the edge of the module with two 3.5mm-pitch screw terminals. You can connect any 12-24V stepper motor to these terminals.

Each channel of the module can deliver up to 2A to the stepper motor. However the amount of current supplied to the motor depends on the power supply of the system.
Control Pins
Using the four control pins IN1, IN2, IN3 and IN4, you can control both the speed and the spinning direction of the stepper motor. These pins actually control the switches of the H-Bridge circuit inside the L298N chip.

The way you pulse these pins affects the behavior of the motor.
- The sequence of pulses determines the spinning direction of the motor.
- The frequency of the pulses determines the speed of the motor.
- The number of pulses determines how far the motor will turn.
Enable Pins
The enable pins ENA and ENB are used to enable or disable the motor independently of the input signals.

Pulling these pins HIGH will enable the motor, while pulling it LOW will disable the motor.
The module usually comes with jumpers on these pins. When the jumpers are in place, the motor is enabled. If you want to control the motor programmatically, you need to remove the jumpers and connect those pins to the digital pins on the Arduino.
On-board 5V Regulator and Jumper
The module has an on-board 5V regulator – 78M05. It can be enabled or disabled via a jumper.

When this jumper is in place, the 5V regulator is enabled, which derives the logic power supply (VSS) from the motor power supply (VS). In this case, the 5V input terminal (VSS) acts as the output pin and delivers 5V 0.5A. You can use it to power your Arduino or other circuitry that requires a 5V power supply.
When the jumper is removed, the 5V regulator is disabled and we have to separately supply 5V through the VSS pin.
Warning:
You can leave the jumper in place if the motor power supply is less than 12V. If it is higher than 12V you must remove the jumper to prevent damage to the onboard 5V regulator.
Also DO NOT supply power to both the VSS and VS pins while the jumper is in place.
How to Identify the Phases of a Bipolar Stepper Motor?
Before you start connecting the motor to the module, you need to identify the phases of the motor you plan to use. The best way to do this is to check the motor’s datasheet.
If you can’t find the datasheet, use the following trick.
- Put your multimeter in ‘resistance’ mode and simply measure pairs of wires for their resistance.
- If the resistance is only a few ohms (<100Ω), you’ve got a pair.
- The other two wires should form the second pair.

Wiring a Bipolar Stepper Motor to the L298N Module and Arduino
Let’s start by connecting the power supply to the module. In our experiment we are using a NEMA 17 bipolar stepper rated at 12V. Therefore, we will connect the external 12V power supply to the VS terminal.
Next, we need to supply 5V to the logic circuitry of the L298N. We will be using the on-board 5V regulator to derive 5V from the motor power supply, so leave the 5V-EN jumper in place.
You also need to keep both the ENA and ENB jumpers in place so that the motor is always enabled.
Now, connect the input pins (IN1, IN2, IN3 and IN4) of the L298N module to the four Arduino digital output pins (8, 9, 10 and 11).
Finally connect one phase of the motor to terminal A (OUT1 and OUT2) and the other phase to terminal B (OUT3 and OUT4). Polarity doesn’t matter.
The following image shows how to wire everything up.

Arduino Code – Controlling NEMA 17 Stepper Motor
Here is the simple sketch that makes the stepper motor spin clockwise at 60 RPM and then counterclockwise.
This sketch will give you a complete understanding on how to control a bipolar stepper motor like NEMA 17 with L298N motor driver and can serve as a basis for more practical experiments and projects.
// Include the Arduino Stepper Library
#include <Stepper.h>
// Number of steps per output rotation
const int stepsPerRevolution = 200;
// Create Instance of Stepper library
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup()
{
// set the speed at 60 rpm:
myStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
}
void loop()
{
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(500);
// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
delay(500);
}
Code Explanation:
The sketch starts with including the Arduino Stepper Library. The stepper library comes packaged with the Arduino IDE and takes care of the sequencing of the pulses that are sent to the motor.
// Include the Arduino Stepper Library
#include <Stepper.h>
After including the library we define a variable called stepsPerRevolution
. As the name suggests it is the number of steps per revolution that your motor is rated at. In our case it is 200.
// Number of steps per output rotation
const int stepsPerRevolution = 200;
Next, we create an object of the Stepper library. The constructor of the Stepper
class takes the steps per revolution of the motor and Arduino pin connections as arguments.
// Create Instance of Stepper library
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
In the setup section of the code, we set the speed of the stepper motor by calling the setSpeed()
function and initialize the serial communication.
void setup()
{
// set the speed at 60 rpm:
myStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
}
Finally in the loop section of the code, we simply call the step()
function which makes the motor turn a specific number of steps at a speed set by the setSpeed()
function. Passing a negative number to this function reverses the motor’s spinning direction.
void loop()
{
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(500);
// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
delay(500);
}
Please note that step()
is a blocking function. This means it will wait until the motor has finished moving, to pass control to the next line in your sketch. For example, if you set the speed to, say, 1 RPM and called step(100)
on a 100-step motor, this function will take a full minute to finish.