Electronic – Arduino Motor Shield for 12v stepper motor

arduinostepper motor

I'm making a basic rig for timelapse photography using arduino.
It is a panning system for a DSLR camera, so I went with the motor shield from Arduino with the L298 chip and a 12V, 1.7A stepper motor. Before I could power the motor shield externally I noticed that the motor was running fine off of the 5V USB supplied to the Arduino board. It was able to fully move the DSLR around at different speeds and hold it in place.

The problem arose when it was asked to do a single step at a time (I assume setting up any speed here will do). I noticed that not all steps are equal. Sometimes, there would 2 small steps followed by a larger step or even the other way around. From my understanding, stepper motors have fixed step size, and either it will fully do it (provided with enough power), or it will fail, is that correct? I thought it will fully overcome the inertia, and not get stuck half way, and then work fine other times.

So is the motor/5v power or my code is at fault here? Providing external power would require me to cut a trace on the shield so I'm holding out on that till I'm sure. (also having a single power supply would be nice!)

Here is the generic code I'm using:

#include <Stepper.h>

 const int stepsPerRevolution = 1024;
 Stepper myStepper(stepsPerRevolution, 12,13);     

// give the motor control pins names:
 const int pwmA = 3;
 const int pwmB = 11;
 const int brakeA = 9;
 const int brakeB = 8;
 const int dirA = 12;
 const int dirB = 13;

 int times = 120;//420
void setup() {
 Serial.begin(9600);
 // set the PWM and brake pins so that the direction pins  // can be used to control the motor:
pinMode(pwmA, OUTPUT);
pinMode(pwmB, OUTPUT);
pinMode(brakeA, OUTPUT);
pinMode(brakeB, OUTPUT);
digitalWrite(pwmA, HIGH);
digitalWrite(pwmB, HIGH);
digitalWrite(brakeA, LOW);
digitalWrite(brakeB, LOW);

// initialize the serial port:
Serial.begin(9600);
// set the motor speed (for multiple steps only):
myStepper.setSpeed(2);
}

void loop() {
  while(times>0){
    myStepper.step(1);
    Serial.println(times);
    times--;
    delay(12000);
   }

  }

Best Answer

If the motor is rated for 12V and 1.7A, then supply it with this. USB can supply 5V at a maximum of 500mA, so instead of a maximum of 12V * 1.7A = 20.4W you have a maximum of 5V * 500mA = 2.5W. That's big difference.
My guess is that due to the DSLR's inertia and the weak stepper coil drive, it it slipping occasionally (or something similar)
Also, from a previous question I recall the Arduino motor shield is not the best design - the L298 drops a volt or two through both it's source and sink drive transistors so you will end up with even less power available, maybe around a watt (see source/sink saturation voltage in the datasheet spec table)

The basic code looks okay, but it's impossible to say for certain as all the real functionality is tucked away in the stepper library. I'll assume this is probably okay if it's a commonly used library that's been around for some time.

So, yes, supply the motor with the 12V and at least 1.7A. If you have to cut the trace then do this, it easy to solder it back later if you need to (make sure there is no jumper on the motor board first though, I have a feeling I remember a jumper for the purpose of an external supply on one of these shields)