A stepper motor is a motor controlled by a series of electromagnetic coils, whose motion is output through reduction gears, and whose rotation-increments are tracked by a driver. The centre shaft has a series of magnets mounted on it, and the coils surrounding the shaft are alternately given current or not, creating magnetic fields which repulse or attract the magnets on the shaft, causing the motor to rotate. This design allows for very precise control of the motor.
There are two basic types of stepper motors, unipolar steppers and bipolar steppers, the 28-BYJ48 is a Unipolar design. The unipolar stepper motor has five or six wires and four coils (actually two coils divided by centre connections on each coil) – the 28-BYJ28 has 6 wires: GND, VDD (power), and 4 control lines. The centre connections of the coils are tied together and used as the power connection. They are called unipolar steppers because power always comes in on this one pole.
The BYJ48´s that I have bought recently have come with small driver boards, and it makes controlling them easy once each cable-coil connection has been identified. I have also controlled them using an L298N H-Bridge board, and ULN2803APG chip but I have found that the small ULN2003A board is much more convenient for projects that require multiple stepper-motor control.
MOTOR SPECS | Datasheet-28BYJ48 |
Rated voltage : Number of Phase 4 Speed Variation Ratio Stride Angle Frequency DC resistance Idle In-traction Frequency Idle Out-traction Frequency In-traction Torque Self-positioning Torque Friction torque Pull in torque Insulation grade | 5VDC 4 1/64 5.625° /64 100Hz 50Ω±7%(25℃) > 600Hz > 1000Hz >34.3mN.m(120Hz) >34.3mN.m 600-1200 gf.cm 300 gf.cm A |
This Motor has a gear-ratio of 64 , and stride-angle of 5.625° so this motor has a 4096 Steps (steps = no. steps in single revolution * gear-ratio): steps= (360°/5.625°) * 64 =4096 (different steppers will have different values, and so a different number of steps in a single revolution).
PROGRAMMING
The Arduino IDE has a good Stepper library which will activate the motor when the coils are triggered in the correct sequence.
A really nice example of some (library-free) code that will get the stepper moving in clockwise and anti-clockwise motion – credits: MAWoodMain
// define the stepper driver pins #define IN1 8 #define IN2 9 #define IN3 10 #define IN4 11 // define how many cycles to a full rotation #define CYCLES_PER_ROTATION 512 void setup() { Serial.begin(9600); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT); pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT); } void loop() { // make the stepper do 1.5 rotations CW turns(1.5); delay(1000); // make the stepper do 1.5 rotations CCW turns(-1.5); delay(1000); }void turns(float rotations) { // if the rotation count is -ve then it is CCW Serial.println(); Serial.print("Turning : "); Serial.print(rotations); Serial.println(" rotations"); bool clockwise = rotations > 0; Serial.print("Clockwise = "); Serial.println(clockwise); // calculate how many cycles the stepper will have to make int cycles = rotations * CYCLES_PER_ROTATION; // force the cycle count to be positive cycles = abs(cycles); Serial.print("That is "); Serial.print(cycles); Serial.print(" Cycles "); // only move if the user specifed an actual movement if(rotations != 0) { if (clockwise) { Serial.println("Clockwise"); // for each cycle for (int x=0; x<cycles; x++) { // for each phase for(int y=0; y<8; y++) { // go to phase y phaseSelect(y); // pause so the stepper has time to react delay(1); } } } else { Serial.println("Counter Clockwise"); // for each cycle for (int x=0; x<cycles; x++) { // for each phase (backwards for CCW rotation) for(int y=7; y>=0; y--) { // go to phase y phaseSelect(y); // pause so the stepper has time to react delay(1); } } } } // go to the default state (all poles off) when finished phaseSelect(8); Serial.println("Done"); } void phaseSelect(int phase) { switch(phase){ case 0: digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); digitalWrite(IN3, LOW); digitalWrite(IN4, HIGH); break; case 1: digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); digitalWrite(IN3, HIGH); digitalWrite(IN4, HIGH); break; case 2: digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW); break; case 3: digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH); digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW); break; case 4: digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH); digitalWrite(IN3, LOW); digitalWrite(IN4, LOW); break; case 5: digitalWrite(IN1, HIGH); digitalWrite(IN2, HIGH); digitalWrite(IN3, LOW); digitalWrite(IN4, LOW); break; case 6: digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW); digitalWrite(IN3, LOW); digitalWrite(IN4, LOW); break; case 7: digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW); digitalWrite(IN3, LOW); digitalWrite(IN4, HIGH); break; default: digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); digitalWrite(IN3, LOW); digitalWrite(IN4, LOW); break; } }