Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

How to Use L298N: Examples, Pinouts, and Specs

Image of L298NDesign with L298N in Cirkit Designer

Introduction

The L298N is a dual H-bridge motor driver designed to control the direction and speed of DC motors and stepper motors. It is a versatile and robust component capable of driving two motors simultaneously, with each channel supporting up to 2A of current. The L298N is widely used in robotics, automation, and other motor control applications due to its ease of use and compatibility with microcontrollers like Arduino.

Explore Projects Built with L298N

Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
Image of ESP32-CAM Controlled Surveillance Robot with Wi-Fi and Servo Pan/Tilt Mechanism: A project utilizing L298N in a practical application
ESP32-CAM Controlled Surveillance Robot with Wi-Fi and Servo Pan/Tilt Mechanism

This circuit is designed to control a mobile platform with four DC motors for movement, two servos for directional control, and an ESP32-CAM module for wireless video streaming. The L298N motor driver interfaces with the ESP32-CAM to drive the motors based on commands received over WiFi, allowing for remote directional control. The ESP32-CAM also handles the servo positioning and streams live video, enabling the user to control and monitor the platform remotely through a web interface.

Open Project in Cirkit Designer

Common Applications and Use Cases

Technical Specifications

Key Technical Details

Pin Configuration and Descriptions

The L298N module typically has the following pins:

Pin Name Type Description
IN1 Input Motor A control input 1. Used to set the direction of Motor A.
IN2 Input Motor A control input 2. Used to set the direction of Motor A.
IN3 Input Motor B control input 1. Used to set the direction of Motor B.
IN4 Input Motor B control input 2. Used to set the direction of Motor B.
ENA Input (PWM) Enable pin for Motor A. Can be used for speed control via PWM.
ENB Input (PWM) Enable pin for Motor B. Can be used for speed control via PWM.
OUT1 Output Motor A output 1. Connects to one terminal of Motor A.
OUT2 Output Motor A output 2. Connects to the other terminal of Motor A.
OUT3 Output Motor B output 1. Connects to one terminal of Motor B.
OUT4 Output Motor B output 2. Connects to the other terminal of Motor B.
12V Power Input External power supply for the motors (5V to 46V).
5V Power Output Regulated 5V output (can power a microcontroller if the jumper is in place).
GND Ground Common ground for the module and external power supply.

Note: Some L298N modules include a 5V-EN jumper. When this jumper is in place, the module's onboard voltage regulator provides 5V to the logic circuit. If using an external 5V supply, remove this jumper.

Usage Instructions

How to Use the L298N in a Circuit

  1. Power Connections:

    • Connect the 12V pin to an external power source (5V to 46V) suitable for your motors.
    • Connect the GND pin to the ground of the power source and the microcontroller.
    • If the onboard 5V regulator is used, ensure the 5V-EN jumper is in place.
  2. Motor Connections:

    • Connect Motor A to OUT1 and OUT2.
    • Connect Motor B to OUT3 and OUT4.
  3. Control Connections:

    • Connect IN1, IN2, IN3, and IN4 to the microcontroller's digital pins.
    • Connect ENA and ENB to PWM-capable pins on the microcontroller for speed control.
  4. Logic Power:

    • If the 5V-EN jumper is removed, provide 5V to the 5V pin from an external source (e.g., Arduino).

Example Arduino Code

Below is an example of how to control two DC motors using the L298N and an Arduino UNO:

// Define motor control pins
const int IN1 = 7;  // Motor A direction pin 1
const int IN2 = 6;  // Motor A direction pin 2
const int ENA = 5;  // Motor A speed control (PWM)

const int IN3 = 4;  // Motor B direction pin 1
const int IN4 = 3;  // Motor B direction pin 2
const int ENB = 2;  // Motor B speed control (PWM)

void setup() {
  // Set motor control pins as outputs
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(ENA, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
  pinMode(ENB, OUTPUT);
}

void loop() {
  // Motor A: Forward at 50% speed
  digitalWrite(IN1, HIGH);  // Set IN1 high
  digitalWrite(IN2, LOW);   // Set IN2 low
  analogWrite(ENA, 128);    // Set speed to 50% (128 out of 255)

  // Motor B: Backward at 75% speed
  digitalWrite(IN3, LOW);   // Set IN3 low
  digitalWrite(IN4, HIGH);  // Set IN4 high
  analogWrite(ENB, 192);    // Set speed to 75% (192 out of 255)

  delay(2000);  // Run motors for 2 seconds

  // Stop both motors
  analogWrite(ENA, 0);      // Stop Motor A
  analogWrite(ENB, 0);      // Stop Motor B

  delay(2000);  // Wait for 2 seconds
}

Important Considerations and Best Practices

Troubleshooting and FAQs

Common Issues and Solutions

  1. Motors Not Running:

    • Check power connections and ensure the external power supply is sufficient.
    • Verify that the control pins (IN1, IN2, etc.) are receiving the correct signals.
  2. Motors Running in the Wrong Direction:

    • Swap the connections of IN1 and IN2 (or IN3 and IN4) to reverse the motor direction.
  3. Overheating:

    • Ensure the module has adequate heat dissipation (e.g., heat sink or fan).
    • Reduce the motor load or use motors with lower current requirements.
  4. No 5V Output:

    • Check if the 5V-EN jumper is in place. If removed, provide an external 5V supply.

FAQs