Motor buzzing at low speeds

I tried to control a motor using Arduino Uno , HC-05 bluetooth module and a L298N driver module.

This is my code

int enA = 9;
int in1 = 4;
int in2 = 5;
int enB = 10;
int in3 = 6;
int in4 = 7;

int motorSpeedA = 0;
int motorSpeedB = 0;

int val = 0;

void setup() {
  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
  Serial.begin(38400);
}

void loop() {
  //Read input from bluetooth module:
  if ( Serial.available())
  {
    val = Serial.read();
  }


  //Input key switch
  switch (val) {
    case '0':
      analogWrite(enA, 0);
      analogWrite(enB, 0);
      //Code when no key is pressed
      break;
    case '1':
      // Set Motor A forward
      digitalWrite(in1, LOW);
      digitalWrite(in2, HIGH);
      // Set Motor B forward
      digitalWrite(in3, LOW);
      digitalWrite(in4, HIGH);//Code when UP key is pressed
      for (int i = 255; i < 256; i++)
      {

        analogWrite(enA, i);
        analogWrite(enB, i);
        Serial.println("<Forward>");
        if (i = 254)
        {
          i = 254;
        }
      }

      Serial.println("<Setting Motor Forward>");
      break;
    case '2':
      // Set Motor A backward
      digitalWrite(in1, HIGH);
      digitalWrite(in2, LOW);
      // Set Motor B backward
      digitalWrite(in3, HIGH);
      digitalWrite(in4, LOW);
      for (int i = 150; i < 256; i++)
      {

        analogWrite(enA, i);
        analogWrite(enB, i);
        Serial.println("<Backward>");
        if (i = 255)
        {
          i = 150;
        }
      }
      //Code when DOWN key is pressed
      Serial.println("<Backward>");
      break;
    case '3':
      analogWrite(enA, 180); //speed 0 - 255
      analogWrite(enB, 180); //speed 0 - 255
      digitalWrite(in1, LOW);
      digitalWrite(in2, HIGH);
      digitalWrite(in3, HIGH);
      digitalWrite(in4, LOW);
      Serial.println("<Left>");
      //Code when LEFT key is pressed
      break;
    case '4':
      //Code when RIGHT key is pressed
      analogWrite(enA, 180); //speed 0 - 255
      analogWrite(enB, 180); //speed 0 - 255
      digitalWrite(in1, HIGH);
      digitalWrite(in2, LOW);
      digitalWrite(in3, LOW);
      digitalWrite(in4, HIGH);
      Serial.println("<right>");
      break;
    case '5':
      //Code when X key is pressed
      motorSpeedA = 0;
      break;
    case '6':
      //Code when O key is pressed
      motorSpeedB = 0;
      break;
    default:
      motorSpeedA = 255;
      motorSpeedB = 255;
      // default code (should never run)
  }
}

when I send the codes I hear a buzzing sound from the motor but it does not spin.

What could be the reason for this??? :confused: :confused: :confused: 8) 8) 8)

My circuit is attached below

This happens only when I connect two motors at the same time. 8) 8)

When I connect only one motor It works finely.

What must I if I want to spin both motors perfectly.:slight_smile: :slight_smile: :slight_smile:

You might want to provide details of what power supply you are using and what the motors are. Datasheets would be good.

My guess is that either the motors are too powerful for the L298N to handle or the power supply can't supply enough current anyway.

Steve