Stepper moter and 2 servos not working togeter

i want to make a head with 1stepmoter and 2 servos

the stepmoter is for a neck to ga up and down and
the servos for eyes and neck go left and right this is the code i used the neck goes up and down (stepmoter works) but eyes doesn't work

What i wanna do is Stepmoter go up and down
and the servos goes left to right sweep in the void(){}

**Old Code
//#include <ESP32Servo.h>
#include <Servo.h>
//#include <WiFi.h>
//#include <HardwareSerial.h>
#include <SoftwareSerial.h>
//#include <Stepper.h>
#include "AccelStepper.h"
#include <DFRobotDFPlayerMini.h>

int serial1 = 10;
int serial2 = 11;

//HardwareSerial mySerial(2);  // Use UART1 (Serial1 on ESP32)
SoftwareSerial mySerial(serial1, serial2); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
# define Start_Byte 0x7E
# define Version_Byte 0xFF
# define Command_Length 0x06
# define End_Byte 0xEF
# define Acknowledge 0x00




//Servos Eyes
Servo ServoEyes;
Servo ServoNeckRotate;

int volume = 30;

int poseye = 40;
int posneckupdown = 40;

const int volumeMute = 32;
const int volumeUP = 33;
const int volumeDOWN = 4;

int servoPinneckleftright = 9;	
int servoPineyes = 12;
int buttonState = 0;  

int lastButtonState = HIGH;
bool isMuted = false;
int savedVolume = 15;

//StepMotor
const int stepsPerRevolution = 2038;
#define HALFSTEP 4

// Motor pin definitions:
#define motorPin1  5      // IN1 on the ULN2003 driver
#define motorPin2  6      // IN2 on the ULN2003 driver
#define motorPin3  7     // IN3 on the ULN2003 driver
#define motorPin4  8     // IN4 on the ULN2003 driver
#define MotorInterfaceType 4
int endPoint = 1024;
//AccelStepper stepper(HALFSTEP, 5, 7, 6, 8);
AccelStepper stepper(MotorInterfaceType, motorPin1, motorPin3, motorPin2, motorPin4);

#define home_switch 4  // Pin 9 connected to Home Switch (MicroSwitch)
int move_finished = 1;     // Used to check if move is completed
long initial_homing = 1;
const int homeSwitchPin = 4; // Connect your limit switch or hall sensor here




void setup() {
  Serial.begin(115200);  // Initializes Serial Monitor for debugging (USB output to PC)
  mySerial.begin(9600);  // RX, TX (DFPlayer communication)
  //pinMode(limitSwitchPin, INPUT_PULLUP); // Internal pull-up resistor
  //myStepperdown.setSpeed(10);
 
  //  DFPlayer Startup
  Serial.println("Initializing DFPlayer...");
	  //  Tries to initialize DFPlayer and prints error if failed
  if (!myDFPlayer.begin(mySerial)) {
    Serial.println("DFPlayer not detected.");  //  Shown if no communication with DFPlayer
    while (1);  //  Stops further execution
  }
  Serial.println("DFPlayer connected!");
  myDFPlayer.volume(30);  // Set volume (0 to 30)
	Serial.println("DFPlayer volume 30");
  myDFPlayer.play(2);     // Play first track (0001.mp3)
  Serial.println("DFPlayer Intro");
	myDFPlayer.loop(2);


	//ServoEyes.setPeriodHertz(50);    // standard 50 hz servo
	ServoEyes.attach(servoPineyes, 500, 2400); // attaches the servo on pin 18 to the servo object
	//myservoneckdownup.setPeriodHertz(50);    // standard 50 hz servo
//	myservoneckdownup.attach(servoPinneckupdown, 500, 2400); // attaches the servo on pin 18 to the servo object
	//ServoNeckRotate.setPeriodHertz(50);    // standard 50 hz servo
	//ServoNeckRotate.attach(servoPinneckupdown, 500, 2400); // attaches the servo on pin 18 to the servo object
	// using default min/max of 1000us and 2000us
	// different servos may require different min/max settings
	// for an accurate 0 to 180 sweep
	pinMode(volumeMute, INPUT);
	pinMode(volumeUP, INPUT);
	pinMode(volumeDOWN, INPUT);
	digitalWrite(volumeMute, HIGH);
	digitalWrite(volumeUP, HIGH);
  digitalWrite(volumeDOWN, HIGH);
stepperhome();
	
}






void eyesa() {
		//Servo Eye
	for (poseye = 60; poseye >= 20; poseye -= 1) { // goes from 180 degrees to 0 degrees
		ServoEyes.write(poseye);    // tell servo to go to position in variable 'pos'
		//delay(130);             // waits 15ms for the servo to reach the position
	}
	for (poseye = 20; poseye <= 60; poseye += 1) { // goes from 0 degrees to 180 degrees
		// in steps of 1 degree
		ServoEyes.write(poseye);    // tell servo to go to position in variable 'pos'
		//delay(130);             // waits 15ms for the servo to reach the position
	}
}


int previousMillisServo = 0;
int pos = 0;  
long servoInterval = 100;
unsigned long currentMillis = 0;

