I'm having trouble with a stepper motor.
Okay, so I'm still quite new to using an Arduino, so this is based on a tutorial I found on youtube (which I'll link at the end of the post).
I'm just trying to get the motor to move at the moment, but it keeps getting stuck every few seconds. If I twist it hard enough, it'll change back to turning the way it should, but it'll still get stuck again after a few seconds. The other sticking problem is that it will automatically be stuck when I change the direction of the motor in the programming. I'm 99% sure the it's not a problem with the programming, because I completely copied it from the video after it stopped working.
The thing that I think it could be is a battery problem, because I had to attach another battery onto the Arduino (9V), after the original hadn't worked.
Link to video: Control Stepper motor 28BYJ-48 with ULN2003 for Arduino - YouTube
Here's the code by the way:
int Pin1 = 10;
int Pin2 = 11;
int Pin3 = 12;
int Pin4 = 13;
int _step = 0;
boolean dir = true;// false=clockwise, true=counter clockwise
int count=0;
void setup()
{
pinMode(Pin1, OUTPUT);
pinMode(Pin2, OUTPUT);
pinMode(Pin3, OUTPUT);
pinMode(Pin4, OUTPUT);
}
void loop()
{
switch(_step){
case 0:
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, LOW);
digitalWrite(Pin4, HIGH);
break;
case 1:
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, HIGH);
digitalWrite(Pin4, HIGH);
break;
case 2:
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, HIGH);
digitalWrite(Pin4, LOW);
break;
case 3:
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, HIGH);
digitalWrite(Pin3, HIGH);
digitalWrite(Pin4, LOW);
break;
case 4:
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, HIGH);
digitalWrite(Pin3, LOW);
digitalWrite(Pin4, LOW);
break;
case 5:
digitalWrite(Pin1, HIGH);
digitalWrite(Pin2, HIGH);
digitalWrite(Pin3, LOW);
digitalWrite(Pin4, LOW);
break;
case 6:
digitalWrite(Pin1, HIGH);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, LOW);
digitalWrite(Pin4, LOW);
break;
case 7:
digitalWrite(Pin1, HIGH);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, LOW);
digitalWrite(Pin4, HIGH);
break;
default:
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, LOW);
digitalWrite(Pin3, LOW);
digitalWrite(Pin4, LOW);
break;
}
if(dir){
_step++;
}else{
_step--;
}
if(_step>7){
_step=0;
}
if(_step<0){
_step=7;
}
delay(1);
}