Stepper 28byj-48

Hi, greetings everyone, I'm a new user, I want to ask about the 28byj-48 stepper and the uln2003 driver, I found a problem about the stepper position always changing when starting up power, can anyone help?

How much does it change? I would expect it to move to match the step to the initial phase position produced by your code.

“28byj-48 stepper”

  • These are geared down by ~64
  • How did you determine it is moving ?

Please read this:

I made code like this, after turning it off and when turning it back on, the stepper starts from the last stopped position, how do I lock the position so that at startup it doesn't start from the last stopped position.

kode saya.

#include <EEPROM.h>

// Define pin untuk motor stepper 1
#define STEPPER1_PIN_1 14
#define STEPPER1_PIN_2 12
#define STEPPER1_PIN_3 13
#define STEPPER1_PIN_4 15

// Define pin untuk motor stepper 2
#define STEPPER2_PIN_1 3
#define STEPPER2_PIN_2 5
#define STEPPER2_PIN_3 4
#define STEPPER2_PIN_4 2

// Deklarasi variabel untuk nomor langkah motor stepper 1 dan 2
int step_number_1 = 0;
int step_number_2 = 0;

void setup() {
// Setup pin untuk motor stepper 1
pinMode(STEPPER1_PIN_1, OUTPUT);
pinMode(STEPPER1_PIN_2, OUTPUT);
pinMode(STEPPER1_PIN_3, OUTPUT);
pinMode(STEPPER1_PIN_4, OUTPUT);

// Setup pin untuk motor stepper 2
pinMode(STEPPER2_PIN_1, OUTPUT);
pinMode(STEPPER2_PIN_2, OUTPUT);
pinMode(STEPPER2_PIN_3, OUTPUT);
pinMode(STEPPER2_PIN_4, OUTPUT);

// Fungsi loop akan dieksekusi secara terus menerus setelah fungsi setup selesai
void loop() {
// Loop untuk menggerakkan motor stepper

// Motor stepper 1
for(int a = 0; a < 300; a++) {
OneStep(false);
delay(6);
}

for(int a = 0; a < 300; a++) {
OneStep(true);
delay(6);
}

// Motor stepper 2
for(int a = 0; a < 300; a++) {
OneStep2(false);
delay(6);
}

for(int a = 0; a < 300; a++) {
OneStep2(true);
delay(6);
}
}

void OneStep(bool dir) {
if(dir) {
switch(step_number_1) {
case 0:
digitalWrite(STEPPER1_PIN_1, HIGH);
digitalWrite(STEPPER1_PIN_2, LOW);
digitalWrite(STEPPER1_PIN_3, LOW);
digitalWrite(STEPPER1_PIN_4, LOW);
break;
case 1:
digitalWrite(STEPPER1_PIN_1, LOW);
digitalWrite(STEPPER1_PIN_2, HIGH);
digitalWrite(STEPPER1_PIN_3, LOW);
digitalWrite(STEPPER1_PIN_4, LOW);
break;
case 2:
digitalWrite(STEPPER1_PIN_1, LOW);
digitalWrite(STEPPER1_PIN_2, LOW);
digitalWrite(STEPPER1_PIN_3, HIGH);
digitalWrite(STEPPER1_PIN_4, LOW);
break;
case 3:
digitalWrite(STEPPER1_PIN_1, LOW);
digitalWrite(STEPPER1_PIN_2, LOW);
digitalWrite(STEPPER1_PIN_3, LOW);
digitalWrite(STEPPER1_PIN_4, HIGH);
break;
}
} else {
switch(step_number_1) {
case 0:
digitalWrite(STEPPER1_PIN_1, LOW);
digitalWrite(STEPPER1_PIN_2, LOW);
digitalWrite(STEPPER1_PIN_3, LOW);
digitalWrite(STEPPER1_PIN_4, HIGH);
break;
case 1:
digitalWrite(STEPPER1_PIN_1, LOW);
digitalWrite(STEPPER1_PIN_2, LOW);
digitalWrite(STEPPER1_PIN_3, HIGH);
digitalWrite(STEPPER1_PIN_4, LOW);
break;
case 2:
digitalWrite(STEPPER1_PIN_1, LOW);
digitalWrite(STEPPER1_PIN_2, HIGH);
digitalWrite(STEPPER1_PIN_3, LOW);
digitalWrite(STEPPER1_PIN_4, LOW);
break;
case 3:
digitalWrite(STEPPER1_PIN_1, HIGH);
digitalWrite(STEPPER1_PIN_2, LOW);
digitalWrite(STEPPER1_PIN_3, LOW);
digitalWrite(STEPPER1_PIN_4, LOW);
break;
}
}
step_number_1++;
if(step_number_1 > 3){
step_number_1 = 0;
}
}

// Fungsi untuk menggerakkan motor stepper 2 satu langkah
void OneStep2(bool dir) {
if(dir) {
switch(step_number_2) {
case 0:
digitalWrite(STEPPER2_PIN_1, HIGH);
digitalWrite(STEPPER2_PIN_2, LOW);
digitalWrite(STEPPER2_PIN_3, LOW);
digitalWrite(STEPPER2_PIN_4, LOW);
break;
case 1:
digitalWrite(STEPPER2_PIN_1, LOW);
digitalWrite(STEPPER2_PIN_2, HIGH);
digitalWrite(STEPPER2_PIN_3, LOW);
digitalWrite(STEPPER2_PIN_4, LOW);
break;
case 2:
digitalWrite(STEPPER2_PIN_1, LOW);
digitalWrite(STEPPER2_PIN_2, LOW);
digitalWrite(STEPPER2_PIN_3, HIGH);
digitalWrite(STEPPER2_PIN_4, LOW);
break;
case 3:
digitalWrite(STEPPER2_PIN_1, LOW);
digitalWrite(STEPPER2_PIN_2, LOW);

    digitalWrite(STEPPER2_PIN_3, LOW);
    digitalWrite(STEPPER2_PIN_4, HIGH);
    break;
} 

} else {
switch(step_number_2) {
case 0:
digitalWrite(STEPPER2_PIN_1, LOW);
digitalWrite(STEPPER2_PIN_2, LOW);
digitalWrite(STEPPER2_PIN_3, LOW);
digitalWrite(STEPPER2_PIN_4, HIGH);
break;
case 1:
digitalWrite(STEPPER2_PIN_1, LOW);
digitalWrite(STEPPER2_PIN_2, LOW);
digitalWrite(STEPPER2_PIN_3, HIGH);
digitalWrite(STEPPER2_PIN_4, LOW);
break;
case 2:
digitalWrite(STEPPER2_PIN_1, LOW);
digitalWrite(STEPPER2_PIN_2, HIGH);
digitalWrite(STEPPER2_PIN_3, LOW);
digitalWrite(STEPPER2_PIN_4, LOW);
break;
case 3:
digitalWrite(STEPPER2_PIN_1, HIGH);
digitalWrite(STEPPER2_PIN_2, LOW);
digitalWrite(STEPPER2_PIN_3, LOW);
digitalWrite(STEPPER2_PIN_4, LOW);
break;
}
}
step_number_2++;
if(step_number_2 > 3){
step_number_2 = 0;
}
}

Read
How to get the best out of this forum

and follow the forum rules.

Redo your topic by placing your code between the tags clicking on " < code > " in the toolbar;

Your question makes no sense, how can the motor start from anywhere other than its last stopped position?

You could make it move back to the beginning position before you shut it down.

Or you could add some kind of sensor at the start position and at the start you could move back towards the start until you trigger the sensor

without sensors is it possible, for example adding code.

Without a sensor, you would have to add code to move it back to the a known starting position before you shut it down. Or one could also record the ending position before powerdown, and initialize from the recorded position on next power up.

But without a sensor/limit switch, (or a hard stop) it is an open-loop system and you can't really know where the actual position is.

Edit: One solution early 3d printers (and simple CNCs) without limit switches used was to have the operator manually move/jog the system to a known location and then start the operation from that zero point.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.