Increase stepper motor speed?

I have a stepper motor connected to my arduino along with a joystick that came with my kit to control the direction of the stepper motor. It works perfectly, but it rotates really slowly. My question is how do I get it to rotate faster? The stepper motor I'm using is 28BYJ-48 ULN2003. Here's the code I'm using

const int s1 = 6;
const int s2 = 7;
const int s3 = 8;
const int s4 = 9;
int x;
void setup() {
  pinMode(s1, OUTPUT);
  pinMode(s2, OUTPUT);
  pinMode(s3, OUTPUT);
  pinMode(s4, OUTPUT);
  pinMode(A1, INPUT);
 }
void loop() {
  x = analogRead(A1);
  
  if(x<500)
  {
 digitalWrite(s1, HIGH);
 digitalWrite(s2, LOW);
 digitalWrite(s3, LOW);
 digitalWrite(s4, LOW);
 delay(5);
 digitalWrite(s1, LOW);
 digitalWrite(s2, HIGH);
 digitalWrite(s3, LOW);
 digitalWrite(s4, LOW);
 delay(5);
 digitalWrite(s1, LOW);
 digitalWrite(s2, LOW);
 digitalWrite(s3, HIGH);
 digitalWrite(s4, LOW);
 delay(5);
 digitalWrite(s1, LOW);
 digitalWrite(s2, LOW);
 digitalWrite(s3, LOW);
 digitalWrite(s4, HIGH);
 delay(5);
 }
 else if(x>550)
 {
  digitalWrite(s1, LOW);
 digitalWrite(s2, LOW);
 digitalWrite(s3, LOW);
 digitalWrite(s4, HIGH);
 delay(5);
 digitalWrite(s1, LOW);
 digitalWrite(s2, LOW);
 digitalWrite(s3, HIGH);
 digitalWrite(s4, LOW);
 delay(5);
 digitalWrite(s1, LOW);
 digitalWrite(s2, HIGH);
 digitalWrite(s3, LOW);
 digitalWrite(s4, LOW);
 delay(5);
 digitalWrite(s1, HIGH);
 digitalWrite(s2, LOW);
 digitalWrite(s3, LOW);
 digitalWrite(s4, LOW);
 delay(5);
 }
 else if(x > 500 && x < 550)
 {
 digitalWrite(s1, LOW);
 digitalWrite(s2, LOW);
 digitalWrite(s3, LOW);
 digitalWrite(s4, LOW);
 }
}

You need to use delayMicroseconds() in timing, microSeconds = (approximately) 29300 / RPM, so 5 RPM would be 5860 or

delayMicroseconds(5860);

But since delayMicroseconds() can only take a maximum value of 16383, minimum speed will be about 1.8 RPM and maximum about 12 RPM (2440 micros), remember that motor has a 64 to 1 gear reduction and 12 RPM shaft speed means the little motor is screaming at 768 RPM, very fast for a stepper.

How fast is your motor moving and how fast do you want it to move?

From looking at the code it seems to make a step every 5 millisecs (the line delay(5) )

You could try changing all those to delay(4) and see what happens.

Of course it would make a lot more sense to have a variable (let's call it stepInterval) with the value 5 and then all the delay() statements could be delay(stepInterval); Then if you want to make a change to the speed you only have to change the number in one place. Something like this

int stepInterval = 5; // at the top of your program
if(x<500)
  {
 digitalWrite(s1, HIGH);
 digitalWrite(s2, LOW);
 digitalWrite(s3, LOW);
 digitalWrite(s4, LOW);
 delay(stepInterval);
  // etc

...R

I'd recommend looking at AccelStepper library, starting with the examples.

outsider - thanks changing it to microseconds worked! It's not as fast as I thought but it think its because my motor is small but it should do the job.

Robin2 - thanks for the tip. saved me a lot of time when changing the delay