Arduino Nano randomly resetting

Hi everyone,

I am currently struggling with an intermittent problem with an Arduino project.

I am using a LabVIEW program to control a few pieces of hardware. One of them is a NEMA 17 stepper motor that drives a rack and pinion actuator. I am using a genuine Arduino Nano with an (official) EasyDriver motor driver to drive the NEMA 17. The arduino listens for the state of a DI pin, and if it is pulled high it moves out the rack until a U-shaped sensor sends a high input signal at the outermost position, it then listens for that DI pin to be pulled low and retracts the rack until a proximity sensor sends a high input signal. Apparently I exceed the 9000 limit when I paste the code here so I'll attach it to this post.

I changed out the Nano and it made no difference. I am using a timeout feature for the first time and I am wondering if the memory usage of this feature could be causing problems. The code is below - would really love to hear any thoughts on whether this is likely to be a hardware or software issue. I am powering the Arduino with a 7V line into the Vin port, and as you can see in the code, I added some status feedback that the Arduino provides via the Serial monitor so I connect it to the COM port of my PC when running the program and see that after a few cycles, the Arduino re-enters the Setup() function.

Let me know what you think, thank you!

Rack and Pinion Actuator.ino (9.8 KB)

I just tried commenting out all the timeout detection parts and the random reset error still occurred

Any help would be much appreciated!