Stepper motor

Hi,

I have bought a stepper motor and i got a standard programme. It works but I don’t understand how i can rotate the stepper motor faster or slower.

This was the programma:

// This Arduino example demonstrates bidirectional operation of a
// 28BYJ-48, using a ULN2003 interface board to drive the stepper.
// The 28BYJ-48 motor is a 4-phase, 8-beat motor, geared down by
// a factor of 68. One bipolar winding is on motor pins 1 & 3 and
// the other on motor pins 2 & 4. The step angle is 5.625/64 and the
// operating Frequency is 100pps. Current draw is 92mA.
////////////////////////////////////////////////

//declare variables for the motor pins
int motorPin1 = 8; // Blue - 28BYJ48 pin 1
int motorPin2 = 9; // Pink - 28BYJ48 pin 2
int motorPin3 = 10; // Yellow - 28BYJ48 pin 3
int motorPin4 = 11; // Orange - 28BYJ48 pin 4
// Red - 28BYJ48 pin 5 (VCC)

int motorSpeed = 1200; //variable to set stepper speed
int count = 0; // count of steps made
int countsperrev = 512; // number of steps per full revolution
int lookup[8] = {B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};

//////////////////////////////////////////////////////////////////////////////
void setup() {
//declare the motor pins as outputs
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
Serial.begin(9600);
}

//////////////////////////////////////////////////////////////////////////////
void loop(){
if(count < countsperrev )
clockwise();
else if (count == countsperrev * 2)
count = 0;
else
anticlockwise();
count++;
}

//////////////////////////////////////////////////////////////////////////////
//set pins to ULN2003 high in sequence from 1 to 4
//delay “motorSpeed” between each pin setting (to determine speed)
void anticlockwise()
{
for(int i = 0; i < 8; i++)
{
setOutput(i);
delayMicroseconds(motorSpeed);
}
}

void clockwise()
{
for(int i = 7; i >= 0; i–)
{
setOutput(i);
delayMicroseconds(motorSpeed);
}
}

void setOutput(int out)
{
digitalWrite(motorPin1, bitRead(lookup[out], 0));
digitalWrite(motorPin2, bitRead(lookup[out], 1));
digitalWrite(motorPin3, bitRead(lookup[out], 2));
digitalWrite(motorPin4, bitRead(lookup[out], 3));
}

Perhaps these lines from your program offer some clues

int motorSpeed = 1200;  //variable to set stepper speed

and

//delay "motorSpeed" between each pin setting (to determine speed)

And please post your programs using the code button </> so it looks like this

…R

Hi and welcome,

could you pls read the forum rules (see link in my signature) and modify your first post, so that you use code tags “</>”. Thanks.

  1. How fast is your stepper turning right now? → just estimate its speed in RPM
  2. How fast do you want it to turn?

You are using a

28BYJ-48 motor is a 4-phase, 8-beat motor, geared down by a factor of 68

Do you understand, what that means?

The built-in gear reduces the speed of your motor by exactly that factor.
Means: If you would be able to have that motor without gear, it would turn 68x faster (theoretically)

Your Arduino has a limited clock speed.

The step angle is 5.625/64 and the operating Frequency is 100pps.

If you take into account that the operating frequency is 100pps and one pulse drives your stepper 5.625 degrees further, you will need 64 pulses for 1 turn and 100pps will result into 1.56 turns/s max.

So this stepper will be a very slow one due to its gear reduction. On the other hand it will give you a lot of torque at its shaft. Try to stop it by hand …

Thanks for answering,

when i change the motorspeed it just goes as fast as it already does. It doesn’t go slower or faster.
<int motorSpeed = 1200; //variable to set stepper speed>

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

int motorSpeed = 1200;  //variable to set stepper speed

What values have you tried other than 1200?

Tom... :slight_smile:

  1. Are you powering the motor directly via the Arduino?
    If yes: although it might work in your given situation when the motor doesn't draw more than said 92mA.
    But: when the motor starts it draws much more to get on the run -> I suggest always using external power for motors, even if it is the same 5V level.

  2. There are AFAIK two types of these motors: one purely for 5V operations and the other one can be driven by 12V (max). If you have the second type, 12V external power for the motor should give you some reserve (but don't expect too much).

To drive stepper motors with higher speed it is always better to drive it with the highest possible voltage that the DRIVER(!) can deal with. As the driver drives the stepper with current pulses, the voltage limit of the motor doesn't matter, it just confuses the beginner. The essential lies in the driver's ability to be driven at high voltage and adjustable current output for the coils of the motor.

To play with, getting to learn a bit and for some given situations (when a slow speed with pretty high torque at lowest possible price tag is needed), your motor is ok; but if you want to see what a stepper can really do, just start with a better stepper motor and a better (chopped) driver.

If your budget is small, take a NEMA 14 or NEMA 17 stepper (those are just the size parameters, has nothing to do with their electrical or mechanical features), look for low resistance, low inductance and say, about max. 1 Amp motor coil current. Those babies are already pretty strong.

Take a DRV8825 as motor driver, power it with 24V, and limit the current for the stepper some 10-15% lower than the max. motor current (the datasheet of the motor will tell you this value). With that driver you can enable/disable the motor current, there are a lot of Arduino libraries available, dozens of proven sketches. AccelStepper library even will give you the possibility to ramp up and down acceleration.

SanderKolkman:
when i change the motorspeed it just goes as fast as it already does. It doesn’t go slower or faster.
<int motorSpeed = 1200; //variable to set stepper speed>

Post the program with the changed value so we can see exactly what you tried.

My guess is that you have accidentally created two separate variables with the same name.

…R