Notifications
Clear all

Arduino UNO Controlling 3x STEPPER MOTORS 28BYJ-48 5V DC

8 Posts
2 Users
1 Likes
2,139 Views
(@revsbeck)
Member
Joined: 2 years ago
Posts: 15
Topic starter  

Hi,

I try to control 3x Stepper Motors with the Arduino UNO. I made the CODE so it will do:

  1. Rotate Stepper-1 90deg CW at Speed 500   (Type: 28BYJ-48 5V DC, 2106231179)
  2. Rotate Stepper-2 90deg CW at Speed 500    (Type: 28BYJ-48 5V DC, 15031801) needs -1, different P/N
  3. Rotate Stepper-3 90deg CW at Speed 500    (Type: 28BYJ-48 5V DC, 2106231179)
  4. Rotate Stepper-3 90deg CCW at Speed 500  (Type: 28BYJ-48 5V DC, 2106231179) 
  5. Rotate Stepper-2 90deg CCW at Speed 500 (Type: 28BYJ-48 5V DC, 15031801) needs +1, different P/N
  6. Rotate Stepper-1 90deg CCW at Speed 500  (Type: 28BYJ-48 5V DC, 2106231179)

 

It works as intended... ;O)

 

Question 1:

How can I make the CODE, so all 3 Stepper Motors starts at the same time, and not like it is doing now where they starts one after another since the CODE is executed line by line.

 

My CODE:

//Include Arduino Stepper Library:
#include<Stepper.h>

//Define Constants:
//Number of Steps per internal motor revolution:
const float STEPS_PER_REV = 32;
// Gear Reduction:
const float GEAR_RED = 64;
//Number og Steps per revolution on Output Shaft:
const float STEPS_SHAFT_OUT = STEPS_PER_REV * GEAR_RED;

//Define Variables:
//Number of Steps Required by User:
int StepsRequired;
int dt1=500;
int fractionX=4;
int fractionY=4;
int Speed=500;

// Create Instance for STEPPER Class:
Stepper steppermotor1(STEPS_PER_REV,2,4,3,5);
Stepper steppermotor2(STEPS_PER_REV,6,8,7,9);
Stepper steppermotor3(STEPS_PER_REV,10,12,11,13);

void setup() {
// Nothing(Stepper Library Sets Pins as Output)
}

void loop() {
steppermotor1.setSpeed(Speed);
StepsRequired = STEPS_SHAFT_OUT/fractionX;
steppermotor1.step(StepsRequired);
delay(dt1);

steppermotor2.setSpeed(Speed);
StepsRequired = -1*STEPS_SHAFT_OUT/fractionX;
steppermotor2.step(StepsRequired);
delay(dt1);

steppermotor3.setSpeed(Speed);
StepsRequired = STEPS_SHAFT_OUT/fractionX;
steppermotor3.step(StepsRequired);
delay(dt1);

steppermotor3.setSpeed(Speed);
StepsRequired = -1*STEPS_SHAFT_OUT/fractionY;
steppermotor3.step(StepsRequired);
delay(dt1);

steppermotor2.setSpeed(Speed);
StepsRequired = STEPS_SHAFT_OUT/fractionY;
steppermotor2.step(StepsRequired);
delay(dt1);

steppermotor1.setSpeed(Speed);
StepsRequired = -1*STEPS_SHAFT_OUT/fractionY;
steppermotor1.step(StepsRequired);
delay(dt1);

}

 

Arduino UNO   3 x STEPPER

 


   
Quote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2535
 
Posted by: @revsbeck

How can I make the CODE, so all 3 Stepper Motors starts at the same time, and not like it is doing now where they starts one after another since the CODE is executed line by line. 

 

I would suggest that you convert your code to use the AccelStepper library to drive each stepper and use the MultiStepper library to control all three of them.

The AccelStepper library will allow you to build an instance of a class to drive each of the three motors and the MultiStepper will allow you to control them so that you can move an arbitrary distance o each stepper with all motion starting and stopping at the same time (which is what I understand you to want).

https://www.airspayce.com/mikem/arduino/AccelStepper/

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@revsbeck)
Member
Joined: 2 years ago
Posts: 15
Topic starter  

@will 

Thank you for your advise.... it is exactly what I try to accomplish....

I will let you when I have made it work using the "AccelStepper" and "MultiStepper"......


   
ReplyQuote
(@revsbeck)
Member
Joined: 2 years ago
Posts: 15
Topic starter  

@will 

I set up my project using AccelStepper.H.

It is running all 3 Stepper Motors at the same time, which is exactly what I wanted.....;O)

I have the following Questions:

  1. Does Stepper Motor "28BYJ-48" have a "zero/ref point", which can be used, if I want to start from "12 O'clock" every time I execute the "Real" Code....?
  2. Can I make a "feedback loop" from Stepper Motor "28BYJ-48", so I can detect exactly at what position it is with reference to "12 O'clock" and follow the numbers through "Serial Port"....?
  3.  (General Question)   Is it possible to open a Library like AccelStepper.H, and look how the Code is made inside the Library...?

   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2535
 

@revsbeck 

YAY, I'm glad it's working for you 🙂

1) No, I don't think the BYJ motors have any kind of feedback, nor has the AccelStepper library (other than the ability to return to the 0 location you've set). Your motor driver probably doesn't have that capability either. You'd probably have to setup a limit switch, I/R sensor, or Hall sensor with a magnet to establish a zero point when powering up from an arbitrary configuration.

2) You can use the "currentPosition()" method of the class to retrieve the coordinates from the steppers and report that via the serial monitor.

3) Yes, the library contents are stored on your hard drive in a folder with the same name as the #include (as they need to be accessed for compilation.  I don't know what OS you are using, I'm on a Mac and the path to my AccelStepper folder from my home directory is:

/Documents/Arduino/libraries/AccelStepper

You'll have to translate that to whatever your file system uses.

You can peek at (but don't change 🙂 the .h and .cpp files therein. 

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@revsbeck)
Member
Joined: 2 years ago
Posts: 15
Topic starter  

@will 

"AccelStepper.h" looks quite complex, and I just looked at it without changing any thing as you recommended. 🙂

Maybe I can use some kind of limit switch to define a "zero point" like you suggest, but I might have to run the stepper very slow in this area due to the Gear Ratio and inertia in the system, so it will not "overshoot" the "zero point".

Questions:

 

  1. Do you know if it is possible to get a Board for Stepper Motors like I have ordered for Servo Motors (16-Channel 12bit PWM/Servo Drive Shield module I2C PCA9685) so I can control 10-15 Steppers with an Arduino UNO. At the moment I have used all "OUTPUTS" on my UNO just to control 3x Stepper Motors.
  2. Do you know a Stepper Motor Model with internal "zero Switch" and "feedback Loop" possibilities, like you can get Servo Motors with an internal Encoder for same purpose...?
  3. My observation is that "HalfSteps" runs much more stable than "FullSteps" even if I increase the speed for the Stepper Motor running "HalfStep". My setup with the 3x Stepper Motors and UNO often lose position, if it runns "Full Steps", but not if it runs "HalfSteps".....Is this observation valid in general, or is it just a coincident because I am using my cheap hardware (28BYJ-48)...?

 

 

 

 

 


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2535
 

@revsbeck 

Yes, AccelStepper code is very complex and so is the MultiStepper. That's why I suggested that you switch to them instead of trying to adapt your code to simulate what you get for free with them.

I use limit switches to zero out my pen position on the plotters I've built. I just run them slowly backwards until the switch triggers. You'll probably need to zero each stepper independently. Exactly which method which will be most effective will depend on the configuration and use of the steppers.

1) No, I don't - for the BYJ steppers I used the ULN0003 motor drivers (IIRC) and it seems to me that they used 4 Arduino pins each as well. If you switch to something like A4988 motor drivers, then you'd only need a minimum of 2 pins (DIRection and STEP) with an optional third pin for ENAble. I can't say if they'd work with BYJ motors though, never tried that. You may need to switch to NEMA motors.

2) AFAIK, no; steppers are made to split the turn into discrete "steps" and are not equipped with any form of homing mechanism because it is not required for operation. A servo, on the other hand, generally only operates on a "range" of values and generally need a zero point so that it can avoid tearing itself apart when it reaches the end of travel.

A quick Google of "homing stepper motor" just gives a list of various external alternatives to add "home" position recognition to applications using steppers.

3) I believe that is probably due to the limitations of BYJ motors. If I recall correctly, as soon as I tried to drive them fast or under a heavy load, their performance started to drag. I eventually switched over to NEMA17 steppers and A4988 drivers and found them superior in performance.

Things may have changed, I haven't used BYJ steppers in over 5 years now, they were a good choice (being cheap) when I started but I found that my requirements (and expectations) just plain outgrew them 🙂

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@revsbeck)
Member
Joined: 2 years ago
Posts: 15
Topic starter  

@will 

 

Thank you for your time to explain me all that....! 🙂

I will try to look for NEMA Stepper Motor and A4988 drivers..... I do not want to spend too much time with BYJ, since they are quite unstable, especially when they are pushed to the speed limit......

 


   
ReplyQuote