L298N Driver
The L298N is a dual H-Bridge motor driver which allows speed and direction control of two DC motors at the same time. The module can drive DC motors that have voltages between 5 and 35V, with a peak current up to 2A.

Let’s take a closer look at the pinout of L298N module and explain how it works. The module has two screw terminal blocks for the motor A and B, and another screw terminal block for the Ground pin, the VCC for motor and a 5V pin which can either be an input or output.
Specifications of L298N Motor Driver
· The module will allow you to control the speed and direction of two DC motors. |
· It can control motors which operates between 5 to 35V and up to 2A. |
· The module has an onboard regulator which helps in giving the output of 5V. |
· The module can be powered from 5 to 35V from Arduino or external power supply. It is recommended to always use the external voltage supply. |
· It can also control a stepper motor. |
· It is inexpensive and perfect for robotic projects. |
Pin out of L298N Motor Driver
Motor A: This terminal block will give the output for the first motor.
12V Jumper: Keep this jumper in place if your supply voltage is less than 12V and the 5V power pin will give you the output of 5V. If the supply voltage is greater than 12V, then remove this jumper and give the 5V supply to the 5V power pin so that the L298 Dual H Bridge IC can work properly.
Power Pins: Give the supply voltage from 5 to 35V at the 12V pin and ground. If your supply voltage is greater than 12, then make sure to remove the 12V jumper. 5V pin will act as Output if the Vs will be less than 12V and 5V pin will act as Input if the Vs will be greater than 12V.
Enable Pins: Remove the jumpers on the Enable A and Enable B if you want to control the speed of DC motors and connect these to PWM pins of Arduino. If you want to control the stepper motor with L298N, then keep the jumper on Enable A and Enable B. Keeping the jumper on these pins means that the these pins will be High.
Logic Pins: Connect the Logic pins to any digital pins of Arduino. These will help in controlling the rotation and speed of DC motors.
Motor B: This terminal block will give the output for the second motor.
5V linear Regulator: This will step down the supply voltage to 5V and will give the output at the 5V pin

Arduino and L298N
Now let’s make some practical applications. In the first example we will control the speed of the motor using a potentiometer and change the rotation direction using a push button. Here’s the circuit schematics.

Arduino Code
/* Arduino DC Motor Control – PWM | H-Bridge | L298N – Example 01
by Dejan Nedelkovski, www.HowToMechatronics.com
*/
#define enA 9
#define in1 6
#define in2 7
#define button 4
int rotDirection = 0;
int pressed = false;
void setup() {
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(button, INPUT);
// Set initial rotation direction
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
}
void loop() {
int potValue = analogRead(A0); // Read potentiometer value
int pwmOutput = map(potValue, 0, 1023, 0 , 255); // Map the potentiometer value from 0 to 255
analogWrite(enA, pwmOutput); // Send PWM signal to L298N Enable pin
// Read button – Debounce
if (digitalRead(button) == true) {
pressed = !pressed;
}
while (digitalRead(button) == true);
delay(20);
// If button is pressed – change rotation direction
if (pressed == true & rotDirection == 0) {
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
rotDirection = 1;
delay(20);
}
// If button is pressed – change rotation direction
if (pressed == false & rotDirection == 1) {
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
rotDirection = 0;
delay(20);
}
}
Applications
- Arduino DC Motor Control using L298N Motor Driver project can be the beginning step of many advanced projects.
- Almost all robots have wheels and we need to control the motors connected to those wheels. Hence, any Arduino based robot can implement this type of motor control using L298N.
- Some of the Robotic Applications of L298N Motor Driver are Hand Gesture Controlled Robot, Line Follower Robot, Obstacle Avoiding Robot, etc.
Reference:
https://electronicshobbyists.com/controlling-dc-motors-arduino-arduino-l298n-tutorial/
https://www.instructables.com/id/How-to-Use-L298n-to-Control-Dc-Motor-With-Arduino/
https://www.electronicshub.org/arduino-dc-motor-control-using-l298n/