L298N - Motor A will not reverse

Hi guys,
I have made a simple setup where I have connected two motors (3v or 5v, not sure) to a L298N Dual H-Bridge. Each motor is controlled by a potentiometer. The code below makes everything work fine, and both motors are running and responds on input from the potentiometers. So far so good.
The L298N is powered by the 5V pin and GRN pin from the UNO-board. The wiring between UNO and L298N is similar with the image below.

However, if I change the code (HIGH>LOW, LOW>HIGH) ) in order to reverse the motors, only motor A is reversing, while motOr B is not running at all.

Anyone has an idea what is wrong?

// Motor A

int enA = 6;
int in1 = 7;
int in2 = 8;

// Motor B

int enB = 11;
int in3 = 9;
int in4 = 10;

// Speed control potentiometers

int SpeedControl1 = A1;  
int SpeedControl2 = A2;


// Motor Speed Values - Start at zero

int MotorSpeed1 = 0;
int MotorSpeed2 = 0;

void setup()
  // Setup Serial Monitor
 
{
 
  // Set all the motor control pins to outputs

  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
 
   
}

void loop() {
  
  // Set Motor A forward

  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
 
 // Set Motor B forward

  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
  
  // Read the values from the potentiometers
    
  MotorSpeed1 = analogRead(SpeedControl1); 
  MotorSpeed2 = analogRead(SpeedControl2);
  
  // Convert to range of 0-255
  
  MotorSpeed1 = map(MotorSpeed1, 0, 1023, 0, 255);
  MotorSpeed2 = map(MotorSpeed2, 0, 1023, 0, 255); 
 
  
  // Adjust to prevent "buzzing" at very low speed
  
  if (MotorSpeed1 < 8)MotorSpeed1 = 0;
        
  if (MotorSpeed2 < 8)MotorSpeed2 = 0;
    
  
  // Set the motor speeds
  
  analogWrite(enA, MotorSpeed1);
  analogWrite(enB, MotorSpeed2);
  
 
}

1. Check if the 5VEN is there, then do not apply 5V from the UNO.
2. Connect external 12V supply across 12V-pin and GND-pin of the Motor Driver Board.
3. Make a simple operational check of the Motors as per following Truth Table:

ENA    IN1   IN2     Function                            Motor Connection
H      H     L       Forward Rotation                    OUT1-OUT2
H      L     H       Reverse Rotation                    OUT1-OUT2
H      PWM   L       Variable speed at Forward directon  OUT1-OUT2
ENB    IN3   IN4     Function                            Motor Connection
H      H     L       Forward Rotation                    OUT3-OUT4
H      L     H       Reverse Rotation                    OUT3-OUT4
H      PWM   L       Variable speed at Forward directon  OUT3-OUT4

PWM Pins:
11, 3 (490 Hz)
9, 10 (490 Hz)
6, 5 (980 Hz)

Not sure what you mean with "check if the 5VEN is there". I have tried both these three configurations of power supply;

  1. external 12V supply and 5V from UNO
  2. only external 12V supply
  3. only 5V from UNO
    Seems to be no difference. Motor ENA still will not reverse.

If I understand you correctly, the operational check has to be performed by editing the code for IN1 and IN2? For ENA the reverse rotation is not happening when I change from H-H-L to H-L-H.
However, ENB is working both directions.

1.

I am talking about the jumper marked in the following diagram (Fig-1). If tis jumper is there, then do not connect 5V supply from UNO.
MotorDriver%VJumper
Figure-1:

2. Perform the following tasks:
(1) Connect Motor across terminals: OUT1-OUT2.
(2) Connect ENA-pin of Motor Driver wit DPin-2 of UNO.
(3) Connect IN1-pin of Motor Driver with DPin-3
(4) Connect IN2-pin of Motor Driver with DPin-4
(5) Uplaod the following sketch and check that the Motor is turning.

#define ENA 2
#define IN1 3
#define IN2 4

void setup()
{
    pinMod(ENA, OUTPUT);
    pinMode(IN1, OUTPUT);
    pinMode(IN2, OUTPUT);
    //-------------------------------------
   digitalWrite(ENA, HIGH);
   digitalWrite(IN1, HIGH);
   digitalWrite(IN2, LOW);
}

