There are a number of different types of stepper motors, but in this tutorial we will specifically be addressing bipolar stepper motors. Bipolar stepper motors typically have 4 pins, which correspond to two coils. To use a stepper, you need to power these two coils in phase with alternating polarity.
To figure out which two pins make up a single coil, insert an LED into any two pins on its socket and rotate the motor shaft. If the LED lights up, you found one coil. The other two pins should make up the other coil.
To make a bipolar motor spin:
Power the first coil.
Next power the second coil with reverse polarity.
Then power the first coil with reverse polarity.
Finally, power the second coil.
To reverse the motor direction of a bipolar stepper, simply reverse the polarity of the second coil.
Here is code to make the stepper spin in one direction:
Here is code to make the stepper spin in the opposite direction: