arduino l298 dual dc motor shield - techshopbd · this motor drive shield sits right on arduino...
TRANSCRIPT
ARDUINO L298 DUAL DC MOTOR SHIELD
This motor drive shield sits right on Arduino Uno/
Mega/ Leonardo and allows driving two DC motors.
It uses a SMD L298P motor driver IC. Motor
speed control is achieved by conventional PWM
which can be obtained from Arduino’s PWM output
Pins. The enable/disable function of the L298P IC is
controlled by an Enable switch placed on this shield.
Motor direction indicating LEDs give visual signal
of how the arduino controls the motors and eases
programming. There’re also three power rails on this
shield that makes it a small power distribution board.
You can attach other Arduino shields (that doesn’t
use Arduino pins 2-7) on top of it.
• Up to 2 DC motors can be controlled
• Logic Control Voltage:5V (From Arduino).
• Motor Driven Voltage:4.8~35V (From
Arduino or External Power Source).
• Logic supply current:≤36mA.
• Motor Driven current:≤2A (per motor).
• Maximum power consumption:25W(T=75℃).
• Arduino pins needed for motor control: 6 (3 for
each motor)
• Option to Enable/ Disable motor driver
• 4 LEDs for indicating direction of motor
rotation.
• 3 sets of power rails for Vin, 5V and GND
A Closer Look at the Shield Motor Connectors: Terminal block
connectors for attaching DC motors. Connect
two wires of your DC motor to OUT1 &
OUT2. Two wires of another DC motor can
be connected to OUT3 & OUT4.
Arduino Vin Jumper pins: Lets you
short Arduino Vin pin & L298 VIN pin and
power up the motors from Arduino Vin
(barrel connector). Never put a jumper here if
you are about to connect separate voltage
sources to L298 voltage input port and
Arduino Vin pin (or barrel connector) as it’ll
short them.
L298 Voltage Input: For providing supply
voltage to the motors using wires. If you are
using separate power sources for the Arduino
and the motors, connect both VIN and GND.
Enable LED & Enable Switch: to
enable/ disable the L298 IC. The LED shows
Enable/Disable status. When disabled, even if
supply voltage source is connected, the
motors won’t run.
Direction Indicator LEDs: Indicates
direction of motor rotation.
Power Rails: 3 sets of power rails for Vin,
5V and GND. Note that they are OUTPUT
pins. Don’t provide any input voltage to
these pins.
METHOD 1
1. Short Arduino Vin and L298 Vin with
a computer jumper.
2. Connect your power source to Arduino
barrel connector. This will power up
both the Arduino and the L298 IC.
3. Don’t connect any other power source
to blue VIN port of the shield.
4. Connect only small motors (that draws
a small amount of current) like this or
this or Pololu micro metal gear motors
if using this method.
Providing Power to Arduino & Motors
1
2
3
4 4
METHOD 2
1. Short Arduino Vin and L298 Vin with a
computer jumper.
2. Connect your power source to the blue
VIN port of the shield. This will power
up both the Arduino and the L298 IC.
3. Don’t connect any other power source to
Arduino barrel connector or Arduino
Vin pin.
4. You can connect comparatively big
motors (that draws up to 2A current)
like this if using this method.
1
2
3
METHOD 3
1. Follow this method only if you want to provide separate power sources to Arduino and L298.
2. Connect your power source for motors to the blue VIN port of the shield.
3. Connect the other power source for Arduino to Arduino barrel connector or Arduino Vin pin.
4. Never put a jumper on Arduino Vin Jumper pins if following this method as it will short your power sources.
#define in1 7
#define ena 6
#define in2 5
#define in3 4
#define enb 3
#define in4 2
void setup()
{
pinMode(in1,OUTPUT);
pinMode(in2,OUTPUT);
pinMode(in3,OUTPUT);
pinMode(in4,OUTPUT);
pinMode(ena,OUTPUT);
pinMode(enb,OUTPUT);
}
void loop()
{
// both motors run at full speed
digitalWrite(in1,HIGH);
digitalWrite(in2,LOW);
analogWrite(ena, 255);
digitalWrite(in3,HIGH);
digitalWrite(in4,LOW);
analogWrite(enb, 255);
delay(2000);
// both motors run in reverse direction at half speed
digitalWrite(in2,HIGH);
digitalWrite(in1,LOW);
analogWrite(ena, 120);
digitalWrite(in4,HIGH);
digitalWrite(in3,LOW);
analogWrite(enb, 120);
delay(2000);
}
Contact [email protected] if you
have any query, complain or development suggestion
about this product.
Arduino pin L298 Pin
2 IN4
3 ENB
4 IN3
5 IN2
6 ENA
7 IN1
CIRCUIT CONNECTION
This shield uses Arduino pin 2-7. You can
attach another Arduino shield (that doesn’t
use those pins) on top of this shield.
TEST CODE