I found this topic in forum
I want to reply and continue with this topic has been created but I can't reply from this one. I have to create a new topic. Sorry if I make a mistake. Thanks.
My project uses the Arduino Uno to control a step motor NEMA 23:
and 2 buttons switches to change the direction each time pressed.
The motor diver is TB6560 IC with wiring as in video.
I found the code from Robin2 that I can apply to my application. Thanks Robin2 !
It works but the motor turns too slow.
I have changed the variable value "illisBetweenSteps" = 5 (from 25 as original) but still slow.
The code is in attached.
Could someone can tell me how to modify the code to make the motor turning faster (10x or more) ?
Thanks in advance,
// this version uses millis() to manage timing rather than delay()
// and the movement is determined by a pair of momentary push switches
// press one and it turns CW, press the other one and it turns CCW
byte directionPin = 8;
byte stepPin = 9;
byte buttonCWpin = A0;
byte buttonCCWpin = A1;
boolean buttonCWpressed = false;
boolean buttonCCWpressed = false;
byte ledPin = 13;
unsigned long curMillis;
unsigned long prevStepMillis = 0;
unsigned long millisBetweenSteps = 5; // milliseconds
void setup() {
Serial.begin(9600);
Serial.println("Starting Stepper Demo with millis()");
pinMode(directionPin, OUTPUT);
pinMode(stepPin, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(buttonCWpin, INPUT_PULLUP);
pinMode(buttonCCWpin, INPUT_PULLUP);
}
void loop() {
curMillis = millis();
readButtons();
actOnButtons();
}
void readButtons() {
buttonCCWpressed = false;
buttonCWpressed = false;
if (digitalRead(buttonCWpin) == LOW) {
buttonCWpressed = true;
}
if (digitalRead(buttonCCWpin) == LOW) {
buttonCCWpressed = true;
}
}
void actOnButtons() {
if (buttonCWpressed == true) {
digitalWrite(directionPin, LOW);
singleStep();
}
if (buttonCCWpressed == true) {
digitalWrite(directionPin, HIGH);
singleStep();
}
}
void singleStep() {
if (curMillis - prevStepMillis >= millisBetweenSteps) {
// next 2 lines changed 28 Nov 2018
//prevStepMillis += millisBetweenSteps;
prevStepMillis = curMillis;
digitalWrite(stepPin, HIGH);
digitalWrite(stepPin, LOW);
}
}