I am using arduino uno to control dc motor speed with L298N. But the problem is that the motor is only going at max speed. PWM pin doesn't work for some reason. I heard many people had some problem but haven't found the solution yet.
code:-
#include <L298N.h>
#define ENA 9
#define IN1 8
#define IN2 7
L298N motor(ENA, IN1, IN2);
void setup() {
// Setup pin mode
//used for display information
Serial.begin(9600);
}
void loop() {
//Drive Motor Forward
motor.setSpeed(10);
motor.forward();
delay(500);
motor.setSpeed(100);
motor.forward();
delay(500);
motor.setSpeed(255);
motor.forward();
delay(500);
}
I only see the motor move at full speed every time. I connected 5V of Arduino to +12V pin of motor driver and Arduino is powered with my laptop USB.
I am using 4.5V toy dc motor for test - DC motor
What could be wrong here?