Sub topic 1
How a Stepper Motor Turns Pulses into Steps
Prerequisites
This chapter assumes you can do the following:
- Write basic Arduino sketches using
setup,loop,digitalWrite, anddelayMicroseconds. - Apply Ohm's law to voltage, current, and resistance.
- Read a simple wiring diagram.
- Use a breadboard and an external power supply.
No stepper hardware is required to follow the chapter. Later chapters cover wiring, drivers, and current limits in detail.
The core idea: position from pulses
A stepper motor is a brushless DC motor that turns in fixed angular increments called steps. A DC motor spins as long as it has power, and you control its speed and position indirectly. A stepper moves a known angle each time the controller switches which coils are energized. If you count the switching events, you know how far the shaft has turned.
This is called open-loop control. The controller sends commands and assumes the shaft followed them. No sensor reports the real position. That assumption holds while the motor has enough torque for the load. It fails when the motor misses steps, which a later chapter covers.
A typical motor has a step angle of 1.8°. A full turn is 360°, so:
steps per revolution = 360 / step angle = 360 / 1.8 = 200A 0.9° motor has 400 steps per revolution. The step angle is fixed by the motor's construction, not by your code.
Inside the motor
A stepper has two main parts.
- The rotor is the rotating part on the shaft. In a hybrid stepper, the most common type for hobby and 3D-printer work, it is a permanent magnet with two toothed iron caps. The caps are offset by half a tooth, and they have opposite magnetic polarity.
- The stator is the fixed housing. It carries electromagnet poles wound with copper coils, and the poles also have fine teeth.
A common 200-step motor has a rotor with 50 teeth. Each full-step moves the rotor a quarter of a tooth pitch. That gives 50 × 4 = 200 steps per revolution.
The coils are wired as two phases, usually called A and B. Each phase is a pair of coils that are driven together. Current through a phase magnetizes its stator poles. The rotor's magnetized teeth then snap into alignment with the energized poles, because opposite poles attract and the rotor seeks the lowest-energy position.
The four-state sequence
The simplest drive method, full-step with both phases on, energizes the two phases in a repeating cycle. Each phase can carry current in either direction, which flips its magnetic polarity. Write the current direction as + or −.
| State | Phase A | Phase B |
|---|---|---|
| 1 | + | + |
| 2 | − | + |
| 3 | − | − |
| 4 | + | − |
Moving from state 1 to 2 reverses only phase A. The stator field rotates by one step, and the rotor follows. Going through states 1, 2, 3, 4, 1, … turns the shaft one way. Going 4, 3, 2, 1 turns it the other way. After four states the pattern repeats, and the rotor has moved four steps.
You rarely produce this sequence yourself. A stepper driver reads a STEP pulse and a DIR level, then handles the phase sequencing and the current in each coil. The sequence itself is the subject of the full-step, half-step, and wave drive chapter.
Holding torque and detents
When the coils hold current but the controller sends no pulses, the rotor stays locked at its position. The force that resists being turned is the holding torque. This is a useful property, because a stepper can hold a load without moving. It also means the motor draws current and gets warm while standing still.
A hybrid stepper also has detent torque. The permanent magnet pulls the rotor toward tooth positions even when no coil is energized. You feel this as a ratcheting resistance when you turn an unpowered motor by hand.
How the step rate sets the speed
Each STEP pulse moves the shaft one step, so speed follows directly from the pulse rate:
steps per second = RPM × steps per revolution / 60
RPM = steps per second × 60 / steps per revolutionFor a 200-step motor at 250 steps per second:
RPM = 250 × 60 / 200 = 75The first code example drives a STEP/DIR driver at exactly this rate. It toggles STEP HIGH for 2000 µs and LOW for 2000 µs, so the period is 4000 µs and the rate is 1 / 0.004 s = 250 steps per second.
const int STEP_PIN = 3;
const int DIR_PIN = 4;
void setup() {
pinMode(STEP_PIN, OUTPUT);
pinMode(DIR_PIN, OUTPUT);
digitalWrite(DIR_PIN, HIGH); // choose direction
}
void loop() {
// One step per rising edge on STEP.
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(2000);
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(2000); // 4000 us period = 250 steps/s
}The driver acts on the rising edge of STEP. The 2 ms high time is much longer than drivers need, since many accept pulses of a few microseconds. Here the high and low times are equal only for simplicity. The pulse rate is what sets the speed, not the pulse width.
Why the motor needs a driver
A motor coil is a low-resistance inductor. A 12 V supply across a coil with 1.5 Ω resistance would push 8 A through it if nothing limited the current. An Arduino pin is rated for about 20 mA, and 40 mA is the absolute maximum on an ATmega328P. The numbers differ by orders of magnitude.
A driver does three jobs the microcontroller cannot:
- It switches the coil current in both directions using H-bridges.
- It limits the current to the motor's rating, usually by chopping the supply.
- It turns a simple STEP/DIR interface into the correct phase sequence.
Later chapters cover each of these.
What limits real motion
Ideal stepping would let the rotor jump instantly from one position to the next. In practice the rotor has inertia, and the coil current needs time to build up because of the coil's inductance. At each step the rotor overshoots slightly and rings back, which you hear as vibration at some speeds. As the step rate rises, there is less time per step for current to build, so torque falls.
If the load needs more torque than the motor can produce at that speed, the rotor cannot follow the field. The field moves on to the next step while the rotor lags, and the motor misses steps. With open-loop control the controller does not know. Its step count and the shaft's true position then disagree, and the error stays until you re-home the axis.
Common mistakes at this stage
- Mixing up step angle and steps per revolution. The two are reciprocal quantities. Use 360 divided by the step angle.
- Assuming a higher step rate is always better. Speed is limited by torque, not by what the Arduino can output.
- Expecting the shaft to match commands without checking load. Open-loop systems need a margin of torque.
- Forgetting that a stopped motor still draws current. A held position costs power and creates heat.
Exercise
A stepper motor has a 0.9° step angle. You want it to turn at 120 RPM in full-step mode. How many steps per revolution does it have, what step rate in steps per second is needed, and what delay in microseconds goes between rising edges of STEP?
Show answer
Steps per revolution = 360 / 0.9 = 400. Step rate = 120 × 400 / 60 = 800 steps per second. The period between rising edges is 1 / 800 s = 1250 µs. In the style of the example sketch, that is 625 µs high and 625 µs low.
Exercise
Your sketch sends 1000 step pulses to a 200-step motor, but the shaft ends up about a quarter turn short of the expected 5 revolutions. The code is correct. What is the most likely cause, and why does the Arduino not detect it?
Show answer
The motor most likely missed steps because the load or the speed demanded more torque than the motor could deliver. About 50 steps (a quarter of 200) were lost. The Arduino cannot detect this because the control is open-loop: it counts the pulses it sent, and no sensor reports the real shaft position.