28BYJ-48 with ULN2003 driver
28BYJ-48
The 28BYJ-48 is a geared stepper motor. One whole revolution are around 2048 steps (32 steps of the stepper motor with a 64:1 gear).
The voltage of those motors differ, e.g. 5V or 12V. See the sticker on the motor for clarification.
ULN2003
The 28BYJ-48 stepper motor comes often in a kit with a ULN2003 motor driver. It has a plug for the motor, pins for the energy source of the motor, and also usually IN1-IN4 as inputs for the steps.
To provide it with power, connect the power input (labeled with 5-12V), which should match the motor, and provide enough current for the motor. Do not use the pins of microcontroller for this.
Then connect 4 pins of a microcontroller with the pins IN1-IN4. You need to "walk" those pins to turn the motor, walk in the different direction to switch the rotation.
Example
For example, to create full steps, you could use a matrix:
const uint8_t steps[][4] = {
{1, 0, 0, 0},
{0, 1, 0, 0},
{0, 0, 1, 0},
{0, 0, 0, 1},
};
void writeStepper()
{
digitalWrite(IN1, steps[step][0]);
digitalWrite(IN2, steps[step][1]);
digitalWrite(IN3, steps[step][2]);
digitalWrite(IN4, steps[step][3]);
}
The variable step stores the current step position. Make sure to never leave the array size.
To make half steps (which are then 4096 steps per revolution), you add steps between, which activates the current and the next step.
const uint8_t steps[][4] = {
{1, 0, 0, 0},
{1, 1, 0, 0},
{0, 1, 0, 0},
{0, 1, 1, 0},
{0, 0, 1, 0},
{0, 0, 1, 1},
{0, 0, 0, 1},
{1, 0, 0, 1},
};