Contents

Interfacing L298N Motor Driver Module with Arduino

L298N Motor Driver Module Features

The L298N module is used to drive DC motors with a maximum current of 2 amps. The L298N driver module is easy to use. It contains a good filter circuit and gives you access access to inputs and outputs via pin headers and terminals.

The L298N is a dual full-bridge motor driver that allows two DC motors to be connected simultaneously.

Note
The L298N motor controller follows the H-bridge configuration, which is handy to drive a stepper motors.

This driver needs a logic voltage supply to drive the motors, which uses a 5-volt regulator to solve the logic voltage supply problem. This module features:

  • Max operating voltage: 46 V DC
  • Max output current: 2 A (Peak 3 A)
  • Power: 25 W
  • Input voltage level: 5 V
  • Working temperature: -25 to 130 Celsius
Note

If the load on the motor is high, the driver temperature will rise rapidly. S Since the working temperature of the L298N is between -25 and 130 degrees Celsius, heatsink should be used to cool down the module.

You can download the datasheet of this module here.

L298N Motor Driver Module Pinout

This sensor has 10 pins:

  • VMS: Motor power supply (input)
  • GND: Ground
  • +5V: Module power supply – 5 V (output)
  • ENA: Activator for channel A
  • ENB: Activator for channel B
  • IN1: Input 1 (5 V)
  • IN2: Input 2 (5V)
  • IN3: Input 3 (5V)
  • IN4: Input 4 (5V)
  • OUT1: Output 1
  • OUT2: Output 2
  • OUT3: Output 3
  • OUT4: Output 4

You can see pinout of this module in the image below.

Required Materials

Hardware Components

Arduino UNO R3 × 1
L298N Dual H-Bridge Motor Driver × 1
DC Gear Motor × 1
Male to Male jumper wire × 1
9v Battery × 1

Software Apps

Arduino IDE

Interfacing L298N Motor Driver Module with Arduino

Step 1: Circuit

The following circuit shows how you should connect Arduino to L298N  module. Connect wires accordingly.

Step 2: Code

Upload the following code to your Arduino.
/*
  L298N HW-094 DC MOTOR DRIVER MODULE
  modified on 25 Sep 2020
  by Saeed Olfat @ Electropeak
  
Home
*/ void setup() { pinMode(8, OUTPUT); //IN2 pinMode(9, OUTPUT); //IN1 pinMode(10, OUTPUT); //Enable Pin } void loop() { // Full speed forward digitalWrite(8, HIGH); digitalWrite(9, LOW); digitalWrite(10, HIGH); delay(3000); // Full speed backward digitalWrite(8, LOW); digitalWrite(9, HIGH); digitalWrite(10, HIGH); delay(3000); // 0 to 100% speed in forward mode for (int i=0;i<256;i++) { digitalWrite(8, HIGH); digitalWrite(9, LOW); analogWrite(10, i); delay(20); } delay(50); // 0 to 100% speed in backward mode for (int i=0;i<256;i++) { digitalWrite(8, LOW); digitalWrite(9, HIGH); analogWrite(10, i); delay(20); } delay(50); }

As you can see in the code, the motor first moves forward for 3 seconds and backward for 3 seconds. Then the motor stops and its speed increases from 0 to 100% in the forward direction with constant acceleration, and then the same movement is done in reverse.

Liked What You See?​
Get Updates And Learn From The Best​

Comments (2)

  • oveas Reply

    Hello. I built the circuit as you said and set it up with the same code. But my DC motor did not work. After that, I connected the motor pins directly to the VMS and GND ports and the motor worked. Is there a problem with my board?
    my Supply: 9V-1A

    September 27, 2023 at 9:33 am
    • Mohammad Damirchi Reply

      Hi oveas,
      did you connect the GND pins of all components together?

      September 30, 2023 at 1:42 pm

Leave a Reply

Your email address will not be published. Required fields are marked *