Author Options:

Arduino motor shield, do the shields not use the same stepper motor sketches or commands? Answered

ok, I have an arduino uno and arduino motorshield. My stepper is a 1.8 degree 75 ohm motor, i can get it to run in one direction, or the other, but what I'm having trouble with is the code really, all the examples Ive been messing with don't seem compatible with the shield, all i want to do is make the stepper go one direction for "x" amount of steps then reverse the same number back, at a set rpm/speed, however when i try to give it step commands it does nothing, seems like i have to use the digital pins to control speed. but that's not exactly working for me. I'm sure this is an easy code for anyone who has used an arduino , but Ive only had this for 4 days and spent the last 2 researching and learning code, I'm getting frustrated. I thought getting the motor shield would make this easier...but it seems to over complicate, maybe not .maybe Ive just over analyzed this. if anyone has a code or recommendation for the arduino motor shield it would be greatly appreciated.

here is an example of something similar to what im trying to do, but im trying to get it to work on an arduino motor shield.(example from Tom Igoe)

Stepper Motor Controller
language: Wiring/Arduino

This program drives a unipolar or bipolar stepper motor.
The motor is attached to digital pins 8 and 9 of the Arduino.  //motor shield pins 8,9 are the motor brake, use other pins or is this //correct?

The motor moves 100 steps in one direction, then 100 in the other.

Created 11 Mar. 2007
Modified 7 Apr. 2007
by Tom Igoe


// define the pins that the motor is attached to. You can use
// any digital I/O pins.

#include <Stepper.h>

#define motorSteps 200     // change this depending on the number of steps
                           // per revolution of your motor
#define motorPin1 8
#define motorPin2 9
#define ledPin 13

// initialize of the Stepper library:
Stepper myStepper(motorSteps, motorPin1,motorPin2);

void setup() {
  // set the motor speed at 60 RPMS:

  // Initialize the Serial port:

  // set up the LED pin:
  pinMode(ledPin, OUTPUT);
  // blink the LED:

void loop() {
  // Step forward 100 steps:

  // Step backward 100 steps:


// Blink the reset LED:
void blink(int howManyTimes) {
  int i;
  for (i=0; i< howManyTimes; i++) {
    digitalWrite(ledPin, HIGH);
    digitalWrite(ledPin, LOW);



Best Answer 6 years ago

There are several stepper motor shields available, for example, Adafruit has one and there are others as well. One of the ones I have has an enable line and two motor drive lines for each of the two coils of the stepper motor. The above code does not explicitly set and enable pins so I assume they are always enabled by setting the pin to either ground or 5v. In a nutshell you need to identify specifically which motor shield you are using, ensure you have installed the appropriate stepper motor library, maybe run the motor test code that probably is available from the motor driver source and go from there.

Best Wishes


Answer 6 years ago

I have the Arduino motor shield R3, the same one used here, https://www.instructables.com/id/Arduino-Motor-Shield-Tutorial/.


Answer 6 years ago

Ah, I see.
This motor shield uses the following pins for the A channel:
D12 Direction
D3 PWM Speed
D9 Brake
A0 Current Sense

And for the B channel:
D13 Direction
D11 PWM Speed
D8 Brake
A1 Current Sense

Here are some links where others have solved your problem:

This link seems to say that the Motor Shield is not well suited for driving steppers: http://letsmakerobots.com/node/30999

but the first link shows it working so I don't know :-)


Answer 6 years ago

Awesome, the first link was exactly what I needed. Much appreciated, I would have never found the commands to digital write PWM, Ive only been at this for 5 days so I dont know much about programing.