Min menu

Pages

project 26 :Control using L298N Motor Driver

 

Arduino DC Motor Control using L298N Motor Driver


In this project, we will see how to control a DC Motor using Arduino and L298N Motor Driver. There are different ways to control a DC Motor but the Arduino DC Motor Control using L298N Motor Driver is becoming quite popular for many reasons.

Speed Control of DC Motor using PWM

Using PWM technique, the average value of the voltage that is applied to the DC Motor is controlled by turning the power on and off at a very high rate. The frequency of this switching will be in the order of few tens of kilo Hertz.
Now, the average voltage applied to the DC Motor will depend on what is called as the Duty Cycle of the PWM Signal. Duty Cycle of a PWM Signal is nothing but the ratio of the time for which the signal is ON or HIGH to the total time period of the signal i.e. sum of ON time and OFF time.

Code

int PWMPin = 10;
int motorSpeed = 0
void setup()
{
}
void loop()
{
for (motorSpeed = 0 ; motorSpeed <= 255; motorSpeed += 10)
{
analogWrite(PWMPin, motorSpeed);
delay(30);
}
for (motorSpeed = 255 ; motorSpeed >= 0; motorSpeed -= 10)
{
analogWrite(PWMPin, motorSpeed);
delay(30);
}
}
reaction: