1. I created a simple circuit with an UNO, L298N and a single motor.

  2. Wrote the following code to test controlling the speed of the motor.

  3. Tested motor with digitalWrite() function and it works fine.

  4. Tested motor with analogWrite() function and from 255 down to around 70 motor works at various speeds.

Q: But from around 70 and below, the L298N starts to beep and the motor stop spinning. Any thoughts?

int enr = 9;
int inr1 = 8;
int inr2 = 7;

void setup() {
 pinMode(enr, OUTPUT);
 pinMode(inr1, OUTPUT);
 pinMode(inr2, OUTPUT);  

void loop() {
  analogWrite(enr, 71);
  digitalWrite(inr1, HIGH);
  digitalWrite(inr2, LOW);
  • 1
    The LN298N should not beep and should not be able to. Might it be the motor, who is beeping? That the motor is not moving below 71 can be because the friction is too big for the motor to move
    – chrisl
    Commented Jul 28, 2019 at 17:51

1 Answer 1


Ok, here is my theory what's happening:

Every motor has an amount of friction at his rotor. You need to pass enough energy to overcome this friction, or the motor will not move. When you use analogWrite(enr, 71) or lower, you pass only a small amount of energy to the motor, so that it cannot overcome the friction.

Now you have to understand, what analogWrite() really does. It does not output an analog voltage. Instead it generates a PWM signal. The voltage changes between HIGH and LOW level (5V and 0V in case of the Uno) at a specific frequency. The relation between HIGH time and LOW time is called duty cycle. That is, what's controlling the motor speed. So instead of supplying different voltages, we turn the motor on and off very fast. Since the rotor has a relatively big inertia (because of it's mass), it cannot react fast enough to follow these pulses. We only give it small pushes very fast. Instead it integrates over all the pulses. If the duty cycle is low (more LOW than HIGH time) only a small amount of energy is passed to the motor.

So, what is the motor doing, when it's got not enough energy to overcome the friction? It will still get little pushes very fast, but cannot actually spin. Instead the passed energy will induce vibrations in the motor, which have the frequency of the PWM signal. These vibrations can then be heard as a continuous beep.

If enough energy is passed to overcome the friction, the rotor spins correctly and does not vibrate, thus you cannot hear a beep.

What to do now:

The described principle applies to every motor, so cannot do much about that. You can simply go the easy way and not drive the motor with such low duty cycles. Another cause might be, that your motor likes to get a higher current to give it's full power. The L298N is quite inefficient, so you could change that to a H-bridge driver, that uses MOSFETs instead of bipolar transistors. Also maybe you can increase the voltage, that you use to drive the motor (depending on the not specified motor).

You didn't describe, how you have connected everything, so 2 other points: You cannot drive a motor from a digital pins power (since a digital output pin can only provide 40mA at max, 20mA recommended) and you should also not power a motor through the Arduino, since you might fry the voltage regulator or the protection diode. You can get away with that, when using small motors without any load, but that doesn't scale well. You should always connect the motor circuit directly with the power supply, so that the motors current does not have to flow through the Arduino.

  • Awesome info! Thank you. The friction problem makes perfect sense (motors are powered by a 7.5V external source). I got used to Lego Mindstorms motors that can turn really slowly. I shall adjust my expectations for now and look into alternative configurations in the future. I did read that the L258N is ancient technology, but by then I had committed my project! Thank you!
    – yannism
    Commented Jul 28, 2019 at 21:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.