Connect Motor Controller Pins To Arduino Digital Pins
Connect Motor Controller Pins To Arduino Digital Pins
Connect Motor Controller Pins To Arduino Digital Pins
// motor one
int in1 = 9;
int in2 = 8;
// motor two
int enB = 5;
int in3 = 7;
int in4 = 6;
void setup()
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
void demoOne()
// this function will run the motors in both directions at a fixed speed
// turn on motor A
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
analogWrite(enA, 200);
// turn on motor B
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
delay(2000);
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
delay(2000);
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
void demoTwo()
// this function will run the motors across the range of possible speeds
// note that maximum speed is determined by the motor itself and the operating v
oltage
// the PWM values sent by analogWrite() are fractions of the maximum speed possi
ble
// by your hardware
// turn on motors
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
analogWrite(enA, i);
analogWrite(enB, i);
delay(20);
analogWrite(enA, i);
analogWrite(enB, i);
delay(20);
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
void loop()
demoOne();
delay(1000);
demoTwo();
delay(1000);
http://www.instructables.com/id/Control-DC-and-stepper-motors-with-L298N-Dual-Moto/
Product Description
This motor controller from Tronixlabs Australia is based on the L298N heavy-duty dual H-bridge controller,
which can be used to drive two DC motors at up to 2A each, with a voltage between 5 and 35V DC - or one
stepper motor with ease. The controller has fast short-circuit protection diiodes, and a nice heatsink to keep
the L298N happy.
There is also an onboard 5V regulator - so if you're using between 7 and 12V DC to driver the motors, the
module can also supply your Arduino (etc) with 5V DC. If you are using more than 12V DC, please remove
the 12V jumper (see below). With a 12 month warranty we think this is the best value L298N dual motor
controller driver module in Australia. Don't forget to check out our Arduino tutorial.
Note that the module is not designed for using the hard brake function of the L298.
Module pinouts - match the numbers against the list below the image: