Go Down

Topic: Stepper Motor continuous motor (Read 586 times) previous topic - next topic

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

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

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

Go Up