A stepper motor lets you move things in small, exact steps. Using a driver module helps control the motor easily and safely.
Stepper motor with driver module in Arduino
1. Connect stepper motor wires to the driver module. 2. Connect driver module pins to Arduino (power, ground, control pins). 3. Use Arduino code to send step and direction signals to the driver. Example Arduino code structure: const int stepsPerRevolution = 200; const int stepPin = 8; const int dirPin = 9; void setup() { pinMode(stepPin, OUTPUT); pinMode(dirPin, OUTPUT); } void loop() { // Forward full revolution digitalWrite(dirPin, HIGH); for (int i = 0; i < stepsPerRevolution; i++) { digitalWrite(stepPin, HIGH); delayMicroseconds(1000); digitalWrite(stepPin, LOW); delayMicroseconds(1000); } delay(1000); // Backward full revolution digitalWrite(dirPin, LOW); for (int i = 0; i < stepsPerRevolution; i++) { digitalWrite(stepPin, HIGH); delayMicroseconds(1000); digitalWrite(stepPin, LOW); delayMicroseconds(1000); } delay(1000); }
Stepper motors move in fixed steps, so you control how many steps to turn.
The driver module handles the power and switching for the motor coils.
const int stepsPerRevolution = 200; const int stepPin = 8; const int dirPin = 9; void setup() { pinMode(stepPin, OUTPUT); pinMode(dirPin, OUTPUT); } void loop() { // Move half revolution forward digitalWrite(dirPin, HIGH); for (int i = 0; i < stepsPerRevolution / 2; i++) { digitalWrite(stepPin, HIGH); delayMicroseconds(500); digitalWrite(stepPin, LOW); delayMicroseconds(500); } delay(500); // Move half revolution backward digitalWrite(dirPin, LOW); for (int i = 0; i < stepsPerRevolution / 2; i++) { digitalWrite(stepPin, HIGH); delayMicroseconds(500); digitalWrite(stepPin, LOW); delayMicroseconds(500); } delay(500); }
#include <AccelStepper.h> AccelStepper stepper(AccelStepper::DRIVER, 3, 4); void setup() { stepper.setMaxSpeed(1000); stepper.setAcceleration(500); } void loop() { stepper.moveTo(200); stepper.runToPosition(); delay(1000); stepper.moveTo(0); stepper.runToPosition(); delay(1000); }
This program controls a stepper motor using a driver module connected to two pins: one for step pulses and one for direction. It moves the motor 200 steps forward, waits, then 200 steps backward, and repeats.
#include <Stepper.h> const int stepsPerRevolution = 200; // Pins connected to the driver module inputs const int stepPin = 3; const int dirPin = 4; void setup() { pinMode(stepPin, OUTPUT); pinMode(dirPin, OUTPUT); Serial.begin(9600); Serial.println("Stepper motor control start"); } void loop() { // Rotate motor 200 steps forward digitalWrite(dirPin, HIGH); // set direction forward for (int i = 0; i < 200; i++) { digitalWrite(stepPin, HIGH); delayMicroseconds(1000); digitalWrite(stepPin, LOW); delayMicroseconds(1000); } Serial.println("Moved 200 steps forward"); delay(1000); // Rotate motor 200 steps backward digitalWrite(dirPin, LOW); // set direction backward for (int i = 0; i < 200; i++) { digitalWrite(stepPin, HIGH); delayMicroseconds(1000); digitalWrite(stepPin, LOW); delayMicroseconds(1000); } Serial.println("Moved 200 steps backward"); delay(1000); }
Make sure your power supply matches the motor and driver requirements to avoid damage.
Use delays carefully; too fast stepping can cause the motor to miss steps.
Check wiring twice before powering up to prevent short circuits.
Stepper motors move in small, exact steps controlled by pulses.
Driver modules make controlling stepper motors easier and safer.
Arduino code sends step and direction signals to move the motor as needed.
