L298N Motor Driver Controller Board

Written by: techguru

Picture of L298N Motor Driver Controller Board

A guide on how to use the L298N Motor Driver Controller Board, this is a dual motor controller board that allow you to control the direction & speed of two DC motors or one stepper motor.

The L298N Motor Driver Controller Board is a very low cost module, there are several design variants available on the market, mine get from GEARBEST.

Step 1: Specifications

Picture of Specifications

  • Controls 2 DC motors @2A max per DC motor, or one stepper motor
  • Driver: L298N Dual H Bridge
  • Driver input voltage: 5V~35V (or 7V~35V depending on power supply needs)
  • Max average current Io: 2A each
  • Maximum power dissipation: 20W@75 degree Celsius
  • Control signal input level: High level 2.3V <= Vin <= Vss; Low: -0.3V <= Vin <= 1.5V

 

The onboard 78M05 linear regulator provided a stable 5V (up to 0.5A) that can be used to power the L298N H-bridge and other parts.

Step 2: L298N block diagram

Step 3: Logic table

Picture of Logic table

L=Low, H=High, X=Don’t care, Z=High impedance, Vin=Input voltage, Vdrop=Voltage drop

Note: There is a voltage drop between the input voltage and the L298’s motor outputs, you can expect a 1V to 3V drop depend on the input voltage and current draw.

Step 4: Schematic

Step 5: How to Control DC Motors

The first DC motor is connected to Out1 and Out2 of the Motor Driver Controller Board which is controlled by In1 & In2. Set In1=HIGH and In2=LOW cause the motor to go forward, reverse the input signal (In1=LOW, In2=HIGH) cause the motor to go backward. Set both In1 & In2 to LOW make the motor stop immediately.

ENA is HIGH by default that make the motor running at a constant speed. In order to control the speed of the motor, the jummper must removed from EnA, then connect it to PWM capable digital output of a micro-controller.

In certain circumstances, ENA is connected to a non-PWM digital output of the micro-controller in order to stop the motor slowly.

The above connections and methods can be applied to controlling the second DC motor.

Step 6: Controlling DC Motors with an Arduino

By connecting the L298N Motor Driver Controller Board to an Arduino, you can control two DC motors. Code below is the Arduino sketch that control two motors at a constant speed.

#define FORWARD 8#define BACKWARD 2#define STOP 5 int Motor[2][2] = //two dimensional array{{4 , 5},   //input pin to control Motor1--> Motor[0][0]=4, Motor[0][1]=5{6 , 7},   //input pin to control Motor2--> Motor[1][0]=6, Motor[1][1]=7}; void setup() {  pinMode(Motor[0][0], OUTPUT);    pinMode(Motor[0][1], OUTPUT);  pinMode(Motor[1][0], OUTPUT);    pinMode(Motor[1][1], OUTPUT);  } void loop() {  motor_run(0, FORWARD); //motor1 forward  delay(2000);           //delay 2 seconds  motor_run(0, STOP);    //motor1 stop   motor_run(1, BACKWARD); //motor2 backward  delay(2000);            //delay 2 seconds  motor_run(1, STOP);     //motor2 stop} void motor_run(int motor, int movement) {  switch (movement) {    case FORWARD:        digitalWrite(Motor[motor][0], HIGH);      digitalWrite(Motor[motor][1], LOW);      break;    case BACKWARD:         digitalWrite(Motor[motor][0], LOW);      digitalWrite(Motor[motor][1], HIGH);      break;     case STOP:        digitalWrite(Motor[motor][0], LOW);      digitalWrite(Motor[motor][1], LOW);      break;        }     }

Step 7: Controlling Motors speed with an Arduino

Picture of Controlling Motors speed with an Arduino

Sketch below control the speed of two DC motors.

Please remove the jumper from ENA & ENB, ENA & ENB is then connected to Digital 9 and Digital 10 respectively.

