Stepper Motor Limit Travel

Hi,

Is there any way to limit the travel of the stepper motors for 90º??

I have this code and want to add something that limits the travel of the stepper motors without using a end stop switch because this is a printable robotic arm project and i don't have enough space for the switch.

Something like a counter with an if but i cannot get anything to work, i have a Joystick that is running the stepper motors for now.

void loop () {
  while (analogRead (X_pin) >= 0 && analogRead (X_pin) <= 100) {
    if (steps> 0) {
      digitalWrite (dir_pin, HIGH); // (HIGH = anti-clockwise / LOW = clockwise)
      digitalWrite (step_pin, HIGH);
      delay (1);
      digitalWrite (step_pin, LOW);
      delay (1);
      //steps--;
    }
  }
   while (analogRead (X_pin)> 900 && analogRead (X_pin) <= 1024) {
      if (steps <2050) {
        digitalWrite (dir_pin, LOW);
        digitalWrite (step_pin, HIGH);
        delay (1);
         digitalWrite (step_pin, LOW);
        delay (1);
        //steps ++;
      }
   }
  
  while (analogRead (X_pin1) >= 0 && analogRead (X_pin1) <= 100) {
    if (steps> 0) {
      digitalWrite (dir_pin_1, HIGH); // (HIGH = anti-clockwise / LOW = clockwise)
      digitalWrite (step_pin_1, HIGH);
      delay (1);
      digitalWrite (step_pin_1, LOW);
      delay (1);
      //steps--;
    }
  }
   while (analogRead (X_pin1)> 900 && analogRead (X_pin1) <= 1024) {
      if (steps <2050) {
        digitalWrite (dir_pin_1, LOW);
        digitalWrite (step_pin_1, HIGH);
        delay (1);
         digitalWrite (step_pin_1, LOW);
        delay (1);
        //steps ++;
      }
   }
}

You commented out the 'steps++;' and 'steps--' lines that would have allowed your limits to work!

Yes i know but those steps will only make the stepper go back the same amout of steps we made them go.

Without position feedback, software will not do the trick.

Maybe you can design in physical stops.

Maybe something that would only allow me to move so many turns from the zero point no mater what its current position is?

If the stepper is not overloaded and the driver is properly adjusted, it should not skip steps.

In that case you always know the shaft position, and can position it anywhere that is mechanically allowed by whatever the shaft is attached to.

It would help if you explained why you are asking this question.

The robotic arm cannot exeed the angles because of the wiring for the stepper, that's why we need to limit the travel of the steppers.

If you have to ask this question, then you must already know the beginning position of the arm when you start the Arduino program.
Most projects have to begin the program by finding a fixed beginning position for the arm and call that position zero or position one, and count steps from that position.
When you are not able to find a beginning position, there is not any way for a program to know the real position of the arm.
You can always add a projection on the arm to trigger a zero position sensor. Or add a second arm 180 degrees from the current arm, or use you imagination to design some way of sensing a beginning position.
Paul

Most people experimentally determine reasonable limits, and manually enter them into the control program.

Why do I suddenly get the feeling that the arm is attached to the stepper motor and it's shaft is attached to some plate?

Paul

Something you ate, maybe?

So the idea is to force the steppers do a home at the start and then trying to make the reading and the stops??
My imagination is huge, the coding skills not so much

that's a negative on that Paul, the robotic arm has plates and belts and bearings to stabilize the move as much as possible and with less noise also.

Yes, that is absolutely correct. The code should first test for the end sensor indicating the arm is at the end. If not, move ONE step towards the end and repeat those two pieces of code until the end is sensed. Now you know where to begin the real program for your project.
Paul

There is no 'zero point'. Without a physical stop, limit switch, or position sensor, there is no way to recognize a 'zero point'. You can count steps and set software limits but without a way to recognize a 'zero point' you can't make the software limits correspond to any particular physical limits.

There are magnetic position detectors that are quite small. https://www.digikey.com/en/products/detail/ams/AS5600-ASOM/4914332. Only about $3 each.

´Can you help me out with the code?

What have you tried?

To limit the angle of the arm without limit switches you need a manual way to set the starting position, a position counter that can be used to count the steps between the 0 degree angle and the 90 degree angle and logic that prevents moving past the limits

At power up you could use a momentary contact button that slowly moves the arm toward the 0 position while pressed. Once there, releasing the button sets the position sensor to 0.

You need to calculate how many steps there are between 0 and 90 degrees of the arm. This depends on how you connect the motor to the arm. Example: if the arm is directly connect to the motor, then ¼ turn of the shaft is 90 degrees. If the motor has 200 steps per revolution and microstepping is set to 16, then the math is:

Steps per rev = 200 x 16 = 3200
Steps for 90 degrees = 3200 / 4 = 800

Increment or decrement the position counter depending on the direction of each step

Your logic then uses the position variable to limit movement between 0 and 800. Never allow the counter to exceed the limits and never allow the motor to step past the limits.

How do you know where zero point is?

What does the stepper shaft control?
What is your project?

If you overstep, what happens if it does not stop?
If it damages something or someone, then put a limit switch in, no brainer.
Make room or find somewhere on the device the stepper is moving to put the limit switch.

Thanks.. Tom.... :grinning: :+1: :coffee: :australia:

Thank you for that will try something and get back