Problem with Arduino + L298N and PWM

I try to control the speed of a dc motor with an arduino and a ls298n.

Connections:
the motor is connected to out1 and out2 on the l298n. There are also +5V input (l298n vcc) and ground from the 5v power supply is connected with l298n ground and ground pin of arduino

In1 and In2 of L298N are connected to Pin 7 and 8 on Arduino.
ENA of L298N is connected to Pin 9

I´ve done exactly the same as in the youtube video

I can set any value with analogWrite(9, x) but nothing happens.

If i use digitalWrite(9, HIGH) the motor is enabled, but then i have to remove the line: pinMode(9, OUTPUT);
If I set the pin, nothing is working, why?

Here is my code

void setup() {
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
}

void loop() {
  digitalWrite(8, HIGH);
  digitalWrite(7, LOW);
  analogWrite(9, 100);
  delay(1000);
  
  digitalWrite(8, LOW);
  digitalWrite(7, HIGH);
  analogWrite(9, 100);
  delay(1000);
}

I just tried another L298N (not the "red"one , the blue one from sainsmart) and this is working with PWM.
I did the same as with the other module.

I also checked the outputs:
From the red module i get always 0.26V (analogWrite(0-250)
and on the blue one, i get 2V +

I think I have found the problem.
I used for testing a 5V power supply and with 5V the "redone" L298N isn´t working with pwm input.
With the jumper on the place there is no problem.

So I tried a 12V power supply and a 8V battery pack and now i can use the pwm pin to control the speed of the motor.

1 Like