ESP32 with L298N DC Motor Driver
- Β 08-06-2025
π§ Basic Introduction
- L298N is a dual H-Bridge motor driver ICΒ that allows controlling the direction and speed of two DC motors or one stepper motor.
- It operates onΒ high voltage and high current, making it suitable for robotics and mechatronics applications.
βοΈ Technical Specifications
- Operating Voltage:Β 5V to 35V (Motor supply); 5V logic supply.
- Current Handling:Β Up to 2A per channel continuously.
- Logic Level Inputs:Β Compatible with 5V logic (Arduino, ESP32, etc.).
- Heat Sink:Β Comes with a built-in heat sink to dissipate heat during high load.
- Control Pins:Β IN1, IN2, IN3, IN4 to control motor direction.
- Enable Pins (EN):Β ENA and ENB to control speed using PWM (Enable A for Motor A; Enable B for Motor B).
π Pin Description
- IN1 & IN2:Β Control Motor A direction.
- IN3 & IN4:Β Control Motor B direction.
- ENA (Enable A):Β Controls speed of Motor A using PWM.
- ENB (Enable B):Β Controls speed of Motor B using PWM.
- VCC:Β Power for motors (up to 35V).
- 5V:Β Logic voltage supply (can be from onboard 5V regulator or external).
- GND:Β Ground connection.
- OUT1 & OUT2:Β Outputs for Motor A.
- OUT3 & OUT4:Β Outputs for Motor B.
β‘ Working Principle
- UsesΒ H-Bridge configurationΒ to allow voltage to flow in either direction, enabling forward and reverse motor motion.
- Direction is controlled by logic levels on INx pins.
- Speed is controlled viaΒ PWM (Pulse Width Modulation)Β on the ENA and ENB pins.
π Direction Logic Table
| IN1 | IN2 | Motor A Direction |
|---|---|---|
| HIGH | LOW | Forward |
| LOW | HIGH | Reverse |
| LOW | LOW | Stop |
| HIGH | HIGH | Stop/Brake |
(Similar logic applies to IN3 and IN4 for Motor B)
β Advantages
- Can control two motors independently.
- Built-in protection diodes to handle back EMF from motors.
- Low cost and easily available.
- Compatible with Arduino, ESP32, Raspberry Pi, etc.
HOW TO OPERATE L298N DC MOTOR
#define IN1 18
#define IN2 19
#define IN3 13
#define IN4 12
void setup() {
pinMode(IN1,OUTPUT);
pinMode(IN2,OUTPUT);
pinMode(IN3,OUTPUT);
pinMode(IN4,OUTPUT);
}
void loop() {
// Forward Wise
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
// Backward Wise
digitalWrite(IN3,LOW);
digitalWrite(IN4,HIGH);
// HIGH HIGH , LOW LOW (BREAK)
digitalWrite(IN3,LOW);
digitalWrite(IN4,LOW);
}

Leave a Reply
You must be logged in to post a comment.