0% found this document useful (0 votes)
8 views10 pages

L298N Motor Control Guide

This document describes how to use an L298N controller to control different types of motors, including DC motors, stepper motors, and how to vary the speed of a DC motor. It explains the necessary connections, the Arduino code, and the characteristics of the controller such as its maximum current and input voltage.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views10 pages

L298N Motor Control Guide

This document describes how to use an L298N controller to control different types of motors, including DC motors, stepper motors, and how to vary the speed of a DC motor. It explains the necessary connections, the Arduino code, and the characteristics of the controller such as its maximum current and input voltage.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

[Link].

com

Bridge Report H
L298N

1
[Link]

Index
Description........................................................................................................................................ 3
Characteristics .................................................................................................................................. 5
DC Motor Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Connectionn........................................................................................................................................ 6
Codeo ............................................................................................................................................ 6
Control of a DC Motor by varying its speedd ........................................................................... 7
Connectionn........................................................................................................................................ 7
Codeo ............................................................................................................................................ 8
Control of a Bipolar Stepper Motor.................................................................................... 9
Connectionn........................................................................................................................................ 9
Codeo 10

2
[Link]

Description
The L298N driver is a device that can control the direction and speed of
operation of motors at a current output per channel of up to 2 [A]. This driver
It features a heat sink suitable for its characteristics, which can work up to
an input voltage of 46 [V], for safety it is recommended to use voltage levels
something below this limit value. The H L298N bridge can be used to drive motors
step by step of two phases (unipolar) or four phases (bipolar), or two DC motors
continuation (DC motors). This driver includes a 78M05 voltage regulator of 5 [V] that is
it should be used to regulate an input voltage of up to 12 [V], for input voltages
above 12 [V] it is recommended to disable the regulator jumper and power the logic part
of the module with an external power source of 5 [V]. This driver has a great filtering capacity of
noise, in addition to having a protection diode against reverse current, causing that
its operation is more stable and safe.

3
[Link]

There are two ways to power this module:

1.- Using a single power supply connected to the Vin input (or 12V pin) and with
the regulator jumper installed to enable the regulator, clarifying that the voltage of the
source is what is sent to the engine. In this way, the logical V input or the 5V pin should not
to be connected to any source (no input voltage), but this can be used
pin as a 5V output, but without exceeding 500mA of consumption. It is recommended to make
this connection is for power supply voltages below 12V to avoid overheating the
regulator.

2.- Using two power supplies, one of 5V connected to the logical V input.
5V (it can be the 5V from an Arduino) and another power supply with the voltage value
that works the motor, connected to the Vin pin (or 12V pin). For this, it needs to be disconnected.
Or remove the regulator jumper, which will disable the voltage regulator.

+12V...+46V
Regulator jumper activated Regulator Jumper Disabled

For the control of the module, it is necessary to:

The ENA, IN1, IN2 pins correspond to the inputs for controlling MOTOR A (OUT1
y OUT2).

Similarly, ENB, IN3, IN4 allow control of MOTOR B (OUT3 and OUT4).

ENA and ENB are used to enable or disable their respective motors, generally they
They are used to control the speed, inputting a PWM signal through these pins. If not
The activation jumpers must be connected so that they are always enabled.

4
[Link]

Characteristics
L298N Controller/ Double H Bridge.
Power supply voltage: 5V ~ 46V.
Maximum current: 2A per channel.
Motor control voltage (with regulator activated): 5V ~ 12V.
Current consumption (logic): 0 to 36mA.
25W
Power indicator light.
Operating temperature: -25°C to +135°C.

Important:
If the regulator jumper is installed (activated), the voltage regulator will be activated.
from the L298N, and in logical V we will have an output of 5V, which can be used for whatever you deem necessary
convenient, for example, to power an Arduino board (it is recommended that the
the consumption should not exceed 500mA). Also, when the 5V regulator jumper is present
activated, the module allows a power supply of between 6V to 12V DC at Vin (since
the regulator only works with voltages of up to 12V), above this value we will have
to remove the regulator jumper and power the logic part of the module from another source with
5V.

Be careful if voltage is introduced through the logic V with the regulator jumper.
installed, as it could damage the module.

If the regulator jumper is removed, the regulator will be deactivated, and it will be necessary to power the
logical part of the module, so a voltage of 5V must be applied through the V connection.
logical for the module to work.

