Two Stepper Motor (28BYJ-48)

First of all, I'm sorry my English isn't good. And I don't know enough about Arduino programming.
I have two 28BYJ-48 stepper motor and ULN2003 Driver Board.
I want to rotate and stop Motor2, at any time while Motor1 is constantly rotating.
What codes should be used to do this.
Thank You!

ecati:
What codes should be used to do this.

We are not going to write your program for you, but we will try to help if you post the program that represents your best attempt and tell us in detail what it actually does and what you want it to do that is different.

If you just want someone to write a program for you please ask in the Gigs and Collaborations section of the Forum and be prepared to pay.

...R

1 Like

I'm a mechanical engineer, and I'm working on a machine project.
I completed the construction of the prototype machine. See picture.
I bought one Ardiuno Nano and two 28BYJ-48 stepper motors and ULN2003 Driver Board.
Now it's time for the engines to run as I wanted.
I did a research on the internet for a few days, but I couldn't get the information I needed.
Taking the "MultiStepper" code in the AccelStepper library. I have prepared the following code. With this code, the motors rotate continuously. See the video ( - YouTube). I've been stuck here because my Arduino programming skills aren't enough.

#include <AccelStepper.h>

AccelStepper kesici(AccelStepper::FULL4WIRE, 8, 10, 9, 11);
AccelStepper surucu(AccelStepper::FULL4WIRE, 4, 6, 5, 7);

void setup() {

kesici.setMaxSpeed(400);
kesici.setSpeed(200);
kesici.setAcceleration(5000);
kesici.moveTo(1000000);

surucu.setMaxSpeed(600);
surucu.setSpeed(600);
surucu.setAcceleration(5000);
surucu.moveTo(1000000);
}
void loop() {

kesici.run();
surucu.run();
}

What I want to do is:
Motor1 will rotate continuously. Motor2 will turn and stop when I want.
Your suggestions or sample code or a tutorial will be highly appreciated.
Thank you.

What I want to do is:
Motor1 will rotate continuously. Motor2 will turn and stop when I want.

Motor2 will turn and stop when I want.

How do you propose to tell Motor2 to turn go/stop? Using: IR, a switch, a whistle . . .

You can use the runSpeed() function for continuous motion. It does not need to have a prior moveTo()

For the other motor you can get it to move a specific number of steps and use run() or runSpeedToPosition(). You can check if it has reached its destination with distanceToGo(). You can make it stop at any time by not calling run(), or if you are using acceleration you can call stop() to get it to do an immediate decelerated stop.

You need to study the Accelstepper documentation. It is one of the better documented Arduino libraries

...R

For your answers, thank you all.
I didn't understand your suggestions because of my insufficient knowledge, despite the fact that I've worked hard on the AccelStepper topic.
Here's the code I've prepared.
This code works partially as I wanted.
But I cannot adjust the speed of the motors separately.
How do I adjust the speed of the motors separately. Or can you suggest another code?
Thank you.

#include <Stepper.h>

Stepper kesici(512, 8, 10, 9, 11);
Stepper surucu(512, 4, 6, 5, 7);

int stepCount1 = 0;

void setup() {
kesici.setSpeed(60);
surucu.setSpeed(60);
}

void loop() {
kesici.step(1);
stepCount1++;
if (stepCount1 >= 1800) {
for (int i = 0; i <= 1800; i++) {
surucu.step(1);
kesici.step(1);
stepCount1 = 0;
}
}
}

“Motor2 will turn and stop when I want.”
How will you tell Motor2 to stop, by pushing a switch?
Is this Motor2? surucu.step(1);

“How do I adjust the speed of the motors separately. ”
To what speeds are you wanting to set them to?

Hello,
That's my code.
I want to;
1- Motor1 should return continuously.
2- When the motor1 is in step 1800, Motor2 should start to rotate. Motor2 should stop after 1800 steps turn.
This code I'm writing works for this.
However, Motor2 has to make 1800 steps faster than Motor1.
Is it possible to adjust the speed of the motors separately by modifying the code I wrote?

#include <Stepper.h> 

Stepper motor1(512, 8, 10, 9, 11);
Stepper motor2(512, 4, 6, 5, 7);

int stepCount1 = 0;

void setup() {  
  motor1.setSpeed(60);
  motor2.setSpeed(60);
}

void loop() {
  motor1.step(1);
  stepCount1++; 
  if (stepCount1 >= 1800) {
  for (int i = 0; i <= 1800; i++) {
  motor2.step(1);
  motor1.step(1);
  stepCount1 = 0; 
  }
 }
}

ecati:
That's my code.

Why gave have you changed from using the AccelStepper library to the much inferior Stepper library?

The AccelStepper library will make the separate control of the two motors much easier.

As you have found with the Stepper library you have to move the motors 1 step at a time and build the step timing into your own code. You could certainly do that using millis() to manage the timing as illustrated in Several Things at a Time. You just need to work out how many millisecs there should be between successive steps for each motor.

Have a look at Using millis() for timing. A beginners guide if you need more explanation.

...R

1 Like

“Motor2 has to make 1800 steps faster than Motor1.”

Explain ‘exactly’ what this means.

How much faster?

The engine is "28BYJ-48 stepper motor". The number of steps to turn the engine once is 2048.
"Motor1" 2048, "Motor2" must take 1850 steps. "Motor2" must perform step 1850 when "Motor1" is between 600-1800 steps.
So, while "Motor1" is taking 1200 steps, "Motor2" should take 1850 steps.
I've worked with the AccelStepper and Stepper libraries. But I still couldn't write the code needed to make the engines work this way.
As I said before, I'm new to Arduino-related issues. Therefore, I find it difficult to understand the writings I read.
A sample code or your suggestions will help me to learn.
Thank you.

ecati:
So, while "Motor1" is taking 1200 steps, "Motor2" should take 1850 steps.

Do you mean that you want both motors to start at the same instant and stop at the same instant?

If so then the AccelStepper library is not intended for that.

I was under the impression that you wanted one motor to run continuously and the other motor to move a specified number of steps and then stop.

Please clarify.

...R

I was under the impression that you wanted one motor to run continuously and the other motor to move a specified number of steps and then stop.

Yes you are right!

Robin2,
Your signature says, "Two or three hours spent thinking and reading documentation solves most programming problems."
For a few days, I've read countless documents and watched videos. My eyes are broken, my brain is burned, but I haven't solved the problem yet. I feel like an idiot.

ecati:
Yes you are right!

Then go back to what I suggested in Reply #4

...R