Go Down

Topic: How to achieve continuous rotation on a bipolar stepper motor. (Read 17486 times) previous topic - next topic

msdhillon

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.

TomGeorge

Hi, post us a copy of your circuit of your arrangement.
Use CAD or picture of hand drawn circuit in jpg, png or pdf format.

Tom...... :)
Everything runs on smoke, let the smoke out, it stops running....

johnwasser

Code: [Select]

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;

Stepper stepper(200, StepperStepPin, StepperDirectionPin);

void setup() {
   pinMode(ForwardLimitSwitchPin, INPUT_PULLUP);
   pinMode(ReverseLimitSwitchPin, INPUT_PULLUP);
   stepper.setSpeed(StepperMaxRPM);
}

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);
   }
}
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

msdhillon

Thanks for the prompt replies.

I am using DRV8825 stepper motor driver, high current for driving the stepper motor. http://www.pololu.com/product/2133
I have attached the picture. I am using http://www.pololu.com/product/1472  stepper motor. It has six leads and I am using for of them as mentioned on the website.

msdhillon

@john

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

johnwasser

Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

Precy

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;

Stepper stepper(200, StepperStepPin, StepperDirectionPin);

void setup() {
   pinMode(ForwardLimitSwitchPin, INPUT_PULLUP);
   pinMode(ReverseLimitSwitchPin, INPUT_PULLUP);
   stepper.setSpeed(StepperMaxRPM);
}

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);
   }
}

Robin2

@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
Quote
"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.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Precy

the prograb is simulated i proteus. the motor atuomatically rotate eventhough the switch pins is in the low state. our reference circuit is ithis

TomGeorge

Hi,

Can you please post a copy of your sketch, using code tags?
Please use code tags.. See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png or pdf?

Tom..... :)
Everything runs on smoke, let the smoke out, it stops running....

Precy

@tom here is my code :

#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;

Stepper stepper(200, StepperStepPin, StepperDirectionPin);

void setup() {
   pinMode(ForwardLimitSwitchPin, INPUT_PULLUP);
   pinMode(ReverseLimitSwitchPin, INPUT_PULLUP);
   stepper.setSpeed(StepperMaxRPM);
}

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);
   }
}

TomGeorge

Hi,
Sorry your image is unreadable.
Can that CAD export an image, rather than you doing a screen capture?
Also remove the grid lines please.

Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

Robin2

the prograb is simulated i proteus.
I doubt if that includes either a link to the datasheet for your motor OR the details of the motor power supply that I requested earlier.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

dushan90

Code: [Select]

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;

Stepper stepper(200, StepperStepPin, StepperDirectionPin);

void setup() {
    pinMode(ForwardLimitSwitchPin, INPUT_PULLUP);
    pinMode(ReverseLimitSwitchPin, INPUT_PULLUP);
    stepper.setSpeed(StepperMaxRPM);
}

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.

Robin2

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.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up