void loop()
{
    
}

3. Modify the Sketch of Step-2(5) to verify the following Truth Table.

ENA    IN1   IN2     Function                            Motor Connection
H      H     L       Forward Rotation                    OUT1-OUT2
H      L     H       Reverse Rotation                    OUT1-OUT2
H      PWM   L       Variable speed at Forward directon  OUT1-OUT2
//--------------------------------------------------------------------------------------------
ENB    IN3   IN4     Function                            Motor Connection
H      H     L       Forward Rotation                    OUT3-OUT4
H      L     H       Reverse Rotation                    OUT3-OUT4
H      PWM   L       Variable speed at Forward directon  OUT3-OUT4

I have done the test as you advised. Motor ENA only runs forward by configuration H-H-L. When configured H-L-H, the motor does NOT reverse. Actually, it doesn't get any voltage at all.

Try OUT3-OUT4.

Can you please, post the picture of the Motor you are driving?

I have also tried OUT3-OUT4. It runs both forward and reverse. It is only OUT3-OUT4 that is the problem.

Tho motor is a quite small 5V gear-motor.

It is OUT1-OUT2 terminals that are apparently at fault.

Please, try to change the Motor Driver Board.

I have tried another Motor driver board as well. Same shit!
Now I have performed a "workaround" by connecting two driver boards to the Uno where I am using OUT3-OUT4 on both boards. Works fine! So problem is kind of solved :slightly_smiling_face:
Thank you for your assistance👍

If your battery is the correct range for your motor, connect directly from battery to motor, then switch wire polarity. If the motor did not work in one of the two directions, the motor gears /teeth might be broken or the gears might be "clutched" to spin one direction for "freewheeling."

For Motor B to reverse, you should set in3 to LOW and in4 to HIGH:

digitalWrite(in3, LOW);   // Motor B reverse
digitalWrite(in4, HIGH);

I think I know what is going on with your driver but you need to post an annotated schematic showing exactly how it is wired, show all connections, power, ground and power sources.

I have set up a simple arrangement based on the code below. The code should run both motors in one direction, and afterwards change rotation. Both motors run forward direction. But only motor B is running reverse direction, while motor A is not moving.
I have measured voltage on pin OUT for pins in1, in2. The voltage for each pins is changing between 0 and 5v according to the code. So it should be OK.
I have tried to connect each motor to both OUT1-OUT2 and OUT3-OUT4. The problem is always related to OUT1-OUT2.

The schematic is like this:

And here is the code:

// Motor A

int enA = 9;
int in1 = 8;
int in2 = 7;

// Motor B

int enB = 3;
int in3 = 5;
int in4 = 4;

void setup()

{

  // Set all the motor control pins to outputs

  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);

}

void demoOne()

{

  // Test This function will run the motors in both directions at a fixed speed

  // Turn on motor A

  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);

  // Set speed to 200 out of possible range 0~255

  analogWrite(enA, 200);

  // Turn on motor B

  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);

  // Set speed to 200 out of possible range 0~255

  analogWrite(enB, 200);

  delay(2000);

  // Now change motor directions

  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  digitalWrite(in3, LOW);
  digitalWrite(in4, HIGH);

  delay(2000);

  // Now turn off motors

  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
}

void loop()

{

  demoOne();

  delay(1000);

}

An additional comment:
I have also tried to use another L298N just to verify there is no failure with the driver board. The problems occurs also with the new driver board.

Hi,
Can you please post some pictures of your project?
Showing your UNO connections as well as driver, motor and power supply.

Do you have a DMM? Digital MultiMeter?

Have you checked your jumper leads?

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

Hi TomGeorge,
See post #13. There you will find this information.

Your code (post #13) works. Assuming both L298N boards are good and wiring is correct, the Arduino has been damaged or power supply is insufficient.

Sorry, a picture(s) of your project, real project, not the Fritzy, we need to see your component layout.

Do you have a DMM? Digital MultiMeter?

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

Here is a picture of the real project: