Whenever I run a program for running the DC motor, the motor suddenly slows down and finally stops, I don't know why it happens.
I use an L298N motor driver, an Arduino Uno, and a 9V battery for motor and separate power for the Arduino.
code:
int In3 = 7;
int In4 = 8;
int ENB = 5;
int SPEED = 250;
void setup(){
pinMode(In3,OUTPUT);
pinMode(In4,OUTPUT);
pinMode(ENB, OUTPUT);
}
void loop(){
analogWrite(ENB, 255);
digitalWrite(In3, HIGH);
digitalWrite(In4, LOW);
}
I am following this circuit:
Is something wrong with my code or is it a hardware problem?