Sub topic 9
Sending STEP and DIR Signals
This chapter assumes you know Arduino setup(), loop(), digitalWrite(), and delayMicroseconds(). You should also understand basic voltage levels and how to read a simple wiring diagram.
A step-and-direction driver separates motion commands into two digital signals:
DIRselects the rotation direction.STEPadvances the motor by one configured step when it receives a pulse.
The driver handles coil current and the motor's winding sequence. The Arduino only sends timing and direction information.
How the signals work
Most drivers move the motor on the rising edge of STEP, which is the transition from LOW to HIGH. One rising edge usually means one full step or one microstep, depending on the driver's microstepping settings.
Set DIR before sending the first step pulse. Drivers require a short setup time between changing DIR and raising STEP. A delay of a few microseconds is safe for many boards, but check the driver's datasheet for exact limits.
Connect the Arduino signal ground to the driver's signal ground. Without a shared reference, the driver may not recognize the HIGH and LOW levels correctly. Connect STEP and DIR to the matching input terminals. Power the motor from the driver's separate motor supply, not from an Arduino I/O pin.
| Signal | Purpose | Typical action |
|---|---|---|
| `STEP` | Advances the motor | Send a pulse for each step |
| `DIR` | Selects direction | Set HIGH or LOW before stepping |
| `GND` | Provides a signal reference | Connect Arduino and driver grounds |
Generating a constant step rate
The following sketch sends one step every 4,000 microseconds. This produces 250 steps per second. A 200-step motor in full-step mode therefore turns at 75 RPM:
250 steps/s × 60 s/min ÷ 200 steps/revolution = 75 RPM
const int STEP_PIN = 3;
const int DIR_PIN = 4;
void setup() {
pinMode(STEP_PIN, OUTPUT);
pinMode(DIR_PIN, OUTPUT);
digitalWrite(STEP_PIN, LOW);
digitalWrite(DIR_PIN, HIGH);
delayMicroseconds(10); // DIR setup time
}
void loop() {
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(2000); // pulse width
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(2000); // completes a 4000 us period
}The pulse frequency determines speed. The direction level determines which way the motor turns. If the motor rotates opposite to your expected direction, invert the DIR level or reverse one mechanical convention in your application.
Common signal faults
A motor that hums without turning often has one or both coil pairs wired incorrectly, but incorrect signal timing can cause similar behavior. Check these items:
- Confirm that
STEPandDIRare connected to the driver's input pins, not motor outputs. - Confirm that Arduino ground and driver signal ground are connected.
- Check that the pulse stays HIGH and LOW for at least the driver's minimum time.
- Make sure
DIRis stable before the firstSTEPrising edge. - Start at a slow step rate before testing faster motion.
Exercise
A 200-step motor uses 8× microstepping. How many STEP pulses are needed for one revolution, and what pulse rate produces 60 RPM?
Show answer
It needs 200 × 8 = 1,600 pulses per revolution. The required rate is 60 × 1,600 ÷ 60 = 1,600 pulses per second.