Is this high pitch sound normal?

Hello,
Im using a L298n to drive a gearbox motor. I can control the speed of the motor using the ENA OUTPUT. when i set it to 255 (highest speed) the motor sounds "normal" but when i try to lower the speed. lets just say to 150 the motor starts making a high pitch sound. Is it normal for a motor to make that sound or is it a indication there is something wrong?

Thanks for your help.

const int buttonPin = 2;
const int limit1Pin = 5;
const int limit2Pin = 4;
const int ENA       = 9;
const int IN1       = 7;
const int IN2       = 6;

int buttonState = 0;
int buttonPushCounter = 0;
int lastButtonState = 0;
int limit1State = 0;
int limit2State = 0;


void setup()
{
  // put your setup code here, to run once:
  pinMode (buttonPin, INPUT);
  pinMode (limit1Pin, INPUT);
  pinMode (limit2Pin, INPUT);
  pinMode (ENA, OUTPUT);
  pinMode (IN1, OUTPUT);
  pinMode (IN2, OUTPUT);
  Serial.begin(9600);
}

void runClockwise()
{
  Serial.println("Clockwise");
  analogWrite (ENA, 255);
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
}

void runCounterclockwise()
{
  Serial.println("Counterclockwise");
  analogWrite (ENA, 255);
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
}

void stopMotor()
{
  Serial.println("Stop");
  analogWrite (ENA, 0);
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
}

void loop()
{
  // put your main code here, to run repeatedly:
  buttonState = digitalRead(buttonPin);
  limit1State = digitalRead(limit1Pin);
  limit2State = digitalRead(limit2Pin);

  if (buttonState != lastButtonState)
  {
    
    lastButtonState = buttonState;

    

    if (buttonState == HIGH)
    {
      runClockwise();
    }
  }

  

  if (limit1State == HIGH)
  {
    // Limit1 Switch Pressed
    runCounterclockwise();
  }

  
  if (limit2State == HIGH)
  {
    // Limit2 Switch Pressed
    runClockwise();
    delay (1500);
    stopMotor();
  }
}

It's normal. The noise is caused by the motor windings resonating at the frequency of the PWM signal.

It is possible to change the PWM frequency and that might eliminate the noise - if the noise matters.

...R

Allright, learned something new today :slight_smile:

thanks for your fast reply.

The default PWM rate for Arduinos is quite low, 500Hz or 1kHz roughly. Typical motor controllers
use higher frequencies for small motors to avoid magnetic saturation during the PWM cycle. 8kHz or
16kHz is fairly common for MOSFET motor controllers, and tends to be much quieter acoustically
as the wires in the windings can't move much at higher frequencies.

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