how to cut power to a stepper motor when idle and bring it back when active ?

Here is my project

A stepper motor is leading the 3kg head of a system. The position of the motor let suppose is controlled by a potentiometer. What I want to do is this :

When the motor arrives at the set-position ( lets say from the potentiometer) and if the position (potentiometer) do not change state, then I want after 5 sec to cut the power to the motor. If the user move the potentiometer in order to change again the position, the power to come back again. Why I want this ?
becouse the whole system will be powered from a battery back and stepper motors continues to consume power even if they are not moving. I cannot think another way to hadle the continusly power consumption of a stepper motor. In fact what I'm asking is something like the automatic switch off you see in many electronic devices when they are not in use and automatic power reinstatement if active again.

Any other idea is welcomed.

Hi,
What stepper motor driver are you using?? That determines how to power off.

The "Holding power" of a stepper when powered off is called "Detent Torque".. See Wikipedia

I m using the L298N

(this one : https://www.amazon.co.uk/dp/B00HNHUYSG)

I m thinking of cutting the power to the driver (maybe with a relay ???) but I have not find any code or module and most important I cannot image how it will be programmed to cut the power if the position-state of a stepper is idle and to bring power back when user want to change position of the stepper.

OK, look at the information and board diagram HERE

See the "enable" inputs. You can use Arduino outputs to enable and disable power to the driver sections.

See that there are two jumpers on the board that "enable" the driver sections. You would remove those and control them with Arduino outputs.

yeah, but the main problem is that I need a code with timer to tell the arduino to cut off the driver when motor is idle (no change in position for 5 sec - no change in the output of potentiometer) and bring power back when the output of potentiometer change.

gspir:
yeah, but the main problem is that I need a code with timer to tell the arduino to cut off the driver when motor is idle (no change in position for 5 sec - no change in the output of potentiometer)

To do that you need to save the value of millis() every time the potentiometer value changes. Then this code will detect when nothing has happened

if (millis() - savedMillis() > 5000) {
   // code to de-power motor
}
else {
   // code to turn on power
}

I think the ELSE part is appropriate for your situation, but I am a bit less confident about it, compared to the IF part.

...R

Yeap, Robin2, it seems like this is the way but how to save the value of millis every time the potentiometer changes ? how to connect into the code the change in analog read (potentiometer) with the millis ?

gspir:
Yeap, Robin2, it seems like this is the way but how to save the value of millis every time the potentiometer changes ? how to connect into the code the change in analog read (potentiometer) with the millis ?

If you click Report to Moderator and ask for this Thread to be merged with your other Thread on the same project I will be able to see the other code and suggest how to add this concept into it.

Don't spilt the same project over multiple Threads.

...R