Sorry, this might be a bit lengthy, but I really need some help (I am aware that there is a question similar to mine that has already been asked here. However, I couldn't come up with a solution to my problem based on the answers to that question as I am using a separate power source as stated in that question's answers.).
This is my first project with an Arduino and a stepper motor. I did some research and found that an L298N motor driver can both drive the motor and power the Arduino if using an external 12V power supply, but it could also handle up to 35V to the motors if the jumper cable was removed and the Arduino externally powered. I wired the stepper motor to the L298N according to the diagram on this website. I removed the jumper on the L298N and hooked up the circuit with a cheap 24V 2A power brick and a 24V to 5V 3A Tobsun EA15-5V DC to DC converter (I wired the 24V positive to the Tobsun and the L298N +12V positive, and I wired the 5V output of the Tobsun to the +5V of the L298N and to the 5V of the Arduino. The ground of the Arduino and the L298N were both wired to the negative of the 24V).
I uploaded the example StepperOneRevolution example to the Arduino, and it seemed to work fine with the motor spinning as expected when the Arduino was plugged into my computer (the 24V power brick was plugged in as well). As soon as I removed the link to my computer, the Arduino and L298N seemed to turn off and on about twice a second (ALL the lights of the Arduino and L298N would flash on and off). The stepper motor would move just a fraction of a rotation when the lights of the Arduino and L298N were on and would stop when they were off. When I unplugged the wires to the motor, the Arduino and L298N would stop flashing and stay on.
After using a multimeter to measure various voltages across the circuit, I thought that maybe the cheap power brick and/or the Tobsun or my wiring were to blame, so I found a 12V 1A power brick around the home that I know works. I replaced the jumper on the L298N and re-wired the circuit to look exactly like the circuit from the same website as before (12V directly to L298N +12V,L298N +5V to the 5V of the Arduino, GND of both to the negative of the 12V brick). This time, once I plugged in the 12V brick, the motor spun for about a second (twice as long as before), but then the Arduino and L298N turned off and the motor cut out again. This is consistent with it resetting (as stated in the answers to the similar question I mentioned at the beginning).
I have attempted to look for a solution to this, rewire the circuit again, use a different L298N controller, but all to no avail; however, one interesting thing I noticed was that if I get rid of the delay(500), then the motor spins continuously one revolution back and forth (as the StepperOneRevolution example dictates, minus the delay) and Arduino doesn't turn off. I'm pretty sure it's not the delay function that is causing the Arduino and L298N to turn off and on because the time between the motor turning off and on remains consistent no matter the amount I put in the delay. If I leave the delay, the motor also doesn't spin in the opposite direction like it is supposed to after the first delay.
I know that was quite long, but I wanted to get all of the backstory there in detail so that there was no confusion as to what exactly the problem might be. Thank you very much f you read through or even skimmed those paragraphs, and I would truly appreciate if anyone could answer this very specific question! (Please let me know if I missed a detail; I tried not to, but I might have :) )