Skip to content

Instantly share code, notes, and snippets.

@samirsogay
Created August 23, 2019 16:00
Show Gist options
  • Save samirsogay/43b87d7830d98a54a6bff6f994b9ff16 to your computer and use it in GitHub Desktop.
Save samirsogay/43b87d7830d98a54a6bff6f994b9ff16 to your computer and use it in GitHub Desktop.
int bluePin = 2; //IN1 on the ULN2003 Board, BLUE end of the Blue/Yellow motor coil
int pinkPin = 3; //IN2 on the ULN2003 Board, PINK end of the Pink/Orange motor coil
int yellowPin = 4; //IN3 on the ULN2003 Board, YELLOW end of the Blue/Yellow motor coil
int orangePin = 5; //IN4 on the ULN2003 Board, ORANGE end of the Pink/Orange motor coil
//going up
//Keeps track of the current step.
//We'll use a zero based index.
int currentStep = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(bluePin, OUTPUT);
pinMode(pinkPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(orangePin,OUTPUT);
digitalWrite(bluePin, LOW);
digitalWrite(pinkPin, LOW);
digitalWrite(yellowPin, LOW);
digitalWrite(orangePin, LOW);
}
void loop() {
//Comment out the Serial prints to speed things up
//Serial.print("Step: ");
//Serial.println(currentStep);
switch(currentStep){
case 0:
digitalWrite(bluePin, HIGH);
digitalWrite(pinkPin, HIGH);
digitalWrite(yellowPin, LOW);
digitalWrite(orangePin, LOW);
break;
case 1:
digitalWrite(bluePin, LOW);
digitalWrite(pinkPin, HIGH);
digitalWrite(yellowPin, HIGH);
digitalWrite(orangePin, LOW);
break;
case 2:
digitalWrite(bluePin, LOW);
digitalWrite(pinkPin, LOW);
digitalWrite(yellowPin, HIGH);
digitalWrite(orangePin, HIGH);
break;
case 3:
digitalWrite(bluePin, HIGH);
digitalWrite(pinkPin, LOW);
digitalWrite(yellowPin, LOW);
digitalWrite(orangePin, HIGH);
break;
}
//CCW
//currentStep = (--currentStep >= 0) ? currentStep : 3;
//CW
currentStep = (++currentStep < 4) ? currentStep : 0;
//2000 microseconds, or 2 milliseconds seems to be
//about the shortest delay that is usable. Anything
//lower and the motor starts to freeze.
//delayMicroseconds(2250);
delay(15);
}
@123Sexyninja
Copy link

Hello, I am using this code and it works nearly perfectly for my simple needs. However, I simply want it to drive the motor in the opposite direction. I’m sure that the key to changing this is at lines 60-64. But, no matter what I try to do I can’t get it to drive the motor in reverse. Obviously I’m a total noob so thanks in advance for any assist and keeping it simple for this old man.

@samirsogay
Copy link
Author

Hi, just uncomment line 61 and comment out line 64.

@RMZNAYDEMR
Copy link

how can i increase speed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment