Lab: Controlling a Stepper Motor With an H-Bridge
In this lab I learned to control the functions of a stepper motor through a motor driver board that handles power functions for the motor and communicates with an Arduino.
The motor controller on hand was a A4988 Stepper Motor Driver Carrier from Pololu. The A4988 board pinout and basic wiring diagram here:
My setup with the Arduino Mega and a Nemo 12-volt stepper motor looked like this, running pins 2 (for direction) and 3 (for steps) from the Arduino:
Using a tutorial from MarkerGuides.com as a starting point I was able to run their Arduino sketch which is copied at the bottom of this page.
This is missing something…
Ah, much better.
It is interesting to consider that while using the motor driver board no libraries were necessary to control the Nema stepper motor.
// Define stepper motor connections and steps per revolution: #define dirPin 2 #define stepPin 3 #define stepsPerRevolution 200 void setup() { // Declare pins as output: pinMode(stepPin, OUTPUT); pinMode(dirPin, OUTPUT); } void loop() { // Set the spinning direction clockwise: digitalWrite(dirPin, HIGH); // Spin the stepper motor 1 revolution slowly: for (int i = 0; i < stepsPerRevolution; i++) { // These four lines result in 1 step: digitalWrite(stepPin, HIGH); delayMicroseconds(8000); digitalWrite(stepPin, LOW); delayMicroseconds(8000); } }