1. Home
  2. Docs
  3. New sna41 Arduino PS2 motor drive expansion board manual
  4. Step 5: Explain the software code
  5. 2, using stepper motor (Stepper Motors)

2, using stepper motor (Stepper Motors)

a) The drive board can be connected to two stepper motors at the same time, both unipolar and bipolar.

b) connecting the motor

In the figure above, the left is Bipolar stepper motors (4 lines), and the right is Unipolar Stepper Motor (6 lines).


  • Unipolar Stepper Motor (6-wire): First you need to know which wire is the centerline, then connect the centerline to the GND of the terminal (white and yellow on the right), and the remaining two ends (black and green) , red and blue) are respectively connected to M1, M2 or M3, M4.
  • Bipolar stepper motors (4-wire): Similar to a unipolar drive, the GND is left blank.

C) Stepper motor control example detailed explanation

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); ; 

// Connect a stepper motor with 200 steps per revolution (1.8 degree)
// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);

void setup() {
  AFMS.begin();  // create with the default frequency 1.6KHz
  myMotor->setSpeed(10);  // 10 rpm   

void loop() {
  //Single coil steps
  myMotor->step(100, FORWARD, SINGLE); 
  myMotor->step(100, BACKWARD, SINGLE); 

  //Double coil steps
  myMotor->step(100, FORWARD, DOUBLE); 
  myMotor->step(100, BACKWARD, DOUBLE);
  //Interleave coil steps
  myMotor->step(100, FORWARD, INTERLEAVE); 
  myMotor->step(100, BACKWARD, INTERLEAVE); 
  //Microstep steps
  myMotor->step(50, FORWARD, MICROSTEP); 
  myMotor->step(50, BACKWARD, MICROSTEP);

Create a MotorShield object:

Adafruit_MotorShield AFMS = Adafruit_MotorShield();

Create a StepperMotor object from MotorShield:

Adafruit_StepperMotor *myMotor = AFMS.getStepper(2002);

getStepper(steps, stepper#)

Steps: Steps per revolution, between 35~200

Stepper#: 1~2, M1, M2 are 1, M3, M4 are 2

Set the rotation speed:

setSpeed(rpm): rotation speed per minute

Running the motor:

step(#steps, direction, steptype)




*Please refer to the online information for the working characteristics of the stepper motor.

Was this article helpful to you? Yes No

Leave A Comment