Hi all,
I'm a beginner and this is my first post, so I apologize in advance if I don't follow the forum guidelines correctly.
I'm trying to power a stepper motor with an Arduino Uno and the Arduino Motor Shield Rev3. Here are the technical specifications of the motor:
I'm using a 12V/4A power supply for the motor shield, and powering the Arduino from the USB cable.
I'm running a simple test program just to try and turn the motor for the first time. I've copied it from this Makerguides tutorial.
/* Example sketch to control a stepper motor with Arduino Motor Shield Rev3, Arduino UNO and Stepper.h library. More info: https://www.makerguides.com */
// Include the Stepper library:
#include <Stepper.h>
// Define number of steps per revolution:
const int stepsPerRevolution = 200;
// Give the motor control pins names:
#define pwmA 3
#define pwmB 11
#define brakeA 9
#define brakeB 8
#define dirA 12
#define dirB 13
// Initialize the stepper library on the motor shield:
Stepper myStepper = Stepper(stepsPerRevolution, dirA, dirB);
void setup() {
// 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);
// Set the motor speed (RPMs):
myStepper.setSpeed(20);
}
void loop() {
// Step one revolution in one direction:
myStepper.step(200);
delay(2000);
//Step on revolution in the other direction:
myStepper.step(-200);
delay(2000);
}
When I run the code, the motor will make one or two good turns, then quickly degenerate into stuttering and shaking. When this happens I quickly unplug it because I'm nervous about damaging my boards.
I've double checked the wiring, since the motor turns well initially, I don't think I've made a mistake here.
Two potentially important points are, I set the wires wrong at first - two positives to one coil and two grounds to the other - and then fixed it when I realized my mistake. I've cut the Vin bridge on the back of the motor shield, but I tried it a few times before I did that. I hope that one of these hasn't somehow damaged my boards!
Thanks in advance for any advice for what could be causing this problem.
EDIT: fixed the code snippet, it didn't paste properly at first
