I did it. I got the cicuit for the stepper motor running via my 12v VIN Ardunio.
This is exciting as Stepper motors for the mechanics to move robot arms, wheels and such things.
They can move in very small increments. In my reading I learned how they are built and work. Basically they are magnetic, and have a number of poles in them.
As you apply the current to one part, you activate a small electromagnet which makes the rotor 'step' a little. Mine is 4 pole, if I do the Poles in the right order, I can make it turn one revolution. Reverse the order and the motor steps in the other direction. Thats a very basic explanation, but in short I could now build my small photography platform I was hoping for. More on that later.
The great news is I didn't cook the board this time ! ... and the code works well.
Below is a video of Robbie moving his arms for his very first time. Ain't he just gorgeous!
Click here for the video !
And below is my code...
//#include <Stepper.h>
int in1Pin = 8;
int in2Pin = 9;
int in3Pin = 10;
int in4Pin = 11;
int ndelay = 100 ;
void setup()
{
pinMode(in1Pin, OUTPUT);
pinMode(in2Pin, OUTPUT);
pinMode(in3Pin, OUTPUT);
pinMode(in4Pin, OUTPUT);
Serial.begin(9600);
//motor.setSpeed(20);
}
void loop()
{
for (int ctr = 0; ctr < 12; ctr++) {
backward();
}
for (int ctr = 0; ctr < 12; ctr++) {
forward();
}
}
void forward()
{
digitalWrite(in1Pin, HIGH); //1
digitalWrite(in2Pin, LOW);
digitalWrite(in3Pin, LOW);
digitalWrite(in4Pin, LOW);
delay(ndelay);
digitalWrite(in1Pin, LOW); //2
digitalWrite(in2Pin, HIGH);
digitalWrite(in3Pin, LOW);
digitalWrite(in4Pin, LOW);
delay(ndelay);
digitalWrite(in1Pin, LOW); //3
digitalWrite(in2Pin, LOW);
digitalWrite(in3Pin, HIGH);
digitalWrite(in4Pin, LOW);
delay(ndelay);
digitalWrite(in1Pin, LOW); //4
digitalWrite(in2Pin, LOW);
digitalWrite(in3Pin, LOW);
digitalWrite(in4Pin, HIGH);
delay(ndelay);
}
void backward()
{
digitalWrite(in1Pin, LOW); //4
digitalWrite(in2Pin, LOW);
digitalWrite(in3Pin, LOW);
digitalWrite(in4Pin, HIGH);
delay(ndelay);
digitalWrite(in1Pin, LOW); //3
digitalWrite(in2Pin, LOW);
digitalWrite(in3Pin, HIGH);
digitalWrite(in4Pin, LOW);
delay(ndelay);
digitalWrite(in1Pin, LOW); //2
digitalWrite(in2Pin, HIGH);
digitalWrite(in3Pin, LOW);
digitalWrite(in4Pin, LOW);
delay(ndelay);
digitalWrite(in1Pin, HIGH); //1
digitalWrite(in2Pin, LOW);
digitalWrite(in3Pin, LOW);
digitalWrite(in4Pin, LOW);
delay(ndelay);
}


No comments:
Post a Comment