Back to Step by Step Course by Robojax

Lesson 53: Using L298N Motor Driver for DC Motor Control | Arduino Step By Step Course

Please select other codes for this lecture from the links below.

Related or required files and link to this lesson

Part 5: DC Motors

In this lesson we learn how to contorl a DC motor using L298N Motor driver module and Arduino .
Please watch the video for full details.

  • 00:00 Introduction
  • 09:13 Wiring Explained
  • 13;24 Code Explained
  • 24:12 Wiring for parallel connection
  • 27:38 Demonstration of parallel driver
AliExpress.com Product - 1pcs L298N MOTOR DRIVER module New Dual H Bridge DC Stepper Motor Drive Controller Board Module

  /*
Lesson 53: Using L298N Motor Driver for DC Motor Control
Watch full detailed Video https://youtu.be/fqBLIrwq2YA

 * Library Example for L298N Module to control DC motors
 * 
 * This code is to control single motor. For two motor control, please open L298N_DC_2_Motors
 P
 * 
 * Written by Ahmad Shamshiri on October 01, 2019 at 21:26 
 * in Ajax, Ontario, Canada. www.robojax.com
 * 
 * 
 * Watch video instruction for this code:
 * 

If you found this tutorial helpful, please support me so I can continue creating 
content like this. You can support me on Patreon http://robojax.com/L/?id=63

or make donation using PayPal http://robojax.com/L/?id=64

 *  * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.* 
 * This code has been download from Robojax.com
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

#include <Robojax_L298N_DC_motor.h>
// motor 1 settings
#define IN1 6
#define IN2 7
#define ENA 8 // this pin must be PWM enabled pin
const int CCW = 2; // do not change
const int CW  = 1; // do not change
#define motor1 1 // do not change
// use the line below for single motor
Robojax_L298N_DC_motor motor(IN1, IN2, ENA, true);


void setup() {
  Serial.begin(115200);
  motor.begin();
  //L298N DC Motor by Robojax.com

}

void loop() {
  
  motor.demo(1);
  motor.rotate(motor1, 60, CW);//run motor1 at 60% speed in CW direction
 
  delay(3000);

  motor.brake(1);
  delay(2000);


  motor.rotate(motor1, 100, CW);//run motor1 at 60% speed in CW direction
  delay(3000);

  motor.brake(1);
  delay(2000);  

  for(int i=0; i<=100; i++)
  {
    motor.rotate(motor1, i, CW);// turn motor1 with i% speed in CW direction (whatever is i) 
    delay(100);
  }
  delay(2000);
  
  motor.brake(1);
  delay(2000);  

  motor.rotate(motor1, 70, CCW);//run motor1 at 70% speed in CCW direction
  delay(4000);

  motor.brake(1);
  delay(2000);    
  
}



   

The least I expect from you is to give the video a thumbs up and subscribe to my channel. I appreciate it. I have spent hundreds of hours making these lectures and writing code. You don't lose anything by subscribing to my channel. Your subscription is a stamp of approval for my videos, helping more people find them and, in turn, helping me. Thank you!

If you found this tutorial helpful, please support me so I can continue creating content like this. support me via PayPal

**** AFFILIATE PROGRAM **** We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to Amazon.com and affiliated sites.

Right Side
footer