Hello
I'm quite new to arduino, completely new to stepper motors. Anyway, I have a 28BYJ-48 5V stepper motor with the corresponding ULN2003 driver, both part of a starter kit with arduinio uno I got some time ago. I've been reading all I've found about steppers, and I think I got the main ideas. I've tested the motor with the stepper library, and it seems to work, although the number of steps per revolution is driving me nuts.
I've seen some sources say that this particular model is a 64 steps per revolution, while other places say it's 32. And then it has an almost 64:1 reduction, so a total of 64x64=4096 steps per revolution (a little less, 4076 apparently, the gear ratio is no exactly 64).
According to this, if I tell arduinio to drive for 4076 steps, it should give me a full 360º rotation of the shaft, shouldn't it? Well, not quite. The rotation I'm getting depends on the speed stetting! With a value of 300, I get a quite-consistent 270º. If I go to 400, it gets me almost 1 rev, a few degrees more. If I lower it to 200, the movement is muche less smoth, jumpier, and I get a bit less than 270º. Going to 100 get's smoother again, but it gives me almost 2 revolutions! From 500 and up, the movement becomes very jumpy and slow, and at 700 it doesn't move.
I don't knwo what the speed setting is really doing, I think it's related to the delay between each step is commanded, but the non-linear behaviour I see is killing me. Other erratic aspect is that when I drive it CW and CCW, I don't get back to the initial point, it's like with every loop it skips or gains a few steps on each direction, completely random, so it ends up drifing away from the stating orientation.
Am I doing something wrong? Or is it that I have a crappy motor and I should be getting a better one?
The circuit is fairly simple, so I don't think I've mess it up. I'm powering the ardunio from the USB, the motor with an external 5v power source, the arduino GND connected to the GND of the 5v supply. Pins for the motor coils are 8 to 11.
This is my sketch, taken form an exapmle online at Stepper Motors with Arduino – Bipolar & Unipolar, with some changes, like the stes per revolution value from 32 to 64.
#include <Stepper.h>
// Define Constants
// Number of steps per internal motor revolution
const float STEPS_PER_REV = 64;
// Amount of Gear Reduction
const float GEAR_RED = 64;
// Number of steps per geared output rotation
//const float STEPS_PER_OUT_REV = STEPS_PER_REV * GEAR_RED;
const float STEPS_PER_OUT_REV = 4076;
// Define Variables
// Create Instance of Stepper Class
// Specify Pins used for motor coils
// The pins used are 8,9,10,11
// Connected to ULN2003 Motor Driver In1, In2, In3, In4
// Pins entered in sequence 1-3-2-4 for proper step sequencing
Stepper steppermotor(STEPS_PER_REV, 8, 10, 9, 11);
void setup()
{
// Nothing (Stepper Library sets pins as outputs)
}
void loop()
{
steppermotor.setSpeed(400);
steppermotor.step(STEPS_PER_OUT_REV);
delay(1000);
steppermotor.step(-STEPS_PER_OUT_REV);
delay(1000);
}
Thanks a lot for any help you can provide.