You are on page 1of 9

Food

Living

Outside

Play

Technology

Workshop

BYJ48 Stepper Motor


by Mohannad Rawashdeh on October 11, 2013

Table of Contents
BYJ48 Stepper Motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Intro: BYJ48 Stepper Motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 1: Specification , Motor Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 2: Arduino Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 3: Library Direction Issue ... And how to fix it . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 4: Modify Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

http://www.instructables.com/id/BYJ48-Stepper-Motor/

Intro: BYJ48 Stepper Motor


Stepper Motor is a motor controlled by a series of electromagnetic coils. The center 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 precious control of the motor,There are two basic types of stepper motors, unipolar steppers and bipolar steppers .
In This instructable , I will talk about an Unipolar Stepper Motor 28-BYJ48 .
The unipolar stepper motor has five or six wires and four coils (actually two coils divided by center connections on each coil). The center 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.

http://www.instructables.com/id/BYJ48-Stepper-Motor/

Step 1: Specification , Motor Driver


There are many Types of Drivers , L293 , ULN2003 , A3967SLB , And More ,
The 28-BYJ48 Even comes with Breakout using ULN2003 As a Motor driver chip .
Specification for this Motor :
Rated voltage 5VDC
Number of Phase 4
Speed Variation Ratio 1/64
Stride Angle 5.625 /64
Frequency 100Hz
DC resistance 507%(25)
Idle In-traction Frequency > 600Hz
Idle Out-traction Frequency > 1000Hz
In-traction Torque >34.3mN.m(120Hz)
Self-positioning Torque >34.3mN.m
Friction torque 600-1200 gf.cm
Pull in torque 300 gf.cm
Insulation grade A
and the schematics of This breakout shown like the Pictures on the attachment
Note that if you want to use L293 Instead of ULN2003 , You will need to leave Red wire No connection .
Materials :
you will need :
1) Arduino Board .
2) BYJ48 Stepper Motor 5v
3) ULN2003 Moror driver Module
4) Jumper .
5) 5v voltage source "Optional" .

Image Notes
1. connect motor poles Here

http://www.instructables.com/id/BYJ48-Stepper-Motor/

http://www.instructables.com/id/BYJ48-Stepper-Motor/

Step 2: Arduino Code .


The Arduino IDE Support a Library for Stepper Motor , Very Easy to use , After Connect Motor with arduino You can Upload the Sketch on to the arduino .
But ...
You must take something in consider :
This Motor has a Gear ratio of 64 , and Stride Angle 5.625 so this motor has a 4096 Steps .
steps = Number of steps in One Revolution * Gear ratio .
steps= (360/5.625)*64"Gear ratio" = 64 * 64 =4096 . this value will substitute it on The arduino Sketch
For adafruit Stepper Motor , the Stride Angle 7.5 and Gear ratio is 16 , So number of steps in 1 Revolution is :
steps in One Revolution = 360 / 7.5 = 48 .
steps= 48 * 16 = 768
That's will be different depend on what motor you are using , So check The Datasheet for Your stepper Motor to calibrate this values
28-BYJ48 Motor Datasheet .
Motor Driver ULN2003 BreakOut Connected To Arduino From IN1 - IN4 To D8 - D11 Respectively
To Power you Motor , Recommanded to use external Power Supply with 5V-500mA at least , Don't power it directly from arduino Board 5V .

http://www.instructables.com/id/BYJ48-Stepper-Motor/

Step 3: Library Direction Issue ... And how to fix it .


When You Upload the sketch to the arduino , The Motor will Be rotate in one direction By type the command :
step(steps);
So you must Put the Number of step to turn the motor .
The reference said You can put the positive value to turn one direction, negative to turn the other.
If that's OK With Your stepper Motor , You don't need to read the following .
If Not , Your Motor turn to same direction even you Put the steps Positive Value or negative , What is the issue ?
This Motor need to operate as the Table on the attachment .
the arduino Stepper Library need to modify to match this requirement .
I wrote a code which is allow to this motor to Move clockwise and counter clock wise
Code in the next step :

http://www.instructables.com/id/BYJ48-Stepper-Motor/

Image Notes
1. Programming Table

Step 4: Modify Code


the final code for this Stepper motor :
/*
BYJ48 Stepper motor code
Connect :
IN1 >> D8
IN2 >> D9
IN3 >> D10
IN4 >> D11
VCC ... 5V Prefer to use external 5V Source
Gnd
written By :Mohannad Rawashdeh
http://www.instructables.com/member/Mohannad+Rawashdeh/
28/9/2013
*/
#define IN1 8
#define IN2 9
#define IN3 10
#define IN4 11
int Steps = 0;
boolean Direction = true;// gre
unsigned long last_time;
unsigned long currentMillis ;
int steps_left=4095;
long time;
void setup()
{
Serial.begin(115200);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
// delay(1000);
}
void loop()
{
while(steps_left>0){
currentMillis = micros();
if(currentMillis-last_time>=1000){
stepper(1);
time=time+micros()-last_time;
last_time=micros();
steps_left--;
}
}
Serial.println(time);
Serial.println("Wait...!");
delay(2000);
Direction=!Direction;
steps_left=4095;
}
void stepper(int xw){
for (int x=0;x<xw;x++){
switch(Steps){
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);

http://www.instructables.com/id/BYJ48-Stepper-Motor/

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;
}
SetDirection();
}
}
void SetDirection(){
if(Direction==1){ Steps++;}
if(Direction==0){ Steps--; }
if(Steps>7){Steps=0;}
if(Steps<0){Steps=7; }
}

http://www.instructables.com/id/BYJ48-Stepper-Motor/

Related Instructables

Easy To Build
Stepper
Controller from
Recycled
Materials by
murray484

Stepper Motor
magic by
goldenshuttle

Re-purposing
an old Scanner
into a Tabletop
Saw by
sudarshan

Bipolar Stepper
Motor by
Husham Samir

Recycled
Stepper
Controller
Followup
(Photos) by
OldVamp

XY-Plotter by
bdeakyne

Advertisements

Comments
2 comments

Add Comment

Jerry E says:

Oct 20, 2013. 4:52 PM REPLY


I bought a couple of these cheap and got them working with my Arduino from an internet example, but you have provided a much better explanation here.
Thanks for posting this!

Mohannad Rawashdeh says:


Thank You Jerry E .

http://www.instructables.com/id/BYJ48-Stepper-Motor/

Oct 20, 2013. 5:36 PM REPLY

You might also like