INTERFACE L298N MOTOR DRIVER MODULE WITH ARDUINO UNO

INTERFACE L298N MOTOR DRIVER  MODULE INTO ARDUINO UNO

INTERFACE L298N MOTOR DRIVER  MODULE WITH ARDUINO UNO


In this tutorial, we will know about L298N motor driver module. What is l298n motor driver module?Why use l298n motor driver module? and learn how to interface motor driver module with Arduino board?. If you want to build a robot then you must definitely know the l298n motor driver module.
It is a two common technique for controlling speed and rotation direction of dc motor. 

1.PWM(Pulse Width Modulation)
2.H-Bridge

PWM:- Speed control of dc motor can be done with PWM technique. While the average voltage of the operating voltage of dc motor is adjusted with sending series of ON-OFF pulses. The average voltage of prepositional to the width of pulses knows as duty cycle.
When duty cycle is higher then the speed of dc motor is higher. And when duty cycle is lower then the speed of dc motor is lower. In this way control the speed of dc motor with PWM technique.
Pulse Width Modulation(PWM)


H-Bridge:- H-bridge can be control spinning rotation direction of dc motor. It can be changed the polarity of it's input voltage. H-bridge circuit have four mosfet or transistor as switches  with motor this like arrangement H type.

When logic gate switch 1 and logic gate switch 4 will on and switch 2 and switch 3 will OFF at the same time ,then the current will flow left to right side of dc motor so dc motor will run forward direction.
H-Bridge Technique for forward direction dc Motor


When logic gate switch 1 and logic gate switch 4 will OFF and switch 2 and switch 3 will ON at the same time ,then the current will flow right to left side of dc motor so dc motor will run reverse  direction.
H-Bridge Technique for reverse direction dc Motor




What is L298N motor driver module ?

L298N motor driver module


L298N motor driver is a high power dc motor driver module for control dc motor and stepper motor. It has single dual H-bridge channel ic and 78M05 5v regulator ic in module. This module have two output terminals for control two dc motors or 4 dc motors  . That is why this module can capable two dc motors separately with direction and speed control of dc motor.

Pin Out of the L298N motor driver module

Pin Out of the L293D motor driver module


L298N motor driver chip  - L298N motor driver ic is high power dc motor control dual H-bridge channel. It's means you can control 2 dc motor or 4 dc motor with spinning direction and speed control of dc motor separately.

12V DC power supply pin  - It is a external input dc power supply for operate dc motor.

5V DC power supply pin  - It is 5V dc power supply for activate logic gate circuit inside the L298n ic.

5V Jumper pin  - You can enable or disable logic gate circuit of dual H-bridge logic gate circuit of l298n ic by the 5v jumper pin. When 5v jumper pin placed, then the 5v supply provide for activate logic gate circuit. And when 5v jumper pin removed ,  then 5v supply is not provide for activate logic gate circuit.

GND  - Ground pin is common pin.   

IN1,IN2 & IN3,IN4  - IN1, IN2 and IN3, IN4 are input pins to control direction of two dc motor A and dc motor B.

ENA & ENB  - Enable A pin is used to PWM signal for speed control of dc motor A. Enable B pin is used to PWM signal for speed control of dc motor B.

Feature:-

  • It has a dual H- bridge channel IC.
  • It can working voltage 5V to 35V dc.
  • It can capable 46V operating voltage for dc motor.
  • It can be controlled 2A amp for driver current.
  • It can control  maximum power 25 watt.

Application:-

  • DC motor control.
  • Stepper motor control.
  • robots etc.

How does it work ?

We known that l298n motor driver is dual H- bridge channel module. This module can control the two dc motor with direction and speed of dc motor separately. There are 4 inputs pins IN1, IN2 and IN3, IN4 for spinning direction control of dc motor A and dc motor B. And there are 2 enable pins ENA and ENB for speed control of dc motor A and dc motor B. All inputs pins in1, in2 and in3, in4 are connected to digital pins of micro controller. When micro controller high signal provided to in1 pin and low signal provided to in2 and high signal provided to in3 and low signal provided to in4 of l298n motor driver module. Then motor A and Motor B is run forward direction. And when micro controller low signal provided to all inputs pin in1, in2 & in3, in4 then motor A and motor B is stopped.
Show in below..
IN1  IN2  IN3  IN4  DIRECTION
 0      0      0     0        Stop
 1      0      1     0        Forward
 0      1      0     1        Reverse
 1      0      0     1        Left
 0      1      1     0        Right

Component required:-

  1. Arduino Uno.
  2. L298N Motor driver module.
  3. Two dc motor.
  4. 12v dc power supply.
  5. Male and female jumper wire.

Schematics diagram:-

It,s a schematics of l298n motor driver with Arduino Uno. How we have connected digital input pins of l298n motor driver module with digital pins of Arduino.Shown in below. 
schematics diagram of l298n motor driver module with arduino uno


Circuit Diagram:-

Circuit diagram of l298n motor driver module with arduino uno
This is a circuit diagram of l298n motor driver with Arduino uno board. That's connection is very simple.Firstly we have  connected Vcc pin of l298n driver module to 12v battery and gnd pin of l298n motor driver module is connected to all gnd pin of 12v battery and Arduino uno. 5v pin of l298n motor driver module is connected to Vin pin (input voltage pin) of Arduino uno. Here we have connected pair of dc motor in pair of dc motor output pins of l298n motor driver module.  And ENA (enable pin) is connected to D7 of Arduino and IN1 and IN2 (input pin) are connected to D6 and D5 of Arduino. And also ENB (enable pin) is connected to D2 of Arduino and IN3 and IN4 (input pin) are connected to D3 and D4 of Arduino. 
  


Interface l298n motor driver module with Arduino uno

L298N  - Arduino Uno

ENA    - D7
IN1      - D6
IN2      - D5

ENB    - D2
IN3      - D4
IN4      - D3

GND    -GND

5V       -Vin

12V  - From the 12v battery

Code:-

//Motor A connection
int enA  = 7;
int in1   = 6;
int in2   = 5;

//Motor B connection
int in3   = 4;
int in4   = 3;
int enB = 2;

void setup()
{
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);

pinMode(enB, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);

digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);

}
void loop()
{
analogWrite(enA, 255);
analogWrite(enB, 255);

//Motor A and Motor B will rotated forward direction
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
delay(5000);
//Motor A and Motor B will rotated reverse direction
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
delay(5000);

//Turn ON both motor A and motor B
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);

//Increasing 0 speed to maximum speed
for(int i=0; i<256; i++)
{
analogWrite(i, enA);
analogWrite(i, enB);
delay(50);
}

//Decreasing maximum speed to 0 speed
for(int i=255; i>0; i--)
{
analogWrite(i, enA);
analogWrite(i, enB);
delay(50);
}
//Stop both motor A and motor B
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
delay(5000);
}

Post a Comment

0 Comments