I'm trying to manipulate a single DC motor (238-9759) using an H-bridge (L298n). I've basically copied the schematics of the multiple tutorials I've read and watched, shown on the image. The polarity of the voltage is controlled via digital pins 2 and 3, and the PWM signal via pin 9. The H-bridge is powered by the 5V output of the Arduino.
The problem is that the tutorials tell me to control the power of the motor (by PWM) by connecting pin 9 of the Arduino to the ENA pin of the L298n. This involves taking off a cap that connects the ENA pin and the 5V pin behind it. Somehow, when I take it off, the motor stops running, and nothing works until I put the cap back off, in which I become unable to control the power of the motor.
It is strange because I am using the exact code and schematic that the tutorials suggest I do.
I would greatly appreciate some help. Thanks!
Code:
int motor1pin1 = 2;
int motor1pin2 = 3;
int ENA = 9;
void setup() {
// put your setup code here, to run once:
pinMode(motor1pin1, OUTPUT);
pinMode(motor1pin2, OUTPUT);
pinMode(9, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(motor1pin1, LOW);
digitalWrite(motor1pin2, HIGH);
// The code below is never portrayed--the motor stays spinning as though the pin output is 255,
// that is, as long as the cap is connected
analogWrite(9,255);
delay(1000);
analogWrite(9,200);
delay(1000);
analogWrite(9,150);
delay(1000);
analogWrite(9,100);
delay(1000);
analogWrite(9,50);
delay(1000);
analogWrite(9,0);
delay(1000);
}