28BYJ-48 Stepper Motor

2,797

34

6

About: Electronics, Systems, Programming, Tech, Geeky stuff.... all are my <3

Intro: 28BYJ-48 Stepper Motor

Assuming you have this type of stepper motor :D and you wonna run it.. you may face two problems in your

project:

  1. Using the arduino stepper library to drive it you found out that the 28BYJ-48 stepper motor
    is only rotating in one direction & when you flip the direction it doesn't respond and continue in that direction ( seems its ignoring your commands OOps :P ).

  2. You found out that you want your arduino to do something else while its rotating that motor and not
    wait till it finish to do so.

    So so in this little instra i will explain the reason for behind THESE

.

Step 1: Why !

The first issue is because not every thing in this world is the same, also stepper motors are not the same some are Bipolar some are Unipolar.. wait a second what does that mean :/ ?

Well you dont have really to care about deep stuff other than its a difference in basic architecture

and difference in switching sequence... and what is the switching sequence ?

If you have read a basic description about stepper motors.. they just work on by switching the coils on off on off one by one or more than one at a time which create a magnetic field that let the metallic part to rotate, so the sequence is like if we have 4 coils .. how we will trigger them at a time.. so this info shall come in product description or just GOOGLE it.. (in the uploaded pics there are two types of sequences) ,.... any way.

So this 28BYJ-48 sequence is gonna be like

1000, 1100, 0100, 0110, 0010, 0011, 0001, 1001 at a time to cause a step

since arduino library could make our stepper not to rotate because of difference in sequences that is the reason of one direction :D

The second issue is that we get into a locked loop to perform the rotation till it finish then the control goes back to the microcontroller ...


Wonna solve these problems go to the next step... >

Step 2: Solution!

28BYJ48 is a simple library i wrote to fix the problem for me,, so i wanted to share it ..

this library is easy to use .. it will let you drive your motor in two directions.. also you can let the program flow while you are driving your motors .. tadaa.

you may think.. how can i tell it to rotate 360 degrees or less or more :/ shall i calculate it all the time in my mind..

the answer is noOO.. if you wonna use degrees, radians or what ever unit you have in your mind other than STEPS

you just write a custom function that will do the conversion from your unit to the motor unit :D implementing your mathematical accuracy,,,

for example:

to give the angle in degrees you may use this way:

long f1(long x){return x*motor.steps_per_rev/360; 
}

or this way:

long f1(long x){return map(x, 0, 360, 0, motor.steps_per_rev); 
}

and then pass that function to the motor

motor.set_conversion_function(f1);

Link to the library is here

Share

    Recommendations

    • Audio Contest 2018

      Audio Contest 2018
    • Fix It! Contest

      Fix It! Contest
    • Tiny Home Contest

      Tiny Home Contest

    6 Discussions

    0
    None
    AhmedL31

    1 year ago

    hi i want that step motor do a half turn to the right and go back to the middle and do a half turn to the left and go back to the middle and repeat all that every 2 hours

    are that possible if yes can anyone give me the code please i try but i Failed thx

    1 reply
    0
    None
    mal-hdAhmedL31

    Reply 1 year ago

    it is easy man, just set the angles 90, 0, reverse directions, 90, 0, reverse directions, delay 2 hrs

    0
    None
    Oceane4022

    1 year ago

    Thank you ! You solved my problem to !

    I didn't know how to give an angle to the motor, now I can do it !

    Thank to share your experience

    1 reply
    0
    None
    DonCesare

    1 year ago

    I was facing these same problems. I am not a C programmer so I couldnt really fix them and couldnt find anything if googled. Now I will finally finish my project thanks to you!
    Thank you so so much for this.

    1 reply
    0
    None
    mal-hdDonCesare

    Reply 1 year ago

    Oh really i appreciate that ... hope it helps