Stepper motor

In this post you will see:

  1.  how to drive a stepper motor using Arduino Meg2560 with pololu driver board.
  2. precautions and troubleshoots.
  3. wiring the circuit together
  4. demonstration(video)

First thing you want to do is soldering the male pin heads to the polou board:

Then you need to do the wirings:
Pay attention to the following precautions:

  1. positive and negative of the power source to the motor, if you reversed them it won’t          turn(luckily it won’t fry also, but don’t count on that!).
  2. NEVER disconnect the power off the motor while the polou board is powered. That means: first dissconnect the power from the polou board then disconnect the power off the motor. Very Important.
  3. if your motor vibrates without turning OR if it turns in a wired way, that means you connected the wires of the motor(A1,A2,B1,B2) wrong, try to reconnect them, until you find the correct wiring(sometimes/all times, datasheet wiring might not match your case.)

Wiring the motor,Polou, Arduino togather

As i stated above, the motor wiring might differ from brand to another, so i will show a general way of doing so:

those are the relevant wirings you need to make

the picture above might not say much, so here is a full circuit diagram:

pay attention that the VDD is the 5volt of the arduino used to power up the polou, and VMOT is the 12volt for powering the motor itself.

**Both pictures above are taken from polou website.
connect the GND of the Arduino to the GND of the Polou, and the negative pole of the motor 12volt power source to the other GND of the Polou, while the poitive pole of the 12volt goes for the VMOT input.

Arduino Code

steppercode

#define Direction 8
# define Step 9
void setup() { 
 pinMode(Direction, OUTPUT); 
 pinMode(Step, OUTPUT);
 digitalWrite(Direction, LOW);
 digitalWrite(Step, LOW);
}
int count = 0;
void loop() {
 digitalWrite(Step, HIGH);
 delay(1);//control the speed of the motor, 1ms is just an example
 digitalWrite(Step, LOW); 
 delay(1); //control the speed of the motor
 count++; //counting steps
 
//revers the direction of the turn.250 is just an example
 if(count == 250){
 if(digitalRead(Direction)==HIGH){
     digitalWrite(Direction,LOW);
 }
 else if(digitalRead(Direction)==LOW) {
      digitalWrite(Direction,HIGH);
  }
 count = 0;//starting to count from 0 again
 } 
}

Demo

notice in the video how i disconnected the Arduino then the power off the motor when i changed the code and re-uploaded it to the Arduino

***HIGH Quality videos are coming soon!***

Control Board

Controlling one stepper motor is fairly simple and straight-forward, as we saw above, however, it’s not that organized in terms of wires, and i got extremely lost sometimes between the similar wires..So why not make an organized break-out board that handels everything?! well..

That control break-out has been designed to handle 4 stepper motors, however, in the demo test video bellow, i used just 2 motors since my power supply it too weak to provide enough current for those beasts:

Stay tuned for more. if you got any questions, leave a comment bellow, i’ll answer it!

Quick links:
project directory

 

2 thoughts on “Stepper motor

  1. Hello,
    I have a minor problem with my code for stepper motor – I wonder if you can help me?
    My basic code is working well in CW and CCW direction controlled by joystick but I did two tries of amendment and code does not want to give stepper the command…

    Please contact me if you have time to help me.

    Thanks,

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: