(Not native english speaker here, feel free to edit my sentences)
I try to control the speed of a DC motor with a L298N shield but it doesn't work very well. Here is my scheme :
The power comes from a transfo with an adjustable voltage of ~7v 1.0 Amp. I don't care about the sens of rotation, so I set IN1
to 5v and IN2
to the ground, is it right to do it like that ?
Now here is the code I'm using :
#define CONTROL_M 9 // To Enable input
void setup ()
{
Serial.begin(115200);
}
void loop ()
{
test_analog_motor();
}
void test_analog_motor()
{
for (int i; i < 250; i=i+25)
{
Serial.println(i);
analogWrite(CONTROL_M, i); // Any value between 0 and 255
delay(500);
}
}
With that code, the speed of my motor should progressively increase and then goes back to 0. I'm aware that, maybe if the value is too low, the motor will have trouble to start so I "help" it manually.
If I doesn't use the Enable output of my Arduino and just use the jumper instead, the motor turns with a good torque. This prooves at least that my shield isn't damaged.
Now here is the problem I have : With the scheme I've shown above, it simply doesn't work, nothing happens when I set the grounds in common, why ? Then if I remove the cable that goes to the arduino ground, it works but the motor has a very low torque, it seems also that there is a kind of latency in regards to what display the Serial monitor.
I feel a bit stupid with what I did with the grounds, it seems wrong t me but I don't know what to do instead :/ What can I do ? My goal is to have the best possible control of the speed of that DC motor in term of reactivity, does a L298N is suited for that ?
EDIT I did tested the PWM with an oscilloscope and a multimeter, the arduino PIN I was using worked correctly. I don't know why but now, the shield works too, I mean : Problem solved. One theory is that I adjusted the tension of my power supply under 5V. In that cas the shield doesn't nothing Arduino is magic sometimes...
for (int i; i < 250; i=i+25)
? You might want to initialize the variablei
, like sofor (int i=0; i < 250; i=i+25)
.