#define FORWARD 8#define BACKWARD 2#define STOP 5#define PWM_PIN_1 9 //speed control pin for motor1#define PWM_PIN_2 10 ///speed control pin for motor2 int Motor[2][2] = //two dimensional array{{4 , 5},   //input pin to control Motor1--> Motor[0][0]=4, Motor[0][1]=5{6 , 7},   //input pin to control Motor2--> Motor[1][0]=6, Motor[1][1]=7}; void setup() {  pinMode(PWM_PIN_1, OUTPUT);     pinMode(PWM_PIN_2, OUTPUT);   pinMode(Motor[0][0], OUTPUT);    pinMode(Motor[0][1], OUTPUT);  pinMode(Motor[1][0], OUTPUT);    pinMode(Motor[1][1], OUTPUT);     motor_run(0, FORWARD);    //motor1 forward  motor_run(1, BACKWARD);   //motor2 backward  } void loop() {   //decelerate  for (int  motor_speed=255; motor_speed>=0; motor_speed--) {    analogWrite(PWM_PIN_1, motor_speed);     analogWrite(PWM_PIN_2, motor_speed);    delay(20);  //delay 20 milliseconds  }     //accelerate  for (int  motor_speed=0; motor_speed<=255; motor_speed++) {    analogWrite(PWM_PIN_1, motor_speed);    analogWrite(PWM_PIN_2, motor_speed);    delay(20);   //delay 20 milliseconds  }} void motor_run(int motor, int movement) {  switch (movement) {    case FORWARD:        digitalWrite(Motor[motor][0], HIGH);      digitalWrite(Motor[motor][1], LOW);      break;    case BACKWARD:         digitalWrite(Motor[motor][0], LOW);      digitalWrite(Motor[motor][1], HIGH);;      break;     case STOP:        digitalWrite(Motor[motor][0], LOW);      digitalWrite(Motor[motor][1], LOW);;      break;        }     }

Step 8: Stepper Motor Basics

There are two types of stepper motors: unipolar and bipolar stepper motors. A unipolar stepper motor only operates with positive voltage (requiring only one power source, e.g. 5V and 0). A bipolar stepper motor has two polarities (requiring two power sources, e.g. 2.5V and -2.5V).

  • 4-wire motors are bipolar.
  • 6-wire motors are unipolar.
  • 8-wire motors can be run as either bipolar or unipolar.

 

 

 

 

Step 9: Stepper Modes

Picture of Stepper Modes

  • Wave Drive (One-Phase on)

 

Consumes the least power, only one phase is energized at a time.

 

  • Full Step Sequence (unipolar stepper motor only)

 

In the full step sequence, two coils are energized at the same time which offers an improved torque-speed product and greater holding torque.

 

  • Half Step Sequence (unipolar stepper motor only)

In Half mode step sequence, motor step angle reduces to half the angle in full mode.

 

Note: The L298N only work with bipolar stepper motor, It would not work with unipolar stepper motor.

 

 

 

 

Step 10: Controlling Bipolar Stepper Motors with an Arduino

Picture of Controlling Bipolar Stepper Motors with an Arduino

 

#define OUT1 4 //Digital 4 connect to L298 IN1
#define OUT2 5 //Digital 5 connect to L298 IN2 #define OUT3 6 //Digital 6 connect to L298 IN3 #define OUT4 7 //Digital 7 connect to L298 IN4 int motor_speed = 20; //delay 20 milliseconds (smaller is faster) void setup() { pinMode(OUT1, OUTPUT); pinMode(OUT2, OUTPUT); pinMode(OUT3, OUTPUT); pinMode(OUT4, OUTPUT); } void loop() { step(1,0,0,0); //step 1 (L1 ON) step(0,0,1,0); //step 2 (L3 ON) step(0,1,0,0); //step 3 (L2 ON) step(0,0,0,1); //step 4 (L4 ON) } void step(int in1, int in2, int in3, int in4) { digitalWrite(OUT1, in1); digitalWrite(OUT2, in2); digitalWrite(OUT3, in3); digitalWrite(OUT4, in4); delay(motor_speed); }

There is a stepper library allows you to control unipolar or bipolar stepper motors, please click here for more information.

 

 

 

 

Step 11: Related article

Picture of Related article

I also wrote an article on how to use a wireless router to control the L298N Module, please click here for details.

 

Leave a Reply