Sub topic 2
Wiring the Motor and Powering the Driver
This chapter assumes you can write basic Arduino code (setup, loop, digitalWrite, delayMicroseconds), apply Ohm's law, and read a simple wiring diagram. You need a bipolar stepper motor, a step/direction driver such as an A4988 or DRV8825, an Arduino, a breadboard, and a separate motor supply.
Wiring the motor and powering the driver
A bipolar stepper has two coils, each with two wires. Use a multimeter in continuity mode to find the pairs: the two wires that beep belong to the same coil. Connect coil A to the driver's 1A and 1B outputs, and coil B to 2A and 2B. Reversing one wire within a pair flips that coil's polarity, and the motor then vibrates or stalls instead of turning.
Power the motor from its own supply on the VMOT and GND terminals, for example 12 V. Power the logic side from the Arduino's 5 V pin, and join all grounds. Place a 100 µF electrolytic capacitor across VMOT and GND close to the driver. Connect or disconnect motor wires only when the motor supply is off. Coil energy released during a disconnect can damage the driver.
Setting the driver's current limit
The current limit caps the current in each coil. Too little current gives weak torque. Too much overheats the motor and driver. On many A4988 boards, the limit follows this formula:
I_max = Vref / (8 × Rs)
Here Rs is the sense resistor value, often 0.1 Ω. Measure Vref with a multimeter between the potentiometer wiper and GND while the driver is powered.
For a motor rated at 1.0 A with Rs = 0.1 Ω, Vref = 8 × 0.1 × 1.0 = 0.8 V. Turn the potentiometer until the meter reads 0.8 V. Never set the limit above the motor's rated current.
Sending STEP and DIR signals
The driver advances the motor one step on each rising edge of STEP. DIR selects the direction: HIGH for one way, LOW for the other. Set DIR before the pulse, and hold STEP high for at least 1 µs. The program below turns the motor at 60 RPM.
const int STEP_PIN = 3;
const int DIR_PIN = 4;
const int STEPS_PER_REV = 200; // 1.8 degree motor, full-step
const float TARGET_RPM = 60.0;
unsigned long halfPeriodMicros;
void setup() {
pinMode(STEP_PIN, OUTPUT);
pinMode(DIR_PIN, OUTPUT);
digitalWrite(DIR_PIN, HIGH); // choose direction
halfPeriodMicros = (unsigned long)(60000000.0 / (TARGET_RPM * STEPS_PER_REV) / 2.0);
}
void loop() {
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(halfPeriodMicros);
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(halfPeriodMicros);
}Converting RPM to step timing
Steps per second equals RPM × steps per revolution ÷ 60. Each full step period in microseconds equals 1,000,000 ÷ steps per second. Each half of the STEP pulse lasts half that period.
| Speed (RPM) | Steps per second | Period per step (µs) | Half pulse (µs) |
|---|---|---|---|
| 60 | 200 | 5000 | 2500 |
| 120 | 400 | 2500 | 1250 |
| 300 | 1000 | 1000 | 500 |
Exercise:
Exercise
A 400-step motor runs at 120 RPM in full-step mode. What is the period of one step in microseconds, and how long is each half of the STEP pulse?
Show answer
Steps per second = 120 × 400 ÷ 60 = 800. Period = 1,000,000 ÷ 800 = 1250 µs. Each half of the pulse lasts 625 µs.