I have an Arduino Uno and A4988 for controlling a NEMA17 motor. I would need the motor to rotate in one direction for 2 meters, and after turning off and on the circuit, it should rotate back. This should work for a one-way cable car that travels back and forth. Thank you for your help.I have the connection according to this manual https://www.youtube.com/watch?v=5CmjB4WF5XA&t=344s
For informed help, please read and follow the instructions in the "How to get the best out of this forum" post, linked at the head of every forum category.
I moved your topic to an appropriate forum category @lukyzeu.
In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.
I noticed some errors in your code and procedure against the forum rules in your post,
It is part of the forum rules that when posting codes it is done using tags.
These tags can be easily used by clicking " < code > " in the answer board toolbar.
Redo your post by correcting this mistake.
In your code, the problem I saw is that you are using pin 0 of the Arduino to connect the button.
Neither pin 0 nor pin 1 should be used as they are used by the serial to load codes and send messages.
If your assembly was the same as the video you posted the link to, your project will not work, as there is no connection between reset with the sleep pin.
Recommended connection for the A4988 module to work.
Finally, you say that your motor has "rotate in one direction for 2 meters" .
What does it mean to run 2 meters?
How many steps will it take to rotate 2 m?
See your mock code here.
When you press the button for the first time, the motor turns one way, the second time it turns the other way, and the third time it stops.
Thank you for your help. Just as you sent me the schematic, I have the A4988 connected to a 12V power supply, so I need two phases and not just one, thank you