HOW TO INTERFACE A UNI_POLAR STEPPER MOTOR WITH ARDUINO
hardware connections
* The in_1,2,3,4 pins of the motor driver port is connected to the digital 2,3,4,5 pins of the arduino respectively .
*connect the ground pin to the ground of the motor driver port to the ground of the arduino, and the negative terminal of the 5v power supply to the other ground of the arduino (ensure that there is a common ground between the arduino,motor driver port and the 5v power supply)
connect the 5v power to the vcc of the motor driver
*connect the 5 wires of the stepper motor to the motor driver port
make sure that the red wire is connected to pin no 5 , yellow wire to pin no 4 , pink to 3 and blue to 2 of the arduino .
programming the arduino
There are 4 steps , in each step only one pin is high , first the blue pin is high , then pink is high and so on .when pin 1 is high it gets energized and it drives the motor then the next pin is high it is energized and it drives the motor and so on . after pin 4 it automatically make pin 1 high and it continues the sequence till infinity.
The code is as follows
int bluePin = 2; //IN1 on the ULN2003 Board, BLUE end of the Blue/Yellow motor coil
int pinkPin = 3; //IN2 on the ULN2003 Board, PINK end of the Pink/Orange motor coil
int yellowPin = 4; //IN3 on the ULN2003 Board, YELLOW end of the Blue/Yellow motor coil
int orangePin = 5; //IN4 on the ULN2003 Board, ORANGE end of the Pink/Orange motor coil
//Keeps track of the current step.
//We’ll use a zero based index.
int currentStep = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(bluePin, OUTPUT);
pinMode(pinkPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(orangePin,OUTPUT);
digitalWrite(bluePin, LOW);
digitalWrite(pinkPin, LOW);
digitalWrite(yellowPin, LOW);
digitalWrite(orangePin, LOW);
}
void loop() {
//Comment out the Serial prints to speed things up
//Serial.print(“Step: “);
//Serial.println(currentStep);
switch(currentStep){
case 0:
digitalWrite(bluePin, HIGH);
digitalWrite(pinkPin, LOW);
digitalWrite(yellowPin, LOW);
digitalWrite(orangePin, LOW);
break;
case 1:
digitalWrite(bluePin, LOW);
digitalWrite(pinkPin, HIGH);
digitalWrite(yellowPin, LOW);
digitalWrite(orangePin, LOW);
break;
case 2:
digitalWrite(bluePin, LOW);
digitalWrite(pinkPin, LOW);
digitalWrite(yellowPin, HIGH);
digitalWrite(orangePin, LOW);
break;
case 3:
digitalWrite(bluePin, LOW);
digitalWrite(pinkPin, LOW);
digitalWrite(yellowPin, LOW);
digitalWrite(orangePin, HIGH);
break;
}
currentStep = (++currentStep < 4) ? currentStep : 0;
//2000 microseconds, or 2 milliseconds seems to be
//about the shortest delay that is usable. Anything
//lower and the motor starts to freeze.
//delayMicroseconds(2250);
delay(2);
}
0 responses on "how to interface stepper motor with arduino"