Stepper motor 28BYJ-48 with ULN2003

Hey to all,

I am puzzling with stepper motors, so i would like to add to my project
2 push buttons to control motor rotation CW and CCW.

My code for this project is:

#include <AccelStepper.h>

AccelStepper stepper1(5, 4, 5, 6, 7);

AccelStepper stepper2(5, 8, 9, 10, 11);



void setup()
{

stepper1.setMaxSpeed(500.0); 
stepper1.setAcceleration(200.0); 

stepper2.setMaxSpeed(500.0);
stepper2.setAcceleration(200.0);


}

void loop ()
{
positive ();
negative ();

}

void positive()
{    

if (stepper1.distanceToGo() == 0){
 stepper1.moveTo(20480);
} 
if (stepper2.distanceToGo() == 0){
 stepper2.moveTo(20480);
}
stepper1.run();
stepper2.run();
}

void negative()
{    
if (stepper1.distanceToGo() == 0){
 stepper1.moveTo(-20480);
} 
if (stepper2.distanceToGo() == 0){
 stepper2.moveTo(-20480);
}
stepper1.run();
stepper2.run();
}

Now everything works fine, i got fine speed of rotation, steppers do 10 full rotation CW and CCW.

I would need for stepper to go CW till i tell them to start/stop on push of the button 1 and then start/stop CCW on push of the button 2.

I don’t need to know step count cause for my use i need them to rotate indefinite as DC motor, just to change direction on the push of the button start/stop is very much needed.

so i tried to do fallowing code:

#include <AccelStepper.h>


AccelStepper stepper1(5, 4, 5, 6, 7);

AccelStepper stepper2(5, 8, 9, 10, 11);

int pos = 0;
int neg = 0;
#define switchPin1 2
#define switchPin2 3



void setup()
{
pinMode(switchPin1, INPUT);
pinMode(switchPin2, INPUT);
stepper1.setMaxSpeed(1000.0);
stepper1.setSpeed(1000.0);
stepper1.setAcceleration(800.0); 

stepper2.setMaxSpeed(1000.0);
stepper2.setSpeed(1000.0);
stepper2.setAcceleration(800.0);


}

void loop ()
{

pos = digitalRead(switchPin1);
if (pos =! 0){
 stepper1.moveTo(20480);
 stepper2.moveTo(20480);
}

neg = digitalRead(switchPin2);
if (neg =! 0){
 stepper1.moveTo(-20480);
 stepper2.moveTo(-20480);
}
stepper1.run();
stepper2.run(); 
}

This code was bit changed from first code, now my stepper motors become to slow and they are not reacting to push buttons.

I am using Mega2560 rev3, for buttons i attached them to pins 2 and 3
as you can see from picture attached 2 stepper motors are connected to 5V and
push buttons are connected on one side to 5V+ and on other side to 2kOhm resistors
directly to 5V-.

I found this connection on fallowing page:

Seem’s to work fine for gentlemen who made this tutorial, you can see it
on youtube - Motor de passo 28BYJ-48 ULN2003 com Arduino - YouTube

I attached picture of breadboard wiring so you can see how it was wired.

Help me guy’s please i am stuck on this whole day and can’t figure what am doing wrong.

Thanks for help!

as you can see from picture attached 2 stepper motors

:grin: :grin: :grin: :grin:

Do you seriously expect anyone to see anything from that gigantic mess of wires.

  1. Post your code using code tags
  2. Do not post pictures any bigger than 1000 pixels wide.
  3. Include a schematic of how you have wired things up.
  4. If you post a picture make it one where you can actually see where the wires come from and go to.
  5. DO NOT CROSS POST

I wonder if you are trying to wind us up here.

moderator:

  • crosspost deleted
  • code tags added: [code] & [/code]