L298N DC motor Driver not Working properly

Hello there. Im having trouble with my l289N driver. My main goal is to make the dc motor rotate counter clockwise and with a push of a button it will rotate counterclockwise. My code seems right but the motor just wont do it. I try manually operate the driver by connecting enablea to 5V, input1 to 5V and Input2 to gnd. The dc motor starts to rotate, but when I interchange the connection of input1 and input2 the motor rotation is just the same, when it is supposed to be rotating the other direction right? Any informative help or just the driver isn't just working the way it is supposed to work?? Thanks alot.

Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile:

Hello this is my code Tom. Thank your for responding. :slight_smile:

#define enA 9
#define in1 6
#define in2 7
#define button 4
int rotDirection = 0;
int pressed = false;
void setup() {
  pinMode(enA, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(button, INPUT);
  // Set initial rotation direction
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
void loop() {
  int potValue = analogRead(A0); // Read potentiometer value
  int pwmOutput = map(potValue, 0, 1023, 0 , 255); // Map the potentiometer value from 0 to 255
  analogWrite(enA, pwmOutput); // Send PWM signal to L298N Enable pin
  // Read button - Debounce
  if (digitalRead(button) == true) {
    pressed = !pressed;
  while (digitalRead(button) == true);
  // If button is pressed - change rotation direction
  if (pressed == true  & rotDirection == 0) {
    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);
    rotDirection = 1;
  // If button is pressed - change rotation direction
  if (pressed == false & rotDirection == 1) {
    digitalWrite(in1, LOW);
    digitalWrite(in2, HIGH);
    rotDirection = 0;

This is my schematic and btw im using 8v dc motor and a gizduino at mega328, pot10k.

Never attempt to use the Arduino 5V output to power motors. Use a separate motor power supply and connect the grounds.

The L298 motor driver is an ancient, inefficient design, and cannot handle the current required by many motors.

Post a link to the product page or data sheet for your motor, or use your multimeter to measure the winding resistance and post that.

OPs pic.

Tom… :slight_smile:

The motor just wont rotate to the opposite direction :frowning:

If we can believe your diagram, you forgot to connect the Arduino and motor controller grounds. I'm surprised it would work at all.

Sorry for the late reply, but what do you mean by that? Like the controller must have a common ground with the driver.. I just found that diagram somewhere over the internet.

You need to add the black wire, it will give a reference point for the UNO signals.

Tom... :slight_smile:

I just found that diagram somewhere over the internet.

Lots of complete garbage on the internet!

Don’t trust any single “diagram” that you find, or, in general, Instructables. Study a few different web pages on a particular topic, and that will help you avoid such bad luck.