so i do railway modelling, and im trying to make a functional bridge
i've got my stepper motor to rotate constantly clockwise, but how could i make it:
-go clockwise
-stop for a certain amount of time
-go anti-clockwise
-repeat after a certain amount of time
I like the MobaTools library. There are classes for stepper motors (MoToStepper) and also for timers (MoToTimer). See the documentation and examples to see how to use the library and those classes.
#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(0);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(-stepsPerRevolution);
delay(10);
// step one revolution in the other direction:
Serial.println("clockwise");
myStepper.step(-stepsPerRevolution);
delay(10);
}
rpm was just seeing what speeds would be the best for what i am planning to use the stepper motor for, and trying to change direction didn't get anywhere, always is going clockwise
i dont know much about the stepper as i didn't order it myself; the only infomation i can give is one the sticker: ROHS 28BYJ-48 5VDC 15031801
#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(0);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(-stepsPerRevolution);
delay(10);
// step one revolution in the other direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(10);
}
I modified your code a bit and it works with my stepper to go one revolution CW, a pause, one revolution CCW, a pause and so on.
#include <Stepper.h>
const int stepsPerRevolution = 2032; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup()
{
// initialize the serial port:
Serial.begin(9600);
Serial.println("starting stepper bounce");
// set the speed at 10 rpm:
myStepper.setSpeed(10); // fastest that I have seen is 15 RPM.
}
void loop()
{
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(1000);
// step one revolution in the other direction:
Serial.println("counter clockwise");
myStepper.step(-stepsPerRevolution);
delay(1000);
}