I've been trying to get my Stepper motor to work for a very long time now and I'm just stuck at this point. The motor keeps vibrating back and forth and not turning correctly. The code I am using is just a simple example code from a tutorial video. The Motor I am using is a Two trees Nema 17 if that matters, with a 12 Volt plugin from the wall. I believe it may be the wiring but I am not sure`// Define pin connections & motor's steps per revolution. Here's my wiring and code (Ignore the buttons).
const int dirPin = 4;
const int stepPin = 3;
const int stepsPerRevolution = 200;
int stepDelay=400;
void setup()
{
// Declare pins as Outputs
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
}
void loop()
{
//clockwise
digitalWrite(dirPin, HIGH);
// Spin motor
for(int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(stepDelay);
digitalWrite(stepPin, LOW);
delayMicroseconds(stepDelay);
}
delay(2000); // Wait 2 seconds
//counterclockwise
digitalWrite(dirPin, LOW);
// Spin motor
for(int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(stepDelay);
digitalWrite(stepPin, LOW);
delayMicroseconds(stepDelay);
}
delay(2000); // Wait 2 seconds
}


