From smart curtains to automated conveyor belts, DC motors power countless IoT solutions. However, directly connecting them to an Arduino isn’t enough. That’s where the L298N motor driver comes in—a powerful solution for speed and direction control in real-world automation projects. One of the most popular methods for achieving this is by using an Arduino with the L298N motor driver. This blog will guide you through the process of connecting and controlling DC motors with Arduino and L298N for IoT projects.
Why Use the L298N Motor Driver?
When working with DC motors in IoT automation projects, directly connecting them to an Arduino is not feasible. This is because DC motors require more current and voltage than what an Arduino can supply. This is where the L298n Motor Driver Arduino setup becomes essential, as it acts as a bridge between the Arduino and the motors.
1. Handles High Voltage and Current
- The L298N can control motors with voltages up to 35V and currents up to 2A per channel.
- Arduino operates at 5V and can only supply a few milliamps, which is not enough for a motor.
2. Bidirectional Motor Control (H-Bridge Design)
- The L298N uses an H-Bridge circuit, allowing it to change the direction of the motor without needing extra relays or switches.
- You can make the motor move forward, backward, or stop using simple digital signals from Arduino.
3. Speed Control with PWM
- The L298N has ENA and ENB pins that accept PWM signals from the Arduino.
- This allows for smooth speed control of DC motors.
4. Can Control Two Motors Simultaneously
- The L298N has two motor channels (A & B), meaning it can control two motors independently.
- Perfect for robotics, automated vehicles, or conveyor belt systems.
5. Built-in Protection and Voltage Regulation
- It has thermal protection, preventing overheating.
- Comes with an onboard 5V regulator, which can supply power to Arduino (if needed).
Comprehensive Control of a DC Motor:
Achieving full control over a DC motor in IoT automation requires the ability to regulate both its speed and direction. This is accomplished using two key techniques:
- Pulse Width Modulation (PWM): Enables precise speed control by varying the motor’s input voltage.
- H-Bridge Circuit: Facilitates bidirectional movement by dynamically reversing the motor’s polarity.
Let’s learn more about these techniques:
1. Controlling DC Motor Speed Using PWM
The speed of a DC motor depends on the voltage supplied to it. To control this voltage efficiently, we use Pulse Width Modulation (PWM).
How PWM Works:
- PWM rapidly switches the motor ON and OFF at a high frequency.
- The Duty Cycle (percentage of time the signal is ON) determines the average voltage supplied to the motor.
- A higher duty cycle means more power, making the motor run faster.
- A lower duty cycle reduces power, making the motor run slower.
The image below illustrates the PWM technique, demonstrating different duty cycles and their corresponding average voltages.


The speed of a DC motor controlled by PWM can be calculated using the duty cycle formula:
2. H-Bridge – Controlling Motor Direction
The direction of a DC motor can be changed by reversing the polarity of its input voltage. A common method to achieve this is using an H-Bridge circuit.
- By activating specific switches, the voltage polarity across the motor changes, causing it to spin in the opposite direction.
- This allows precise forward and reverse control of the motor.
H-Bridge Control Logic:
IN1 | IN2 | Motor Direction |
HIGH | LOW | Forward |
LOW | HIGH | Backward |
LOW | LOW | Stop |
The animation below illustrates how an H-Bridge circuit controls motor direction.
H-Bridge circuit controls motor direction
L298N Motor Driver Chip:
The L298N motor driver is a widely used dual H-Bridge IC that enables efficient control of DC motors and stepper motors. It is commonly used in robotics, IoT automation, and motor control systems where independent speed and direction control of multiple motors is required.
- Key Features of the L298N Motor Driver
- Controls Two DC Motors Independently – Allows separate speed and direction control for each motor.
- Supports PWM for Speed Control – Enables smooth acceleration and deceleration.
- Works with a Wide Voltage Range – Operates with motors from 5V to 35V and provides up to 2A per channel.
- H-Bridge Circuitry – Enables bidirectional motor control (forward & reverse).
- Built-in Thermal Shutdown – Protects against overheating and excessive current.
- Compatible with Microcontrollers – Works with Arduino, ESP8266, ESP32, Raspberry Pi, and other platforms.
Technical Specification:
Parameter | Specification |
Operating Voltage | 5V – 35V |
Output Current | Up to 2A per channel |
Logic Voltage | 5V |
Logic Current | 0 – 36mA |
PWM Support | Yes |
Controlled Motors | 2 DC or 1 Stepper Motor |
Built-in Protection | Thermal shutdown |

