hello again, i've started toying with a 28BYJ-48 stepper motor i bought off ebay, with a uln2003a controller and arduino uno. i started with some code i found on the forums here.
//Small Stepper Motor and Driver
/*-----( Import needed libraries )-----*/
#include <Stepper.h>
/*-----( Declare Constants, Pin Numbers )-----*/
#define STEPS 100 //Number of steps per revolution
/*-----( Declare objects )-----*/
/* create an instance of the stepper class, specifying
the number of steps of the motor and the pins it's
attached to. The pin connections need to be 4 pins connected
to Motor Driver In1, In2, In3, In4 and then the pins entered
here in the sequence 1-3-2-4 for proper sequencing*/
Stepper small_stepper(STEPS, 8, 10, 9, 11);
int Steps2Take = 0;
void setup(){
}
void loop()
{
small_stepper.setSpeed(100);
Steps2Take = 2038; // Rotate CW steps = 2038
small_stepper.step(Steps2Take);
delay(200);
}
/* --(end main loop )-- */
from all the info on the net i can find on peoples experiences and from data sheets, the motor has a
Reduction Ratio: 1/64
Step Torque Angle: 5.625°/64
i have a couple of questions about this code:
how is the steps2take value of 2038 calculated?
what is #define STEPS 100 doing?
i have also made some mods to this code so that the stepper will not move untill i press a button, i would like to make this movement exactly 1/6 a rev or 1/10 a rev is this possible with this code and this stepper motor?
i have changed Steps2Take to 339, this i got by dividing 2038 by 6 hoping this would be close enough to 1/6 a rev, but slowly it moves out due to it actually needing to move by 339.6 steps (i assume this isnt possible)
#include <Stepper.h>
const int stepsPerRevolution = 100; // change this to fit the number of steps per revolution
const int buttonPin = 2; // the number of the pushbutton pin
int Steps2Take = 0;
int buttonState = 0; // variable for reading the pushbutton status
Stepper small_stepper(stepsPerRevolution, 8, 10, 9, 11);
void setup()
{
pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input
}
void loop()
{
buttonState = digitalRead(buttonPin); // read the state of the pushbutton value
small_stepper.setSpeed(50);
if (buttonState == HIGH) {
Steps2Take = 339; // Rotate CW steps = 339
small_stepper.step(Steps2Take);
}
else
{
(buttonState == LOW); {
Steps2Take = 0; // Stop moving
small_stepper.step(Steps2Take);
}
}
}
/* --(end main loop )-- */
here is what i have done, please let me know if there is a better way of doing this as im very new to all this XD