Hi All
I want to know how can I make a program to rotate a stepper to rotate continuously until I tell it otherwise.
I want to make a program where I have two limit switches. If the stepper rotates clockwise and it should continue until it hit one of the limit switches and then it should rotate anticlockwise direction and it another limit switch and rotate clockwise and so on.
I tried to use default stepper library but I could not figure out how to rotate it continuously. I also tried custom stepper library and it solves the problem but it takes at least 4 output pins to attach stepper. My arrangement works with only two outputs to the stepper.
I am new to arduino so any help would be appreciated.
Thanks very much. You are a life saver. Can I use your code for my project. It works. I understood the basic functionality and now I can expand on that to what I need.
Hi all, i'm using this codes for the continuous rotation of stepper motor but its not working,anyone who can help me with this? i'm using L297 and L298 stepper motor driver. I'm new in arduino, i badly need you help
#include<Stepper.h>
const int ForwardLimitSwitchPin = 2;
const int ReverseLimitSwitchPin = 3;
const int StepperStepPin = 4;
const int StepperDirectionPin = 5;
const int LimitSwitchActivated = LOW; // Limit switch grounds pin
const int StepperMaxRPM = 100;
void loop() {
// Step forward until the limit switch is activated
while (digitalRead(ForwardLimitSwitchPin) != LimitSwitchActivated) {
stepper.step(1);
}
// Step reverse until the limit switch is activated
while (digitalRead(ReverseLimitSwitchPin) != LimitSwitchActivated) {
stepper.step(-1);
}
}
@Precy - you are double posting and wasting time. I have already replied to your question in your other Thread
Here is the other answer - ask the Moderator to lock the other Thread
"its not working" does not provide any useful diagnostic information.
Have you any program that can make the motor work properly?
If not do that first. Don't bother with limit switches or anything else that might complicate things.
If you can make the motor work properly with other code tell us what, exactly, the problem code does.
You don't have any Serial.println() statements to allow you to see the values of the detected switches.
L298s are a poor choice for driving stepper motors. See stepper motor basics.
Post a link to the datasheet for your stepper motor?
Give details of the motor power supply - volts and amps.
My reply would probably have been different if I had known the code came from an experienced programmer and was working for another user. However I think I covered the essential points.
void loop() {
// Step forward until the limit switch is activated
while (digitalRead(ForwardLimitSwitchPin) != LimitSwitchActivated) {
stepper.step(1);
}
// Step reverse until the limit switch is activated
while (digitalRead(ReverseLimitSwitchPin) != LimitSwitchActivated) {
stepper.step(-1);
}
}
void loop() {
// Step forward until the limit switch is activated
while (digitalRead(ForwardLimitSwitchPin) != LimitSwitchActivated) {
stepper.step(1);
}
// Step reverse until the limit switch is activated
while (digitalRead(ReverseLimitSwitchPin) != LimitSwitchActivated) {
stepper.step(-1);
}
}
Hello!
How do I change this to stop when it hits the limit switch?
What I need is that it should starts to rotate when I press a push button and rotates until it hits limit switch 1. And when I press the push button once again, it should stars to rotate in the opposite direction until it its limit switch 2.
dushan90:
How do I change this to stop when it hits the limit switch?
That is not a complete program. And this Thread has been dead for nearly 4 years.
It would probably make more sense to start your own Thread with details of your project. For example what stepper motor driver and stepper motor are you using? (Post links to their datasheets)
And if you have a program that partially works post it and tell us what it actually does and what you want it to do that is different.