I have a L298N Motor Driver, connected to a two dc geared motor and I am using an Arduino Nano as a microcontroller for it.
I'm also using a HW688 buck converter, it has two terminals, a terminal for output (and this is what I use to power the 5V Arduino) and another terminal for input (it has a 12V male power jack and a terminal screw, this is where I connected the L298N)
But the problem is, as I observed the LED of the buck converter turns off (indicating that the power suppy suddenly turns off) whenever I intend to stop the motor in the code. Upon troubleshooting, I started using different L298N motor driver, thinking that the one I use is faulty but the problem still persists. I started looking around in the code, and noticed that when I set the speed below 255 (for example 200) it fixes the problem and the power supply does not turn off when the motor stops.
I have also tried to use a different code without any library and solely relying on digitalWrite() but notices that it is still having the same problem and convinced that it is a hardware problem
What is the reason for this problem? and how to fix it?
Its design lacks the 5 V power supply from the L298 module.
Is the +5V enable jumper connected?
If in the real project you did not power the module with 5V or jumper is connected ,it will not work.
Check if you really have 12V on the connector pins on the module.
Because it wasn't supposed to do that. The buck converter/power supply must not turn off even though the motor stopped. And since the arduino is also connected to that power supply, whenever the power supply turns off the arduino also turns off causing it to reset and to not properly run the whole code.
the 12V power supply that I use is from a 12V power adapter that I directly connected to an outlet
Yes the jumper of the regulator is still connected. I am confuse, as I read it is suppose to be connected? is my assessment correct and if not can you further elaborate on this?
And yes, I have check the voltage of the L298N terminals using a multimeter, the buck converter is giving the L298N consistent 12V and both motor is receiving approximately 8V-10V.
When that library stops the motor(s), does the motor coast or brake to a stop? What is the 12V power supply's current rating? What are the motor(s) current rating? You might try removing the power jumper on the L298 (behind the 3 terminal block) and supply the 5V logic power from the Arduino's 5V pin.
It may fail under special circumstances (back EMF?) and make the buck converter turn off. I'd try a diode towards the motor driver to prevent spikes entering from the stopping motors.
I actually think this is the problem, when the motor stop it probably gives back an EMF that makes the buck converter turns off, what diode would you recommend for this? and can you elaborate how should I connect it to the motor?