Arduino program freezes

I wrote a program to run a stepper motor with arduino. There are buttons to change the speed and direction in the program and a I2C display to display the running parameters. But the program freezes randomly when I press the button. The issue is very common and occurs only when I change the running parameters.
What could be the reasons for freezing? How can I fix the issue?

I am attaching the link to my program here.
backFromStepper Copy - Wokwi ESP32, STM32, Arduino Simulator

Your picture is missing some major things such as power to the stepper motor. Also you need to post links to the motor, motor driver, display module. If that picture is exactly as you have wired it I highly recommend getting some spare Arduinos and motor drivers as you will be frying them.


Sorry for not mentioning that the link i shared shows only the high level of the program. The Nema 34 stepper motor that i use actually has a controller and a power source. I have attached the images for your reference.

what could be reason for the freeze?

You are most likely having EMI problems with all the power and logic is close proximity. I will take a SWAG and expect your box to get overly warm when operating. Powering via the Vin is helping you but apparently not enough. We need the other parameters requested to hopefully solve your problem. EMI can be an extremely difficult problem to solve when there with the hardware, even worse at a distance.

1 Like

Gotta admit, your fab needs work.
Establish a solid +5V and power everything except the motors from that. Build a Power Distribution Board:

Use a terminal shield for inter connects.

Get a 3D printer and build some proper mounts.

Better interconnects on your duponts:

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.