DC Motor Control
A DC motor will be controlled through output B of the L298N H Bridge module. The pin ENB
it will connect to the activation jumper at +5V, that is, with the activation jumper
installed.

The example is developed in Arduino UNO, but the code is compatible.


with any other Arduino model.

5
[Link]

Connection

Code

The program basically activates the motor in one direction for 1 second, then stops it.
motor for 0.5 seconds, then activate the motor in the reverse direction for 1 second and for
last stops the engine for 0.5 seconds, doing this infinitely many times.

intIN3=5;
intIN4=4;

void setup()
{
pinMode(IN4,OUTPUT);// Input4 connected to pin 4
pinMode(IN3,OUTPUT);// Input3 connected to pin 5
}
voidloop()
{
Motor rotates in one direction
digitalWrite(IN4,HIGH);
digitalWrite(IN3, LOW);

6
[Link]

delay(1000);
The motor does not turn
digitalWrite(IN4, LOW);
digitalWrite(IN3, LOW);
delay(500);
Motor rotates in the opposite direction
digitalWrite(IN4,LOW);
digitalWrite(IN3,HIGH);
delay(1000);
Motor does not turn
digitalWrite(IN4,HIGH);
digitalWrite(IN3, HIGH);
delay(500);
}

Control of a DC Motor by varying its speed


To control the speed of the motor, PWM must be used. This PWM signal
will be applied to the activation pins of each output or pins ENA and ENB, respectively,
Therefore, the activation jumpers of the motors must be removed.

Connection

7
[Link]

Code

The program controls the speed of a DC motor by applying PWM to the ENB pin of the module.
L298N.

intIN3=5;// Input3 connected to pin 5


intIN4=4;// Input4 connected to pin 4
intENB=3;// ENB connected to pin 3 of Arduino
void setup()
{
setPinMode(ENB, OUTPUT);
pinMode(IN3, OUTPUT);
set pin mode of IN4 to OUTPUT
}
voidloop()
{
We prepare the output so that the motor turns in one direction
digitalWrite(IN3,HIGH);
digitalWrite(IN4, LOW);
We apply PWM to the ENB pin, making the motor rotate every 2 seconds.
increase the speed
analogWrite(ENB,55);
delay(2000);
analogWrite(ENB,128);
delay(2000);
analogWrite(ENB,255);
delay(2000);
We turn off the engine and wait 2 seconds
analogWrite(ENB,0);
delay(2000);
We prepare the output for the motor to rotate in reverse direction.
digitalWrite(IN3, LOW);
digitalWrite(IN4,HIGH);
We apply PWM to the ENB pin, rotating the motor every 2 seconds.
decrease the speed
analogWrite(ENB,255);
delay(2000);
analogWrite(ENB,128);
delay(2000);
analogWrite(ENB,55);
delay(2000);
We turn off the engine and wait 5 seconds.
analogWrite(ENB,0);
delay(2000);
}

8
[Link]

Control of a Bipolar Stepper Motor


Stepper motors can be unipolar or bipolar. In this example, we will
work with a bipolar stepper motor, knowing that the maximum permitted consumption is
of 2 [A].

Connection

The wiring diagram shows the connection used between the L298N module and the motor.
step by step. Each of the motor coils is connected to a motor output of the
module. To identify the coils of a stepper motor, a tester is used in mode
of continuity. The wires that provide continuity are the ends of each coil and must
be connected to the same engine output, that is, one end of the coil must be
connected to the output of motor A and the other end of the coil must be connected to the output
of motor B.

9
[Link]

Code

The Arduino code makes the stepper motor rotate one turn in one direction and then
execute another turn in the opposite direction. This code makes use of the library 'Stepper.h', which
It is installed by default in the latest versions of the Arduino IDE.

The value of the variable stepsPerRevolution depends on the number of steps of the stepper motor.
step. This value is found in the specifications of the engine data sheet
In this case, the stepper motor used has 48 steps/revolution.

#include<Stepper.h>

const int stepsPerRevolution = 48; // change this value to the number of


steps of its engine

// initializes the 'stepper' library on pins 8 to 11


Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {
sets the speed to 60rpm
[Link](60);
// initialize the serial port
[Link](9600);
}

voidloop() {
turn in one direction
clockwise
[Link](stepsPerRevolution);
delay(500);

turn around in the other direction


counterclockwise
[Link](-stepsPerRevolution);
delay(500);
}

10

You might also like