Sub topic 12
A First Look at Stepper Motors
Assume you can upload Arduino sketches, use setup() and loop(), and read basic wiring diagrams. You should also understand that an Arduino pin provides a control signal, not motor power.
A stepper motor is a motor that turns in small, fixed increments called steps. Instead of applying one continuous voltage to make the shaft spin, a controller energizes the motor's internal coils in a sequence. Each change in the sequence moves the shaft to the next position.
Stepper motors are useful when you need controlled movement, such as moving a carriage, turning a dial, or feeding material a measured distance.
How a stepper motor works
A typical two-phase stepper motor has two coil groups. The driver energizes those coils in a particular order. Reversing the order reverses the direction.
The Arduino usually does not control the coils directly. It sends low-power signals to a stepper driver, which is a board that supplies the correct coil current from an external power source.
The most common interface has two control inputs:
- STEP: Each input pulse requests one step.
- DIR: The logic level selects the direction.
Some drivers also have ENABLE, SLEEP, or RESET inputs. The driver documentation tells you whether those inputs are active high or active low.
Step angle, speed, and torque
A motor's step angle is the angle moved by one full step. A motor rated at 1.8 degrees per step needs:
\[ 360 \div 1.8 = 200 \]
full steps for one revolution.
Many drivers support microstepping. Microstepping divides each full step into smaller commanded increments, such as know? 1/2, 1/4, or 1/16. It can make motion quieter and smoother, but it does not guarantee the same increase in positioning accuracy. Load, vibration, and missed steps still matter.
Stepper motors can hold position while energized, which is called holding torque. They consume current and become warm even when they are not turning. Their available torque usually falls as speed increases. If the load is too large or acceleration is too sudden, the motor can miss steps. The Arduino does not automatically know that this happened.
| Property | Stepper motor | Hobby servo |
|---|---|---|
| Position feedback | Usually none | Usually internal feedback |
| Command style | Step pulses and direction | Position signal |
| Typical motion | Repeated rotation or travel | Bounded angular position |
| Main failure | Missed steps | Stall or limited travel |
Wiring and driver settings
Never connect a stepper motor coil directly to Arduino pins. The coils need more current than an I/O pin can safely provide, and switching them creates electrical stress.
Connect the driver's logic ground to Arduino GND, and power the motor side from the voltage specified by the driver and motor. Set the driver's current limit before running the motor. A wrong setting can cause weak motion, overheating, or permanent damage.
The following example assumes a STEP/DIR driver. The exact pulse timing and enable logic differ between driver boards, so check the board's datasheet.
const int STEP_PIN = 3;
const int DIR_PIN = 4;
const int STEPS_PER_REV = 200;
void setup() {
pinMode(STEP_PIN, OUTPUT);
pinMode(DIR_PIN, OUTPUT);
}
void moveSteps(long count, bool clockwise) {
digitalWrite(DIR_PIN, clockwise ? HIGH : LOW);
for (long i = 0; i < count; i++) {
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(800);
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(800);
}
}
void loop() {
moveSteps(STEPS_PER_REV, true);
delay(1000);
moveSteps(STEPS_PER_REV, false);
delay(1000);
}This sketch turns the motor one full revolution in each direction if the driver is set to full-step mode and the motor has 200 full steps per revolution. At higher speeds, use acceleration rather than instantly requesting a fast pulse rate. Libraries such as AccelStepper can generate step timing and acceleration profiles.
Exercise
Why does a stepper motor need a driver board instead of being connected directly to Arduino pins?
Show answer
The driver supplies and switches the higher coil current, while the Arduino provides only the low-power STEP and DIR control signals.