Tutorial: Controlling the Displacement of a Stepper Motor with the Arduino+Easy Driver

This turorial shows a curious way of controlling the displacement (clockwise and anti-clockwise) of a bipolar stepper motor with the Arduino and the Easy driver, rotating it in several different ways. The software uses some elements of C Programming Language .

For this purpose, it will be necessary the following components:

- 1x Arduino board

- 1x Bipolar Stepper Motor (MERCURY SM-42BYG011-25 - used here)

- 1x Easy Driver

- Jumpers for connection

 - 1x 9V Source/Battery 

 

A stepper motor is like an eletric one (receives eletric energy and converts it into mechanical type) but it divides its rotation in several intervals (in degrees), which we call steps. The one used in this project has 200 steps per rotation (being each pulse a step). It is possible dividing/configuring both steps and intervals, and this is the task of the software.

Now, set up the circuit below with its components:

PS: The last buses of the protoboard that are not connected, will be afterwards on your 9V source/battery.

And then, open the Arduino's IDE and enter the following code:

 

/* Pins to Configure the Displacement of the Stepper Motor (on the Easy Driver):
//////////////////////////////////////////////
// MS1 MS2 //
// //
// LOW LOW = Full Step //
// HIGH LOW = Half Step //
// LOW HIGH = A quarter of Step //
// HIGH HIGH = An eighth of Step //
// //
//////////////////////////////////////////////
*/

#define step_pin 3    // Define pin 3 as the steps pin
#define dir_pin 2    // Define pin 2 as the direction pin
#define MS1 5     // Define pin 5 as "MS1"
#define MS2 4       // Define pin 4 as "MS2"

int direction;    // Variable to determine the sense of the motor
int steps = 200;      // Number of steps that you want to execute (for full steps, 200 = 1 turn)

void setup() {
   pinMode(MS1, OUTPUT);     // Configures "MS1" as output
   pinMode(MS2, OUTPUT);     // Configures "MS2" as output
   pinMode(dir_pin, OUTPUT);    // Configures "dir_pin" as output
   pinMode(step_pin, OUTPUT);    // Configures "step_pin" as output
   digitalWrite(MS1, LOW);      // Configures the steps division (see above)
   digitalWrite(MS2, LOW);    // Configures the steps division (see above)
   digitalWrite(dir_pin, LOW);    // Sense (HIGH = anti-clockwise / LOW = clockwise) - It can be also changed
}

void loop() { 
while(steps>=0) {    // While the steps value is greater or equal zero
         digitalWrite(step_pin, HIGH);    // Sends logic level 'high' to the steps pin of the motor
         delay(5);    // Waits 5ms for the next step
         digitalWrite(step_pin, LOW);    // Sends logic level 'high' to the steps pin of the motor
         delay(5);    // Waits 5ms for the next step
         steps--;   // Decrements the "steps" variable

   }
}

Connect your 9V battery/source on your circuit. So, do the upload of the program to your Arduino.

Your displacement control of a bipolar stepper motor is ready!!! Change the indicated variables and run the program as many times as you want. We hope you have enjoyed. Any doubts, post here.

We see you next time!

Reference Links:

Datasheet of the MERCURY SM-42BYG011-25 motor

Stepper Motor

Views: 16210

Comment

You need to be a member of GarageLab (arduino, electronics, robotics, hacking) to add comments!

Join GarageLab (arduino, electronics, robotics, hacking)

Latest Activity

Marcelo Rodrigues replied to GarageLab's discussion Serious claims against BeagleBone's manufacturer CircuitCo
"Ed, No, they didn't deliver yet.  :( Good luck for us all."
yesterday
Profile IconWesenachin Asfaw and Muhammad Basil joined GarageLab (arduino, electronics, robotics, hacking)
yesterday
Marcelo Rodrigues replied to FiniousFingers's discussion New to group
"Hey man! A good point to start is reading basic tutorials on Arduino coding and wiring. Then, you…"
yesterday
FiniousFingers posted a discussion

New to group

Couple quick things,I am just starting to learn, or wanting to learn, how to use the Arduino UNO…See More
yesterday
Profile IconDan Urbauer, Bjorn and Jiaming Zhao joined GarageLab (arduino, electronics, robotics, hacking)
Wednesday
FiniousFingers is now a member of GarageLab (arduino, electronics, robotics, hacking)
Monday
Erva updated their profile
Mar 16
Erva and Mrs. Priscilla Bonneval are now friends
Mar 16
Profile IconSamantha Dorr, Lee Robinson and Celso Eiju Ito joined GarageLab (arduino, electronics, robotics, hacking)
Mar 16
Edward Evans updated their profile
Mar 15
Edward Evans replied to GarageLab's discussion Serious claims against BeagleBone's manufacturer CircuitCo
"Hi Marcelo, I am curious if you have had any resolution on this?  We may be in the same boat…"
Mar 15
Celso Eiju Ito left a comment for Mrs. Priscilla Bonneval
"I just accept your invitation. Thank You for contact me. Sincerelly,   'Eiju"
Mar 15
Mohasin Ahamed Chinnapattan commented on Mauro Assis's blog post How to hack a remote control (and a flying shark) I
"You mentioned collector is set to ground but emitter is set to ground in your diagram "
Mar 14
Profile Iconbadrkhan mijbas khalifa, Bethany Cruz, Mrs. Priscilla Bonneval and 1 more joined GarageLab (arduino, electronics, robotics, hacking)
Mar 13
Edward Evans is now a member of GarageLab (arduino, electronics, robotics, hacking)
Mar 9
Profile IconAllan Zilkowsky, Shubham Dewangan, FAUSTO PEREIRA ROMANO and 4 more joined GarageLab (arduino, electronics, robotics, hacking)
Mar 1
Dave Lewing is now a member of GarageLab (arduino, electronics, robotics, hacking)
Feb 27
Profile Iconjames essien and Chow HP joined GarageLab (arduino, electronics, robotics, hacking)
Feb 17
Profile IconPerry Duvall, Irayya Mathad and wiley milam joined GarageLab (arduino, electronics, robotics, hacking)
Feb 16
Profile IconAlan Powell and Chuck Nolan joined GarageLab (arduino, electronics, robotics, hacking)
Feb 9

© 2017   Created by Marcelo Rodrigues.   Powered by

Badges  |  Report an Issue  |  Terms of Service