Motor driver buzzing

My L298N motor driver makes a buzzing sound when I press the turn 'left' command on my bluetooth app. Both motors work fine and they can go forward, backward, and right.

Here is my code:

#include <SoftwareSerial.h> // TX RX software library for bluetooth
#include <Servo.h> // servo library 
Servo myservo1, myservo2, myservo3; // servo name
int bluetoothTx = 10; // bluetooth tx to 10 pin
int bluetoothRx = 11; // bluetooth rx to 11 pin
int motorOne = 4;
int motorOne2 = 5;
int motorTwo = 6;
int motorTwo2 = 7;
int enA = 3;
int enB = 2;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);


//initial motors pin

char command; 
char Value;

void setup()
{
  myservo1.attach(2); // attach servo signal wire to pin 9
  myservo2.attach(8);
  myservo3.attach(12);
   
  //Setup usb serial connection to computer
  Serial.begin(9600);
  //Setup Bluetooth serial connection to android
  bluetooth.begin(9600);
}
void loop()
{
  while (bluetooth.available() > 2) {
    Value = bluetooth.read();
    Serial.println(Value);
  }

  if ( Value == 'F') {
    // Robo Pet Run Forward
    digitalWrite(enA, 255);
    digitalWrite(enB, 255);
    digitalWrite(motorOne, HIGH);
    digitalWrite(motorOne2, LOW);
    digitalWrite(motorTwo, HIGH);
    digitalWrite(motorTwo2, LOW);
  } else if (Value == 'B') {
    //Robo Pet Run Backward
    digitalWrite(enA, 255);
    digitalWrite(enB, 255);
    digitalWrite(motorOne, LOW);
    digitalWrite(motorOne2, HIGH);
    digitalWrite(motorTwo, LOW);
    digitalWrite(motorTwo2, HIGH);
  } else if (Value == 'L') {
    //Robo Pet Turn Left
    digitalWrite(enA, 255);
    
    digitalWrite(motorOne, LOW);
    digitalWrite(motorOne2, LOW);
    digitalWrite(motorTwo, HIGH);
    digitalWrite(motorTwo2, LOW);
  } else if (Value == 'R') {
    //Robo Pet Turn Right
    
    digitalWrite(enB, 255);
    digitalWrite(motorOne, HIGH);
    digitalWrite(motorOne2, LOW);
    digitalWrite(motorTwo, LOW);
    digitalWrite(motorTwo2, LOW);
  } else if (Value == 'S') {
    //Robo Pet Stop
    digitalWrite(motorOne, LOW);
    digitalWrite(motorOne2, LOW);
    digitalWrite(motorTwo, LOW);
    digitalWrite(motorTwo2, LOW);
  }

  //Read from bluetooth and write to usb serial
  if(bluetooth.available()>= 2 )
  {
    unsigned int servopos = bluetooth.read();
    unsigned int servopos1 = bluetooth.read();
    unsigned int realservo = (servopos1 *256) + servopos;
    Serial.println(realservo);
    if (realservo >= 1000 && realservo <1180) {
      int servo1 = realservo;
      servo1 = map(servo1, 1000, 1180, 0, 180);
      myservo1.write(servo1);
      Serial.println("Servo 1 ON");
      delay(10);
    }
    if (realservo >= 2000 && realservo <2180) {
      int servo2 = realservo;
      servo2 = map(servo2, 2000, 2180, 0, 180);
      myservo2.write(servo2);
      Serial.println("Servo 2 ON");
      delay(10);
    }
    if (realservo >= 3000 && realservo <3180) {
      int servo3 = realservo;
      servo3 = map(servo3, 3000, 3180, 0, 180);
      myservo3.write(servo3);
      Serial.println("Servo 3 ON");
      delay(10);
    }
    
  }
} 

My materials:

  • Arduino Nano
  • HC-05 blutooth module 6-pin
  • L298N motor driver
  • 2 DC bo gear motors (2WD kit)
  • Turnigy 7.4v lipo 2200mAh (motors)
  • 3.7v lipo 1000mAh (Nano & HC-05)

The app used to control the robot:

Any help & tips would be very much appreciated.

Thank you!

First tip: read the topic "How to get the best from this forum".
Second tip: Post schematics.
Third tip: Post links to the datasheets of the motors.

Is it the driver that is actually buzzing and not the motor?

Yes it's the driver thats making the buzzing sound.

That would then be a mechanical noise from something moving in the driver or board. Expect a failure. That part is old and not the best choice. It will drop about 1.4 volts per side or 2.8 volt. Example: 5V motor - 2.8V = 2.2V on the motor leads. Most of your power is used up as heat.

So do you recommend getting a new L298N driver? or should I get a different one?

Hi,
Have you developed your code in stages?
Do you have code that JUST concerns the motor, NO Bluetooth?
If so does the motors work properly when controlled LEFT?

If you have no code, then can I suggest you write some JUST to control the motor so you can prove the control hardware and software?

A schematic would also help.

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

I highly recommend getting a different driver with MOSFET outputs. You will get a lot more from your batteries.

Alright, I tested a simple code to see if the motors are working fine:

int motorOne = 5;
int motorOne2 = 6;
int motorTwo = 7;
int motorTwo2 = 8;
int en1 = 2;
int en2 = 4;

void setup() {
  // put your setup code here, to run once:
    digitalWrite(en2, 255);
    digitalWrite(motorTwo, HIGH);
    digitalWrite(motorTwo2, LOW);
    digitalWrite(motorOne, LOW);
    digitalWrite(motorOne2, LOW);
    delay(500);
    digitalWrite(en1, 255);
    digitalWrite(motorOne, HIGH);
    digitalWrite(motorOne2, LOW);
     digitalWrite(motorTwo, LOW);
    digitalWrite(motorTwo2, LOW);
}

void loop() {
  // put your main code here, to run repeatedly:

}

So both motors are working which means might be something wrong with software or communications with Bluetooth.

1 Like

And here is the schematic diagram:

Thank you. I read the post you referred to and will make the required changes moving forward.

Schemaics please, not paintings lacking pin numbers, proper power supply etc.

Here is a datasheet for the motors: The site is not where I bought it from but the motors are the same:

That motor needs from 1 to 1.5 amps when starting. That's okey for the L298 I think.
However the voltage lost across the L298 doesn't leave much for the motor. Powering the motors from 7.4 volt would be better.

Hi,
They are not brushless motors...
They are the standard hobby motors that most vendors sell, cheap but workable.

Yes please, and a picture(s) of your project would be good too?
So we can see your component layout.

Tom... :smiley: :+1: :coffee: :australia:

@Railroader @TomGeorge

Hopefully this is more clear:


nmsZPtGUnscSkz7VnRf6xEy.jpeg)

Hi,
Have you got a gnd connection between the Nano and the motor controller?

All is see are EnA, In1, In2, In3, In4, and EnB connections.

You need to connect the gnds so the motor controller has a gnd reference for the control signals.

Tom.. :smiley: :+1: :coffee: :australia:

The last picture tells a story. The 2 first pictures, hang them on the wall naming them: "Mystery".
Provided the controller and the HC-05 are specified for the full voltage range of the battery, and adding the gnd asked for by @TomGeorge, it could work.

@Railroader @TomGeorge

I connected the arduino gnd to the drivers gnd as in the picture:

Nothing is happening now and I hear buzzing from the left gear motor.

That kind of picture is useless. Maybe a chriminal detective solving a murder case will dig into it.