Documente Academic
Documente Profesional
Documente Cultură
Table of Contents
Overview
Speed Control of DC Motor using PWM
o Code
DC Motor Control using H-Bridge
A Brief Note on L298N Motor Driver
Arduino DC Motor Control using L298N
o Circuit Diagram
o Components Required
o Code
Applications
Overview
A DC Motor is the simplest of motors that beginners and hobbyists
encounter. It is very simple to operate: connect the two leads of the motor
to the two terminals of a battery and voila! Your motor starts rotating.
If you switch the leads i.e. reverse the polarity, the motor will rotate in
reverse direction. It is as simple as that.
If you want to control the speed of rotation of a simple DC Motor, then there
is a technique called PWM DC Motor Control. The Pulse Width Modulation
or PWM signal generated by this technique will allow us to control the
average voltage that is being delivered to the DC Motor.
The PWM Signal from any source like Arduino in this example, can be
given to the gate of a MOSFET and depending on the duty cycle of the
PWM Signal, the speed of the DC Motor will vary.
The following image shows a simple circuit diagram, where a PWM output
from Arduino is given to a MOSFET and the 12V DC Motor is connected
through the MOSFET.
The code for this circuit is given below. Using this code, the Arduino will
vary the speed of a DC Motor in a fading fashion i.e. gradually increases
the speed to peak and then gradually decreases the speed to halt.
Code
int motorSpeed = 0
void setup()
{
void loop()
{
This circuit is good for controlling the speed of the motor but not an
effective way to change the direction of rotation. For changing the direction
of rotation without reversing the leads of the motor every time, you need to
use a special circuit called H-Bridge.
DC Motor Control using H-Bridge
An H-Bridge is a simple electronic circuit consisting of four switching
elements like transistors (BJT or MOSFET) that can drive a motor in both
the directions without switching the leads.
The name “H-Bridge” refers to the look of the connection consisting of four
transistors and a motor in the center forming the letter “H”.
By combining both the features i.e. PWM technique for speed control and
H-Bridge connection for direction control, you can have a complete control
on a DC Motor.
The following image shows the Pin Diagram of the L298N IC in Multiwatt
Package (Multi Leaded Power Package).
Since the L298N Motor Driver IC is a dual full bridge driver IC, you can
control two motors at the same time with individual inputs. The logic supply
voltage is 5V but the motor supply voltage can be as high as 45V. The
peak output current per channel is 2A.
There is a 3-pin screw terminal block through which you need to give the
supply voltage to the motor. If the motors used are rated for 12V or less,
then the 12V supply is given through this screw terminal and the onboard
5V regulator will provide the 5V logic supply to the L298N IC.
You can also access this regulated 5V through the third pin in the 3-pin
screw terminal block. The jumper provided near the 3-pin screw terminal
must be engaged for supply voltages up to 12V as this jumper will enable
the onboard regulator. The 5V output from the third pin of the 3-pin screw
terminal is available only when the jumper is engaged i.e. supply voltage is
12V. This 5V output can be used to power your Arduino Board.
If the supply voltage is greater than 12V, then remove the jumper as it
might damage the regulator. In this case, the logic supply of 5V to the
L298N IC is given through the third pin of the 3-pin screw terminal.
Circuit Diagram
Components Required
Code
int mot1 = 8;
int mot2 = 9;
int en1 = 10;
int dir = 6;
bool state = true;
int nob = A0;
int val=0;
void setup()
{
pinMode(mot1,OUTPUT);
pinMode(mot2,OUTPUT);
pinMode(en1,OUTPUT);
pinMode(dir,INPUT_PULLUP);
void loop()
{
val = analogRead(nob);
if(digitalRead(dir)==LOW)
{
state=!state;
while(dir==LOW);
delay(300);
}
if(state)
{
digitalWrite(mot1,HIGH);
digitalWrite(mot2,LOW);
}
else
{
digitalWrite(mot1,LOW);
digitalWrite(mot2,HIGH);
}
Applications
Arduino DC Motor Control using L298N Motor Driver project can be
the beginning step of many advanced projects.
Almost all robots have wheels and we need to control the motors
connected to those wheels. Hence, any Arduino based robot can
implement this type of motor control using L298N.
Some of the Robotic Applications of L298N Motor Driver are Hand
Gesture Controlled Robot, Line Follower Robot, Obstacle Avoiding
Robot, etc.