# about stepper motor

Joined Nov 21, 2018
243
Hello,
I am testing a 17sh4401 stepper motor by the example from Arduino, I saw the step forward and backward alternately when I used the example: oneStepAtATime, I shift the wires many ways, still same, why? it is nothing complex.

Code:
/*
Stepper Motor Control - one step at a time

This program drives a unipolar or bipolar stepper motor.
The motor is attached to digital pins 8 - 11 of the Arduino.

The motor will step one step at a time, very slowly.  You can use this to
test that you've got the four wires of your stepper wired to the correct
pins. If wired correctly, all steps should be in the same direction.

Use this also to count the number of steps per revolution of your motor,
if you don't know it.  Then plug that number into the oneRevolution
example to see if you got it right.

Created 30 Nov. 2009
by Tom Igoe

*/

#include <Stepper.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

int stepCount = 0;         // number of steps the motor has taken

void setup() {
// initialize the serial port:
Serial.begin(9600);
}

void loop() {
// step one step:
myStepper.step(1);
Serial.print("steps:");
Serial.println(stepCount);
stepCount++;
delay(500);
}

Joined Nov 21, 2018
243
The stepper motor be able to continuous running at the direction expected. the steps forward/backward alternately happened when tested it run step by step.

#### BobTPH

Joined Jun 5, 2013
2,433
If it is stepping back and forth, that should be fixed by reversing the connections on ONE of the windings.

Bob

#### KeepItSimpleStupid

Joined Mar 4, 2014
4,103
They place I picked doesn't know the voltage of the motor. 5, 12 and 24 are common.

What you could do is take a bipolar LED or 4 diodes and 4 LED's. and 4 current limiting resistors e.g 2 red and 2 green LED's.
Arrange it such that when + is in the pattern, the RED LED is lit in the + direction, green in the - direction for each winding.

Slow the pattern down low enough until you see the required pattern of polarity in the datasheet.

Once you have the "pattern", you can up the voltage and measure the current to find the voltage of the stepper.

Joined Nov 21, 2018
243
If it is stepping back and forth, that should be fixed by reversing the connections on ONE of the windings.

Bob
Thanks.
I have shift the wires in many ways, nothing change.

Joined Nov 21, 2018
243
They place I picked doesn't know the voltage of the motor. 5, 12 and 24 are common.

What you could do is take a bipolar LED or 4 diodes and 4 LED's. and 4 current limiting resistors e.g 2 red and 2 green LED's.
Arrange it such that when + is in the pattern, the RED LED is lit in the + direction, green in the - direction for each winding.

Slow the pattern down low enough until you see the required pattern of polarity in the datasheet.

Once you have the "pattern", you can up the voltage and measure the current to find the voltage of the stepper.
Thanks.

#### HardyM

Joined Jun 16, 2020
1
You have a bipolar stepper motor. Connect your motor as per the example in L298 datasheet (page 8 from the link above).
In1 should be inverted In2 - This is winding 1 signal
In3 should be inverted In4 - This is winding 2 signal
Now generate a 2 bit gray code and feed bit 1 to winding 1, and bit 2 to winding 2. (Check Optical encoder data - it outputs a gray code).
So output sequence for rotation is
In1 In2 In3 In4
0 1 0 1
1 0 0 1
1 0 1 0
0 1 1 0
Then repeat
Reverse the sequence for reverse rotation

Joined Nov 21, 2018
243
You have a bipolar stepper motor. Connect your motor as per the example in L298 datasheet (page 8 from the link above).
In1 should be inverted In2 - This is winding 1 signal
In3 should be inverted In4 - This is winding 2 signal
Now generate a 2 bit gray code and feed bit 1 to winding 1, and bit 2 to winding 2. (Check Optical encoder data - it outputs a gray code).
So output sequence for rotation is
In1 In2 In3 In4
0 1 0 1
1 0 0 1
1 0 1 0
0 1 1 0
Then repeat
Reverse the sequence for reverse rotation
Thanks.