Using both a Stepper motor( 28BYF-48) and a servo on an UNO

Hello, I am working on a “pan & tilt” project controlled by a joystick.

The pan motor is a 28BYJ-48 w/ ULN2003 driver
The tilt is a servo GS90
I am not able to get the stepper to work with the servo and I m using IDE 1.8.12

There appear to be a conflict on the timing between these to, independently they work perfectly but when I combine them they both move together.

I have read online about timer conflicts and tried ServoTimer2 but that would compile for the UNO with this IDE so I need some help.

It would be fine if it would pan then tilt but simultaneously is best.

My Code is below and Thanks in advance, Steve

A special thanks to the moderator for the coaching on posting code!

/* Control Stepper Motor with ULN2003 and Analog Joy Stick for Pan
   GS90 Servo Control for the Tilt Axis
This code is in the public domain...

#include <Servo.h>
Servo servoTilt;    // Assign the name of the Tilt servo

#include <AccelStepper.h>     // AccelStepper library by Mike McCauley :

#define StepperDriverType 4  // 4 Wires Stepper Motor interface
// Arduino Pins 8,10,9,11 connected to OUT 1,2,3,4 on ULN2003  BE CAREFUL HERE!
AccelStepper stepper = AccelStepper(StepperDriverType, 8,10,9, 11); 

#define Pan_Stick_Pin A0    // Arduino A0 Pin connected to the analog out of the Stick to Pan
#define Tilt_Stick_Pin A1    // Arduino A1 Pin connected to the analog out of the Stick to Tilt

int Tilt_Stick_Value;          //Create an integer variable for the joy stick reading in the Tilt_Stick
int Pan_Stick_Value;     // Used to save the current Analog Pan_Stick Value
int Stepper_Speed;       // Used to set the travel speed of the stepper motor
int Stepper_Direction;   // Used to choose the direction of travel
int motorSpeed = 1000;   // High speeds (800 and above) may cause erratic behavior in 28BYJ-48
int motorAccel = 500;    // As above: better avoiding extreme accelerations

void setup() 
  Serial.begin(9600);   // Only used for debugging
  servoTilt.attach(5);    //Assign pin 5 as the output for the Tilt Servo
  // the following two lines reset "step zero" to the current position

void loop() 
Pan_Stick_Value=analogRead(Pan_Stick_Pin);  // Read the value of the analog Pan_Stick
   // Use the next line to determine the Pan_Sticks center position in this case 526
   //Serial.print("Pan ");
  if (Pan_Stick_Value > 550)   // If Pan_Stick is moved to the Right
    // Map the Right value of the Pan_Stick to a Speed value for the stepper
    Stepper_Direction--;  // Decrease the position to reach by one which will be used to move the stepper later
  else if (Pan_Stick_Value < 500)   // If Pan_Stick is moved to the Left
    // Map the Left value of the Pan_Stick to a Speed value for the stepper
      Stepper_Direction++;   // Increase the position to reach by one which will be used to move the stepper later
      Stepper_Speed=0;  // If Pan_Stick is around the middle then don't move the stepper by setting the speed to zero
      stepper.disableOutputs();  // Turn OFF ULN2003
// Move the stepper to new position
 // Serial.print("Stepper "); 
 // Serial.println(Stepper_Direction);

// Do this until the stepper as reached the new destination
  while (stepper.distanceToGo() != 0)   // if stepper hasn't reached new position
      stepper.enableOutputs();  // Turn ON ULN2003
      stepper.runSpeedToPosition();  // move the stepper until new position reached
 // Read the value of analog input A1 and store it it the valJoyTilt variable
  Tilt_Stick_Value = analogRead(Tilt_Stick_Pin);
  //scale the Tilt_Stick_Value varible from 0-1023 counts to 0-180 deg.
  Tilt_Stick_Value = map(Tilt_Stick_Value, 0, 1023, 0, 180);
  //Serial.print("Tilt "); 
  servoTilt.write(Tilt_Stick_Value);      // Write the newly mapped Tilt_Stick_Value value to the servo output
  delay(1);                               // Delay 1 milliseconds to allow communication   

If you post your code as described in the how to use this forum sticky more members will be able to see it.

post your code as described in the how to use this forum sticky

You have posted code without using code tags, as described in the forum stickies. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don’t do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons. The “Code: [Select]” feature allows someone to select the entire sketch so it can be easily copied and pasted into the IDE for testing.
If you have already posted without using code tags, open your message and select “modify” from the pull down menu labelled, “More”, at the lower right corner of the message. Highlight your code by selecting it (it turns blue), and then click on the “</>” icon at the upper left hand corner. Click on the “Save” button. Code tags can also be inserted manually in the forum text using the code and /code metatags.