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: 16466

Comment

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

Join GarageLab (arduino, electronics, robotics, hacking)

Latest Activity

Marco is now a member of GarageLab (arduino, electronics, robotics, hacking)
Monday
Muhammad Ali commented on Marcelo Rodrigues's blog post Arduino generated VGA (color) signal - Complete!
"Thanks for the advice. I will persist with the code till I get it done. thanks once again."
Apr 18
Marcelo Rodrigues commented on Marcelo Rodrigues's blog post Arduino generated VGA (color) signal - Complete!
""The output waveforms on oscilloscope for Hsync and Vsync and for that matter RGB pins are not…"
Apr 17
Muhammad Ali commented on Marcelo Rodrigues's blog post Arduino generated VGA (color) signal - Complete!
"Hi  Marcelo I am trying to make this code work with Attiny 44a operating @ 20 MHz. I have…"
Apr 17
Profile IconReal NOiseux, Muhammad Ali, bob v and 1 more joined GarageLab (arduino, electronics, robotics, hacking)
Apr 17
baiqian is now a member of GarageLab (arduino, electronics, robotics, hacking)
Apr 10
Profile IconDavide and Almas Amandossov joined GarageLab (arduino, electronics, robotics, hacking)
Apr 6
Profile Iconvamoalrenga and John Ferrell joined GarageLab (arduino, electronics, robotics, hacking)
Apr 3
Marcelo Rodrigues replied to FiniousFingers's discussion New to group
"Yes, please share your progress here. Thanks and good"
Mar 27
FiniousFingers replied to FiniousFingers's discussion New to group
"Thanks, good to know someone is out there. I will be…"
Mar 27
Edward Evans replied to GarageLab's discussion Serious claims against BeagleBone's manufacturer CircuitCo
"Have you moved forward with any action?  I would be interested in discussing your…"
Mar 27
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."
Mar 23
Profile IconWesenachin Asfaw and Muhammad Basil joined GarageLab (arduino, electronics, robotics, hacking)
Mar 23
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…"
Mar 23
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
Mar 23
Profile IconDan Urbauer, Bjorn and Jiaming Zhao joined GarageLab (arduino, electronics, robotics, hacking)
Mar 22
FiniousFingers is now a member of GarageLab (arduino, electronics, robotics, hacking)
Mar 20
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

© 2017   Created by Marcelo Rodrigues.   Powered by

Badges  |  Report an Issue  |  Terms of Service