void eyes() {
  for (pos = 20; pos <= 60; pos += 1) { 
    ServoEyes.write(pos);              

    previousMillisServo = millis();

    // delay for the servoInterval
    while ((millis() - previousMillisServo) < servoInterval) ;
  }

  for (pos = 60; pos >= 20; pos -= 1) { 
    ServoEyes.write(pos);              

    previousMillisServo = millis();

    // delay for the servoInterval
    while ((millis() - previousMillisServo) < servoInterval) ;
  }
}


void stepperhome (){
Serial.println("Homing in progress...  (Langnek)");
Serial.println("");
pinMode(home_switch, INPUT_PULLUP);
  //  Set Max Speed and Acceleration of each Steppers at startup for homing
  //stepper.setMaxSpeed(700);      // Set Max Speed of Stepper (Slower to get better accuracy)
  stepper.setAcceleration(250);  // Set Acceleration of Stepper
  //stepper.setSpeed(0);

  // Start Homing procedure of Stepper Motor at startup
 while (digitalRead(home_switch)) {  // Make the Stepper move CCW until the switch is activated
   stepper.setMaxSpeed(700.0);      // Set Max Speed of Stepper (Slower to get better accuracy)
   stepper.setAcceleration(250.0);
   //stepper.setSpeed(0);
   stepper.moveTo(initial_homing);  // Set the position to move to
   initial_homing--;                 // Decrease by 1 for next move if needed
   stepper.run();                   // Start moving the stepper
   stepper.runSpeed();
   delay(0);
 }

  stepper.setCurrentPosition(0);   // Set the current position as zero for now
  stepper.setMaxSpeed(700.0);      // Set Max Speed of Stepper (Slower to get better accuracy)
  stepper.setAcceleration(100.0);  // Set Acceleration of Stepper
  initial_homing = 1;
  stepper.setCurrentPosition(0);
  Serial.println("Homing Langenek Completed");
  Serial.println("");
  stepper.setMaxSpeed(700.0);      // Set Max Speed of Stepper (Faster for regular movements)
  stepper.setAcceleration(250.0);
	  //stepper.moveTo(200);  // Set the position to move to
    //initial_homing--;                 // Decrease by 1 for next move if needed
    //stepper.run();                   // Start moving the stepper
    //delay(5);


}




void steppernek() {
  myDFPlayer.play(1);     // Play first track (0001.mp3)
  Serial.println("DFPlayer Langnek Verhaal");
	myDFPlayer.loop(1);

  stepper.setCurrentPosition(0);
  stepper.setMaxSpeed(700);      // Set Max Speed of Stepper (Slower to get better accuracy)
  stepper.setAcceleration(100);
  stepper.moveTo(230000);
  //stepper.setSpeed(500);
  Serial.println("Up Langenek");
  stepper.runToPosition();
  //Serial.println(stepper.targetPosition());
   //Serial.println(stepper.speed());
  //while (stepper.distanceToGo() != 0) {
  //  stepper.run();
  //}


  Serial.println("Up Langenek Completed");
  //delay(1000);

  //stepper.moveTo(10);
  Serial.println("Down Langenek");
  //while (stepper.distanceToGo() != 10) {
  //  stepper.run();
  //}
   while (digitalRead(home_switch)) {  // Make the Stepper move CCW until the switch is activated
   stepper.setMaxSpeed(700);      // Set Max Speed of Stepper (Slower to get better accuracy)
   stepper.setAcceleration(250);
   stepper.moveTo(initial_homing);  // Set the position to move to
   initial_homing--;                 // Decrease by 1 for next move if needed
   stepper.run();                   // Start moving the stepper
   delay(0);
 }
   stepper.setCurrentPosition(0);
   Serial.println("Down Langenek Completed");
  delay(1000); 
   
}



 //Loop new
int posw = 40;
int sweepDirection = 1; // 1 for forward, -1 for backward
unsigned long lastServoTime = 0;
const long servoIntervalw = 100;

void loop1(){
// 1. NON-BLOCKING STEPPER    
  stepper.setMaxSpeed(700);      // Set Max Speed of Stepper (Slower to get better accuracy)
  stepper.setAcceleration(50);
  stepper.moveTo(230000);
  stepper.run();
  stepper.moveTo(100); 
  stepper.run();


// 2. NON-BLOCKING SERVO SWEEP
  unsigned long currentTime = millis();
  if (currentTime - lastServoTime >= servoIntervalw) {
    lastServoTime = currentTime;

    // Move servo position
    posw += sweepDirection;
    ServoEyes.write(posw);

    // Reverse direction at limits
    if (posw >= 60 || posw <= 20) {
      sweepDirection = -sweepDirection;
    }
  }


}






//Loop
void loop() {
steppernek();
eyes();

//mp3story();
//testmodus();
//neckupdown();
//neckleftright();

}


void volumeINC()
{
volume = volume+1;
if(volume==31)
{
volume=30;
}
exe_cmd(0x06, 0, volume);
delay(500);
}

void volumeDEC()
{
volume = volume-1;
if(volume==-1)
{
volume=0;
}
exe_cmd(0x06, 0, volume);
delay(500);
}

