L298N: problems with motor directions (reverse does not work!)

I am using an L298N motor driver to control the DC 12v gear motor


I'm using esp32 and this is my code

#include <L298N.h>

const unsigned int IN3 = 17;
const unsigned int IN4 = 16;
const unsigned int ENB = 4;

L298N motor1(ENB, IN3, IN4);
void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:
motor1.setSpeed(255);
motor1.forward;
delay(5000);
motor1.backward;
delay(5000);
motor1.setSpeed(130);
motor1.forward;
delay(5000);
motor1.backward;
delay(5000);
}

my motor Is going forward but not backward

Ground connected?

Does L298N.h configure pinMode()?

IMPORT

You can import the library in your code using the Arduino IDE going to Sketch -> Include library -> L298N or directly writing the include statement in your code:

// For single motor instance
#include <L298N.h>
// For two motors instance at once
#include <L298NX2.h>

I think you need to motor1.stop() before changing direction.

yes, the ground is connected and L298N.h doesn't need configure pinMode

ok ill try that like this -

void loop() {
  // put your main code here, to run repeatedly:
motor1.setSpeed(255);
motor1.forward;
delay(5000);
motor1.stop();
motor1.backward;
delay(5000);
motor1.stop();
motor1.setSpeed(130);
motor1.forward;
delay(5000);
motor1.stop();
motor1.backward;
delay(5000);
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.