Pages: [1]   Go Down
Author Topic: Unipolar stepper - one direction  (Read 179 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 146
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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);
}
Logged

Offline Offline
Edison Member
*
Karma: 56
Posts: 2187
The last thing you did is where you should start looking.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 146
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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. 
Logged

Pages: [1]   Go Up
Jump to: