I want to make this motor rotate 12times per hour (ie 12rev/ hour) And there is
ID: 3791847 • Letter: I
Question
I want to make this motor rotate 12times per hour (ie 12rev/ hour)
And there is a original code below. How can I change the code to have 12rev/hour?
#define step_pin 3 // Define pin 3 as the steps pin
#define dir_pin 2 // Define pin 2 as the direction pin
#define MS1 5 // Define pin 5 as "MS1"
#define MS2 4 // Define pin 4 as "MS2"
int direction; // Variable to determine the sense of the motor
int steps = 1; // Number of steps that you want to execute (for full steps, 200 = 1 turn)
void setup() {
pinMode(MS1, OUTPUT); // Configures "MS1" as output
pinMode(MS2, OUTPUT); // Configures "MS2" as output
pinMode(dir_pin, OUTPUT); // Configures "dir_pin" as output
pinMode(step_pin, OUTPUT); // Configures "step_pin" as output
digitalWrite(MS1, LOW); // Configures the steps division (see above)
digitalWrite(MS2, LOW); // Configures the steps division (see above)
digitalWrite(dir_pin, LOW); // Sense (HIGH = anti-clockwise / LOW = clockwise) - It can be also changed
}
void loop() {
while(steps>=0) { // While the steps value is greater or equal zero
digitalWrite(step_pin, HIGH); // Sends logic level 'high' to the steps pin of the motor
delay(5); // Waits 5ms for the next step
digitalWrite(step_pin, LOW); // Sends logic level 'high' to the steps pin of the motor
delay(5); // Waits 5ms for the next step
}
}
Explanation / Answer
#define step_pin 3 // Define pin 3 as the steps pin
#define dir_pin 2 // Define pin 2 as the direction pin
#define MS1 5 // Define pin 5 as "MS1"
#define MS2 4 // Define pin 4 as "MS2"
int direction; // Variable to determine the sense of the motor
int steps = 1; // Number of steps that you want to execute (for full steps, 200 = 1 turn)
void setup() {
pinMode(MS1, OUTPUT); // Configures "MS1" as output
pinMode(MS2, OUTPUT); // Configures "MS2" as output
pinMode(dir_pin, OUTPUT); // Configures "dir_pin" as output
pinMode(step_pin, OUTPUT); // Configures "step_pin" as output
digitalWrite(MS1, LOW); // Configures the steps division (see above)
digitalWrite(MS2, LOW); // Configures the steps division (see above)
digitalWrite(dir_pin, LOW); // Sense (HIGH = anti-clockwise / LOW = clockwise) - It can be also changed
}
void loop() {
while(steps>=0) { // While the steps value is greater or equal zero
digitalWrite(step_pin, HIGH); // Sends logic level 'high' to the steps pin of the motor
delay(750); // Waits 5ms for the next step
digitalWrite(step_pin, LOW); // Sends logic level 'high' to the steps pin of the motor
delay(750); // Waits 5ms for the next step
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.