Robin2:
What is the difference between your non-working program and the program you used to prove that the motor works? The problem will be somewhere in the difference.
The code that made the motor spin:
void loop(){
//Enables the motor direction to move in a certain direction.
digitalWrite(dirPin,LOW);
//Makes 200 Pulses for making one full cycle (1.8 degree stepper).
for(int x = 0; x < 200; x++){
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
}
Now I wanted to add the functionality of it being RPM controlled between 0 and 100 RPM so I changed it to:
void loop(){
Pot = analogRead(A1);
RPM =(Pot*100L)/1023;
//Enables the motor direction to move in a certain direction.
digitalWrite(dirPin,LOW);
//Makes 200 Pulses for making one full cycle (1.8 degree stepper).
for(int x = 0; x < 200; x++){
digitalWrite(stepPin,HIGH);
motor =((((RPM*1000000)/60)/200)/2);
delayMicroseconds(motor);
digitalWrite(stepPin,LOW);
motor =((((RPM*1000000)/60)/200)/2);
delayMicroseconds(motor);
}
}
I checked the RPM value with serial.print and it varies between 0 and 100 nicely when turning the potentiometer. I am sure the reason the motor doesn't spin has to do with the code after the RPM has been defined. Any pointers or tips on standard code to control a motors RPM? Having a hard time to find something similar and useful on the forum.
Yours sincerely,
Driez