Stepper motors are found in many thrown out electronic devices. Here's how I got one up and running.
Pull the stepper motor out from the chassis housing (usually only held down by a few screws). Next we have to identify what type of motor we have. Stepper motors are classed as either bipolar or unipolar depending on the coils that make up the stator.
Unipolar configuration consists of 2 phases per winding with a common tap in each coil that can either be joined to both windings or separate. With the common tap connected to Vcc, by controlling whether the phase terminals can pass current or not will switch them on or off. Since current only flows in one direction through any of the phases (from center tap to ground), this is where the name uni-polar comes from. When the current flows through one side of a winding, the magnetic field will be opposite in polarity compared to when the current flows through the other side.
Bipolar configuration consists of single coils per phase with current flowing in both directions, hence the name bi-polar. Before with unipolar, the current direction didn't have to change to alternate the magnetic field, however in bipolar configuration the current must be alternated in order to alternate the polarity of the magnetic field.
You can see that the first motor I found has 5 pins with the red one separated from the rest. The first step, as with any electronic device, is to check for product information on the component and hopefully find a data sheet. This motor in particular did have sufficient information to find a matching data sheet, but it's good practice to classify them using other techniques for instances where the exact model is unknown.
In order to determine the type of motor, I could take a guess and say that it is unipolar with 4 phases and a single common tap but it's worth checking our resistances to be sure. From the red wire to all the others is 34 Ohms while any combination of the 4 separate wires is 69 Ohms. With reference to the above diagram, it is clear that since 34 Ohms is smaller in resistance and occurs between the red wire and all others, that this is a common tap measuring resistance of half a winding. The 69 Ohms is from measuring across an entire winding which makes sense since 2 x 34 Ohm = 68 Ohm = approx. 69 Ohm. So from this test we conclude that this is indeed a 4 phase unipolar stepper motor.
Now that we know what kind of stepper motor we have, we can build a simple test circuit to get the thing moving. At the bottom left, the control pins for the motor can be connected to any TTL logic device you wish to use to run the motor (in my project I went with an arduino uno).
Stepper motors come in a range of voltage requirements so it's important to select the correct voltage for your motor. If you have access to the data sheet this will be easy enough but if you have an unidentified motor, it will require a little guess work. Your best option here is to connect the motor to 12V and read the current. The current per phase can typically range from 50 mA up to 850 mA in some instances under peak load but this is still an estimated range. If your motor is pulling more than 850 mA and gets very hot it could be an indication that your voltage is too high.
For this motor, it requires 24 V and has a peak current of 850 mA. Vcc is connected to the common tap on both windings and each phase is then connected to an NPN transistor. Make sure when selecting a transistor that the collector-emitter voltage rating is above your motor voltage and the collector current rating is above the current draw per phase of the motor. The resistor leading to the base of the transistor is to limit the current so select a value for R such that
Where V(base) is your transistor control voltage (5V from an arduino), V(BE) is your base emitter saturation voltage (found in the data sheet) and I(base) is the current flowing into the base of the transistor.
The minimum base current is determined by the DC current gain of the transistor (HFE) by
Where I(load) is the maximum current that the load draws through the transistor. As a rule of thumb, for a switching transistor, pick a minimum base current value that is approx. 5 times the absolute minimum you need.
Next we have to set up the control software to drive the motor. Each of the motor phases should be connected to a pin of your TTL control device such as a GPIO pin on an Arduino Uno. In order to turn the motor in either direction, we have to turn on each phase in a particular order.
The first and simplest form of control is the 1-1 phase excitation which excites each phase one at a time in a circular motion. Going through steps 1-4 will turn the motor one direction and reversing the step order will turn it the opposite direction. This form of control uses the least amount of power but sacrifices torque. The step resolution for this control will be the standard degree/step specified for the motor.
Another form of control is 2-2 phase excitation where two phases are active at the same time. This provides more torque than 1-1 phase excitation but consumes more power as two phases are powered at once.
For the motor I'm using I went with 2-2 phase excitation as it was specified by the data sheet. If you are using an Arduino, you will find a stepper library that has a few examples that work well with this setup. All you have to do is to change the pin numbers specified when initialising the stepper library.