I have a stepper motor (NEMA 23) with a TB6600 driver and I want the motor to work for a few seconds like 10 seconds its supposed to lift something from the ground to a specific position above the ground so I want the motor to hold the load at this specific position without turning it off or continue lifting I want to control it with a pushbutton that can make me hold it. Can anyone help me with that? Is this holding position feature available in my motor and if it is available please can someone tell me how to write the Arduino code for that?
thanks in advance.
If a stepper has sufficient power it will hold its position when not being stepped if its holding torque is not overcome. Some mechanical systems like the lead screw or worm drive naturally resist being moved by outside forces (back driven).
Robin2's stepper basics might be of interest.
The simple stepper code tutorial will get you started a programming for a stepper.
If the motor zero position (home) is established, it is easy to determine position from there. Homing can be done with mechanical, optical or magnetic switch. How are you planning to establish the zero position for the motor?
yeah I got you, but now how can I make this process to make the motor gets its sufficient power to hold the position is there is an Arduino command to make the motor holds, or what can I do to hold its position without turning off
You first must choose a motor with more holding torque than you will need. That, of course, means that you know the torque that is required. Get that by measurement or calculation. The data sheet for a motor will list the holding torque and the current limit for the motor coils (at which maximum torque will be generated). Once you have the current requirement you can choose a stepper driver and a power supply that will supply the current.
If you want a stepper to hold, just stop sending it step commands. If the stepper driver remains powered, the motor will hold position.
If a motor can lift a load to a position, then it has enough torque to hold it in that position.
Just stop sending it pulses to move and it holds.
// Define pin connections & motor's steps per revolution
const int dirPin = 2;
const int stepPin = 3;
const int stepsPerRevolution = 500;
int stepDelay=2000;
void setup()
{
// Declare pins as Outputs
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
}
void loop()
{
//clockwise
digitalWrite(dirPin, HIGH);
// Spin motor
for(int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(stepDelay);
digitalWrite(stepPin, LOW);
delayMicroseconds(stepDelay);
}
delay(1000); // Wait a second
}
This is the code that I am using can u modify it and put the line that will stop the Arduino from sending pulses to the motor. I want him to stop pulses after 500 full step
If you want something to happen just once instead of repeatedly, put it in setup(){...}
rather than loop(){...}
.
For 500 steps replace this line with
for(int x = 0; x <500; x++)`
That of course will repeat because it is the loop function, so to stop it repeating put it in the setup function. Or put it inside the scope if an if statement so you can control when it does these steps based on the value of a variable.
i replaced the line and did not work for me
2000us, not 2000ms:
So did you do the other things I said as well as replacing the line?
When you have been given advice to change code and you are not having success you need to post your code again in a new post and not change your existing post. Then we can see if you implemented the advice correctly.
thank u bro for all your help and I appreciate all your efforts. I am new to Arduino coding and do not how to solve this problem if u can write the code that makes that function for me I will be really blessed because I am trying all that time and I couldn't do anything.
thanks in advance.
You are not trying all the time. You have not done what I asked, if you had have done what I ask you would have posted code. Learning takes a will and an effort. You seem to be ignoring all offers of help to take on a "please do it for me" approach.
// Define pin connections & motor's steps per revolution
const int dirPin = 2;
const int stepPin = 3;
const int stepsPerRevolution = 500;
int stepDelay=1000;
int x = 0;
void setup()
{
// Declare pins as Outputs
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
//clockwise
digitalWrite(dirPin, HIGH);
// Spin motor
if ( x < stepsPerRevolution )
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(stepDelay);
digitalWrite(stepPin, LOW);
delayMicroseconds(stepDelay);
x++;
}
else {
}
}
I did what u told me and the code does show errors and I do not know why!
No you didn't. Now we can see what you did.
I said:-
I don't see that line in your code at all.
I said:-
So did you put it in the setup function? Yes you did.
So why did you put an if statement round it? and a very silly one at that. It has the effect of only giving the motor one step not the many you would have if you had used the for statement line like I told you to.
The code shows errors because you do not have a loop function in your code, you need one even if it does nothing, like this:-
void loop(){
}
The else clause in an if statement is optional, if you don't want to do anything then leave it out.
stepper holding position:
Have you ever tried to turn the axle of a stepper-motor if the stepper-motor has finished his motion and is just standing still? You will be unable to turn it with the force of your fingers.
You will need a pliers to turn the axle against the holding-torque of a powered stepper-motor.
If you do not reduce the current. The axle will hold its position because the currnet through the coils of the stepper-motor is flowing
all the time
and this makes the stepper-motor hold its position without the need to do anything in your code
Except stop telling it to move any more.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.