how to use the L298 Motor Driver Module
- Get link
- X
- Other Apps
L298 Motor Driver Module
Introduction
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 micro-controller requiring just a couple of control lines per motor.
It is ideal for robotic applications and well suited for connection to a micro-controller requiring just a couple of control lines per motor.
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:
|
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.
The code::
***************************************************************************
//L293D
//Motor A
const int motorPin1 = 5; // Pin 14 of L293
const int motorPin2 = 6; // Pin 10 of L293
//Motor B
const int motorPin3 = 10; // Pin 7 of L293
const int motorPin4 = 9; // 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.
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(2000);
//This code will turn Motor A counter-clockwise for 2 sec.
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(2000);
//This code will turn Motor B clockwise for 2 sec.
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
delay(2000);
//This code will turn Motor B counter-clockwise for 2 sec.
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
delay(2000);
//And this code will stop motors
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
}
void loop(){
}
***************************************************************************
Note :: For example try to combine parts of code to move both motors simultaneously.
Try to use analogWrite(pin, PWM value) instead digitalWrite(pin, HIGH/LOW) 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. |
- Get link
- X
- Other Apps
Comments
Post a Comment