Technical Specification
L298N Motor Driver Module Pinout Overview:

L298N Motor Driver Module Pinout Diagram
Understanding the Pinout of the L298N Motor Driver Module
The L298N motor driver module is designed to control two DC motors or one stepper motor using an H-Bridge circuit. Below is a brief explanation of each pin:
1. Power Pins:
- The L298N motor driver has two input power pins: VS and VSS and one GND pin.
- VS[1] → Connects to an external power source (5V to 35V) for driving the motors.
- GND[2] → Common ground connection for both logic and motor power.
- VSS[3] → Provides a regulated 5V output (used when operating at voltages above 7V).
2.Motor Output Pins:
The L298N motor driver module has two output channels for connecting motors:
- OUT1 & OUT2[8] → Connect Motor A
- OUT3 & OUT4 [9]→ Connect Motor B
These outputs are provided through screw terminals for easy wiring.
You can connect two DC motors (5V-12V) to these terminals. Each motor channel can provide up to 2A of current, but the actual current depends on your power supply’s capacity.
3. Control Pins (For Motor Direction):
- IN1 & IN2 [5](Motor A Control):
- IN1 = HIGH & IN2 = LOW → Motor A moves forward
- IN1 = LOW & IN2 = HIGH → Motor A moves backward
- IN1 = IN2 → Motor A stops
- IN3 & IN4 [6](Motor B Control):
- IN3 = HIGH & IN4 = LOW → Motor B moves forward
- IN3 = LOW & IN4 = HIGH → Motor B moves backward
- IN3 = IN4 → Motor B stops
4. Enable Pins (For Speed Control using PWM):
Setting these pins to HIGH will make the motors spin, while setting them to LOW will stop them. However, you can control the speed of the motors using Pulse Width Modulation (PWM), which allows you to adjust how fast they spin.
By default, the module has a jumper on these pins, which makes the motors run at full speed. If you want to control the speed programmatically, you need to remove the jumper and connect these pins to the PWM-enabled pins of an Arduino or microcontroller.
ENA [4] (Enable A) → Controls the speed of Motor A via PWM signal.
ENB [7] (Enable B) → Controls the speed of Motor B via PWM signal.
If ENA/ENB = HIGH, the corresponding motor is enabled.
If ENA/ENB = LOW, the corresponding motor is disabled.
Voltage Drop in L298N Motor Driver:
The L298N motor driver has an internal voltage drop due to its built-in transistors, which affects the voltage supplied to the motors. This drop depends on the motor power supply voltage and the current drawn by the motors.

Typical Voltage Drop:
- When using a 12V power supply, the actual voltage available to the motors is around 10V due to a 2V drop per channel.
- The voltage drop increases as motor current increases, typically between 1.8V to 3V per channel.
- At higher currents (above 1A per channel), the voltage drop can reach up to 4V, reducing motor efficiency.
Impact of Voltage Drop:
- If your motor requires a specific voltage (e.g., 12V), you should use a higher power supply voltage (e.g., 15V–18V) to compensate for the loss.
- For low-voltage motors (5V–6V), the voltage drop can significantly affect performance, making other motor drivers (e.g., DRV8871, TB6612FNG) a better choice.
Wiring an L298N Motor Driver Module to an Arduino:
To control two DC motors using the L298N motor driver and Arduino, follow these wiring steps carefully:
1. Powering the Motor Driver:
- Connect the 12V (VCC) pin of the L298N to the positive terminal of the battery pack (6V-12V). This powers the motors.
- Connect the GND pin of the L298N to the negative terminal of the battery pack.
- Connect the same GND pin of L298N to the GND pin of Arduino to ensure a common ground.
2. Connecting Motor A (Left Motor) to L298N:
- Connect one motor terminal to the OUT1 pin on the L298N.
- Connect the other motor terminal to the OUT2 pin on the L298N.
- The motor’s direction depends on the HIGH/LOW signals sent to IN1 and IN2.
3. Connecting Motor B (Right Motor) to L298N:
- Connect one motor terminal to the OUT3 pin on the L298N.
- Connect the other motor terminal to the OUT4 pin on the L298N.
- The motor’s direction depends on the HIGH/LOW signals sent to IN3 and IN4.
4. Connecting the L298N to Arduino:
- ENA (Enable A) pin → Arduino Pin 9 (PWM) → Controls speed of Motor A.
- IN1 pin → Arduino Pin 7 → Controls Motor A Direction.
- IN2 pin → Arduino Pin 8 → Controls Motor A Direction.
- ENB (Enable B) pin → Arduino Pin 10 (PWM) → Controls speed of Motor B.
- IN3 pin → Arduino Pin 5 → Controls Motor B Direction.
- IN4 pin → Arduino Pin 6 → Controls Motor B Direction.
5. Optional: Powering Arduino from L298N
- If using a 12V battery pack, the 5V output of L298N can provide power to Arduino by connecting it to the Arduino’s 5V pin.
- Important: If using an external Arduino power source, remove the jumper cap on the L298N 5V output to prevent damage.
Circuit Diagram:

