Go Down

Topic: Unipolar stepper - one direction (Read 267 times) previous topic - next topic

ifugaopapercraft

Is this sketch the most direct method to run a unipolar stepper in one direction? Using the stepper library would seem to involve less code but I haven't been successful using it for a single direction.
Code: [Select]
int motorPin1 = 8;
int motorPin2 = 9;
int motorPin3 = 10;
int motorPin4 = 11;
int delayTime = 10;

void setup() {
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
}

void loop() {
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(delayTime);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(delayTime);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
delay(delayTime);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
delay(delayTime);
}

LarryD

Your code is OK.
Maybe play with the delay.
Do you have a common ground?
Your programming technique will improve as you become more knowledgeable.

What components are you using?
Show us how your motor is wired up, a schematic, a picture.
The way you have it in your schematic isn't the same as how you have it wired up!

ifugaopapercraft

I should have mentioned the ULN2003 to drive the motors. The sketch above I assume will run the stepper without this chip or the library. Fortunately, I adapted a much shorter sketch which works well. Thanks. 

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy