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);
}