joystick controlled servo will not stop when in neutral

I am trying to control 2 servos to go in both directions. But when the joystick is in neutral position the servos keep on rotating.
I am using SG90 Towerpro 9g servos that has been rebuilt to go 360+

How can i make it stop?

Here is my program:

#include <Servo.h>
#include <Arduino.h>

Servo myServo1;
Servo myServo2;

int servo1 = 3;
int servo2 = 5;

int joyX = 0;
int joyY = 1;

int val=0;

void setup() {
myServo1.attach(servo1);
myServo2.attach(servo2);
Serial.begin(9600);
}

void loop() {

int valX = analogRead(joyX);
int valY = analogRead(joyY);

valX = map(valX, 0, 1023, 10, 170);
valY = map(valY, 0, 1023, 10, 170);

myServo1.write(valX);
myServo2.write(valY);

; delay(5);

}

that has been rebuilt to go 360+

Which means that your servo can no longer be set to a specific angle. Your code assumes it can be set to an angle.

Do you know what you have to write to the servo to get it to stop? You need to do some tests to find the appropriate number to either write as an angle or write microseconds. This is because once you modify a servo there is no way of knowing what numbers do what.

  1. Use Code Tags when you post your program.

  2. Use Serial print statements to add debug information.

  3. What is the value of the analog read in Neutral?

The last is a three-step process. First you will need to decouple the variables in the map statement, so you can execute #2 and print the analogRead value to see it, finally find out that neutral does not mean 0 (as you appear to expect).

Look forward to seeing you updated code and serial output data soon.

You can put some Serial.prints in to check what actual values you get from the joystick. They often don't go full range and often don't centre very accurately.

Then you can test what actual value written to the servo causes it to stop. 360 servos usually stop at something close to 90 but very often not exactly 90.

Steve