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.
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.
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.
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.