hello everyone, i need help with my code , i want to run my motor (12v 30rpm) for a few seconds and return to the same position , i use l298n motor drive, this is my code
If you want to control the position of your motor you should use a servo or stepper motor. You can't control the position of a normal DC motor without an encoder feedback.
Encoder feedback is some additional bit of equipment that provides information as to the number of revolutions the motor has made in a particular direction.
It might be helpful if you describe your greater project so that a suitable feedback mechanism could be recommended. If, for example, the motor opens and closes a door, the feedback might simply be a switch ("limit switch") that makes contact when the door is fully open or closed.
This happens a lot when you try to build before doing a schematic and a project statement. Your problem is how to know when you are in the home position. That can be easy to impossible. There is no positioning with DC motors, you must use external feedback. You can time but as components wear etc that will change. At the current point all you have given us is a motor with a shaft, more details such as what you are building, a schematic, etc.