Arduino Code:
#define ENA 9 // Enable A (PWM control for Motor A)
#define IN1 8 // Input 1 for Motor A
#define IN2 7 // Input 2 for Motor A
#define ENB 3 // Enable B (PWM control for Motor B)
#define IN3 5 // Input 1 for Motor B
#define IN4 4 // Input 2 for Motor B
void setup() {
pinMode(ENA, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
}
void loop() {
moveForward();
delay(2000);
moveBackward();
delay(2000);
stopMotors();
delay(2000);
}
void moveForward() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
analogWrite(ENA, 150);
analogWrite(ENB, 150);
}
void moveBackward() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
analogWrite(ENA, 150);
analogWrite(ENB, 150);
}
void stopMotors() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
IOT Applications
1. Smart Home Automated Curtains
Description: A DC motor can be used to open and close curtains remotely via an IoT-based system.
Code:
void openCurtains() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
analogWrite(ENA, 200);
}
void closeCurtains() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
analogWrite(ENA, 200);
}
2. Automated Smart Door Lock
Description: A motorized locking mechanism that can be controlled using a smartphone.
void unlockDoor() {
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
analogWrite(ENB, 255);
}
void lockDoor() {
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
analogWrite(ENB, 255);
}
3. IoT-Based Conveyor Belt System
Description: An automated conveyor belt system controlled via IoT for industrial automation.
Code:
void startConveyor() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
analogWrite(ENA, 180);
analogWrite(ENB, 180);
}
void stopConveyor() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
Conclusion:
Using the L298N motor driver with Arduino provides an efficient and reliable way to control DC motors for IoT automation. This setup enables smooth motor operation, including speed control and direction changes, making it ideal for smart home applications, robotics, and industrial automation.
By integrating an IoT module, such as ESP8266, ESP32, or Raspberry Pi, users can remotely control motors via a web interface or mobile app, thereby enhancing automation and convenience. The flexibility and scalability of this system make it a cost-effective solution for various IoT-based motor control applications.
With the right coding and hardware setup, this project can be extended for real-world use cases such as automated conveyor systems, smart locks, and home automation. By leveraging Arduino’s versatility and IoT connectivity, users can create more intelligent and responsive systems for modern automation needs.
Image(s) used in this blog belong to their respective owners. If you own the rights and would like credit or removal, please contact us.
Click here to read more blogs like this.
As a Software Development Engineer in Test (SDET), I specialize in developing automation scripts for mobile applications with integrated hardware for both Android and iOS devices. In addition to my software expertise, I have designed and implemented PCB layouts and hardware systems for integrating various components such as sensors, relays, Arduino Mega, and Raspberry Pi 4. I programmed the Raspberry Pi 4 and Arduino Mega using C/C++ and Python to control connected devices. I developed communication protocols, including UART, I2C, and SPI, for real-time data transmission and also implemented SSH communication to interface between the hardware and testing framework.