void exe_cmd(byte CMD, byte Par1, byte Par2)
{
word checksum = -(Version_Byte + Command_Length + CMD + Acknowledge + Par1 + Par2);
byte Command_line[10] = { Start_Byte, Version_Byte, Command_Length, CMD, Acknowledge, Par1, Par2, highByte(checksum), lowByte(checksum), End_Byte};
for (byte x=0; x<10; x++)
{
mySerial.write(Command_line[x]);
}
}

void mp3story() {
	myDFPlayer.volume(30);  // Set volume (0 to 30)
	Serial.println("DFPlayer volume 30");
  myDFPlayer.play(2);     // Play first track (0001.mp3)
  Serial.println("DFPlayer Langnek");
	myDFPlayer.loop(1);

}


void serverstory() {


}

Describe how the eyes do not work, how are they not doing what you expect?

Wow... that sketch is a mashup of so many things.

@chello21 Do yourself a favor. Write one sketch that simply moves one servo as you want it to move. Omit all the other fluff for now. If that works, then compare with your code; if it doesn't work, present it here, and we can debug that, and then work forward to integrate a working servo into your code.

Thanks.

oke i try that i'm new to coding in the void loop i have the eyes and neck
when i turn the code of eyes on it works the eyes but the neck not move up and down

oke i try that i'm new to coding the code what i have now is a find on google

the stepper is homing to a 0 position the goes up and down that works (in loop)
the eyes goes not go left to right sweep (in loop)

Verify your driver module is set correctly. How are you making a "up and down" from a rotating motor?

from this code the neck goes up and down i used a steppermoter

void steppernek() {
  myDFPlayer.play(1);     // Play first track (0001.mp3)
  Serial.println("DFPlayer Langnek Verhaal");
	myDFPlayer.loop(1);

  stepper.setCurrentPosition(0);
  stepper.setMaxSpeed(700);      // Set Max Speed of Stepper (Slower to get better accuracy)
  stepper.setAcceleration(100);
  stepper.moveTo(230000);
  //stepper.setSpeed(500);
  Serial.println("Up Langenek");
  stepper.runToPosition();
  //Serial.println(stepper.targetPosition());
   //Serial.println(stepper.speed());
  //while (stepper.distanceToGo() != 0) {
  //  stepper.run();
  //}


  Serial.println("Up Langenek Completed");
  //delay(1000);

  //stepper.moveTo(10);
  Serial.println("Down Langenek");
  //while (stepper.distanceToGo() != 10) {
  //  stepper.run();
  //}
   while (digitalRead(home_switch)) {  // Make the Stepper move CCW until the switch is activated
   stepper.setMaxSpeed(700);      // Set Max Speed of Stepper (Slower to get better accuracy)
   stepper.setAcceleration(250);
   stepper.moveTo(initial_homing);  // Set the position to move to
   initial_homing--;                 // Decrease by 1 for next move if needed
   stepper.run();                   // Start moving the stepper
   delay(0);
 }
   stepper.setCurrentPosition(0);
   Serial.println("Down Langenek Completed");
  delay(1000); 
   
}

Then you must look at doing many things at once, not one then another as you have done. It may take some time to get your head around this, because you've admitted your code so far consists of grabbing pieces off the internet, but at this point your progress will be nil until you do. Please read through:

There are other helpful threads in the Tutorial section as well, but this one is an excellent starting point.

Show links to the origin of all the code you are using. You have mixed the code like it is a cake recipe in a blender. Arduino code needs to be orderly.

[edit]
I see you did some editing... but used the wrong value

3500 revolutions?

Maybe using my MobaTools library will make things easier. It controls the stepper in the background. You need not care about creating every step in the sketch. The same for the servo: the lib controls the speed of the servo without the need of for loops. So it is easy to have stepper and servo moving simultaneously.


stepper.moveTo(230000);
is for the neck go up is very long neck see picture

I would guess the gears are binding and the motor can not overcome the force.

stepsPerRevolution = 2038; must be remove in code

The big gear is for neck to go left right
In the neck i used a stepper to go up down
En the head are the eyes

is a big project is the LongNeck from the efteling

Must match stepper motor steps per revolution.

Where did you find that? does it match to your HW? The code, as it is now, is a mess.
Show as a schematic of your HW. Which ESP are you using?
Obviously the stepper is a small geared stepper. Is it strong enough?

To be able to help you, we need much more information about your hardware and what you’re planning to do with it.
Start step by step.

now i use a arduino nano
i order a arduino r4 wifi

the steppermotor is used for neck to go up and down,
i used a servo for the eyes go left right
and
i used a servo for the neck go left right

What you've described can be accomplished with a Nano; throwing different hardware at it won't solve anything, and you'll find far fewer libraries/drivers available for the R4, from what I've read; also, you'll have to find sample codes for those libraries to do what you want, because it's rarely a 1:1 equivalence. Sorting all that out from a beginner's POV is daunting, and changing horses will only frustrate your helpers here.

Continously? Or what will start and stop the movement? We still don't know much about your project.

it is continously in the setup is the neck homing to 0 postion
and in the loop i will try to neck up and down and left to right also for the eyes