Ardumotive Arduino Greek Playground
  • Home
    • About us
    • Contact
    • License
  • Arduino
    • Tutorials
    • Workshop
  • Raspberry Pi
  • DIY 3D Printer
  • News
    • Events >
      • Unboxing & Review
    • Blog
The 1st Arduino Playground in Greece - Open Source Hardware

L298 Motor Driver Module

Available Languages
Greek
English
*Σύντομα και στα Ελληνικά

Introduction 

Picture
This dual bidirectional motor driver is based on the very popular L298 Dual H-Bridge Motor Driver IC. This module will allow you to easily and independently control two motors of up to 2A each in both directions.

It is ideal for robotic applications and well suited for connection to a microcontroller requiring just a couple of control lines per motor.

​BUY L298N module from here! Free Shipping! 
In this tutorial you will learn how to use it with Arduino uno to control two dc motors.

What you will need - Hardware

For this tutorial you will need:
  • Arduino uno
  • Breadboard
  • L298 Module
  • 2x DC motors
Picture

The Circuit

The connections are pretty easy!

  • Module 5V (or Vcc) - Arduino 5V pin
  • Module GND - Arduino GND pin
  • Module 12V (or Vbat) - To external power source up to 35V.  For this tutorial just connect it with Arduino Vin pin.
  • Module output 1 & 2 - Connect dc motor A
  • Module output 3 & 4 - Connect dc motor B
  • Module IN1 - Arduino pin 5
  • Module IN2 - Arduino pin 6
  • Module IN3 - Arduino pin 10
  • Module IN4 - Arduino pin 9

The code 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//L293D
//Motor A
const int motorPin1  = 9;  // Pin 14 of L293
const int motorPin2  = 10;  // Pin 10 of L293
//Motor B
const int motorPin3  = 6; // Pin  7 of L293
const int motorPin4  = 5;  // Pin  2 of L293

//This will run only one time.
void setup(){
    //Set pins as outputs
    pinMode(motorPin1, OUTPUT);
    pinMode(motorPin2, OUTPUT);
    pinMode(motorPin3, OUTPUT);
    pinMode(motorPin4, OUTPUT);
    //Motor Control - Motor A: motorPin1,motorpin2 & Motor B: motorpin3,motorpin4
    //This code  will turn Motor A clockwise for 2 sec.
    analogWrite(motorPin1, 180);
    analogWrite(motorPin2, 0);
    analogWrite(motorPin3, 180);
    analogWrite(motorPin4, 0);
    delay(5000); 
    //This code will turn Motor A counter-clockwise for 2 sec.
    analogWrite(motorPin1, 0);
    analogWrite(motorPin2, 180);
    analogWrite(motorPin3, 0);
    analogWrite(motorPin4, 180);
    delay(5000);
    //This code will turn Motor B clockwise for 2 sec.
    analogWrite(motorPin1, 0);
    analogWrite(motorPin2, 180);
    analogWrite(motorPin3, 180);
    analogWrite(motorPin4, 0);
    delay(1000); 
    //This code will turn Motor B counter-clockwise for 2 sec.
    analogWrite(motorPin1, 180);
    analogWrite(motorPin2, 0);
    analogWrite(motorPin3, 0);
    analogWrite(motorPin4, 180);
    delay(1000);    
    //And this code will stop motors
    analogWrite(motorPin1, 0);
    analogWrite(motorPin2, 0);
    analogWrite(motorPin3, 0);
    analogWrite(motorPin4, 0); 
}
void loop(){
}
Download the code from here and open it with Arduino IDE.
l298_tutorial.zip
File Size: 0 kb
File Type: zip
Download File

You can keep playing with that, for example try to combine parts of code to move both motors simultaneously. Change PWM value to control the speed of motors.

Well done!

You have successfully completed one more Arduino "How to" tutorial and you learned how to use the L298 motor driver IC module to control two dc motors with the Arduino uno board.

I hope you liked this, let me know in the comments.
Picture

Search Engine

Picture

Licence 

Picture

Help us to grow up!

Picture


Donate us
About us
License
Cookies policy

Visit the biggest Arduino Shop in Greece!

Picture
find us on dwrean.net
find us on Codebender
find us on Instructables
Developed and designed by Vasilakis Michalis Copyright © 2013 Ardumotive All Rights Reserved
All trademarks referenced herein are properties of their
Powered by Create your own unique website with customizable templates.
Design by DivTag Templates