Back to Tutorial

ESP32 with L298N DC Motor Driver


  •  08-06-2025

🔧 Basic Introduction

  1. L298N is a dual H-Bridge motor driver IC that allows controlling the direction and speed of two DC motors or one stepper motor.
  2. It operates on high voltage and high current, making it suitable for robotics and mechatronics applications.

⚙️ Technical Specifications

  1. Operating Voltage: 5V to 35V (Motor supply); 5V logic supply.
  2. Current Handling: Up to 2A per channel continuously.
  3. Logic Level Inputs: Compatible with 5V logic (Arduino, ESP32, etc.).
  4. Heat Sink: Comes with a built-in heat sink to dissipate heat during high load.
  5. Control Pins: IN1, IN2, IN3, IN4 to control motor direction.
  6. Enable Pins (EN): ENA and ENB to control speed using PWM (Enable A for Motor A; Enable B for Motor B).

🔌 Pin Description

  1. IN1 & IN2: Control Motor A direction.
  2. IN3 & IN4: Control Motor B direction.
  3. ENA (Enable A): Controls speed of Motor A using PWM.
  4. ENB (Enable B): Controls speed of Motor B using PWM.
  5. VCC: Power for motors (up to 35V).
  6. 5V: Logic voltage supply (can be from onboard 5V regulator or external).
  7. GND: Ground connection.
  8. OUT1 & OUT2: Outputs for Motor A.
  9. OUT3 & OUT4: Outputs for Motor B.

⚡ Working Principle

  1. Uses H-Bridge configuration to allow voltage to flow in either direction, enabling forward and reverse motor motion.
  2. Direction is controlled by logic levels on INx pins.
  3. Speed is controlled via PWM (Pulse Width Modulation) on the ENA and ENB pins.

🔄 Direction Logic Table

IN1IN2Motor A Direction
HIGHLOWForward
LOWHIGHReverse
LOWLOWStop
HIGHHIGHStop/Brake

(Similar logic applies to IN3 and IN4 for Motor B)


✅ Advantages

  1. Can control two motors independently.
  2. Built-in protection diodes to handle back EMF from motors.
  3. Low cost and easily available.
  4. 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);


}
iotwebplanet.com - 1

Share this post

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to Tutorial