servo motor

i used this code to make servo rotate using joystick and it work … there is a problem that when i did not move the joystick the servo is rotate … i want the servo be fixed when i lift the joystick

Code;
#include <Servo.h>

const int servo1 = 3; // first servo
const int servo2 = 10; // second servo
const int joyH = 3; // L/R Parallax Thumbstick
const int joyV = 4; // U/D Parallax Thumbstick

int servoVal; // variable to read the value from the analog pin

Servo myservo1; // create servo object to control a servo
Servo myservo2; // create servo object to control a servo

void setup() {

// Servo
myservo1.attach(servo1); // attaches the servo
myservo2.attach(servo2); // attaches the servo

// Inizialize Serial
Serial.begin(9600);
}

void loop(){

// Display Joystick values using the serial monitor
outputJoystick();

// Read the horizontal joystick value (value between 0 and 1023)
servoVal = analogRead(joyH);
servoVal = map(servoVal, 0, 1023, 0, 180); // scale it to use it with the servo (result between 0 and 180)

myservo2.write(servoVal); // sets the servo position according to the scaled value

// Read the horizontal joystick value (value between 0 and 1023)
servoVal = analogRead(joyV);
servoVal = map(servoVal, 0, 1023, 70, 180); // scale it to use it with the servo (result between 70 and 180)

myservo1.write(servoVal); // sets the servo position according to the scaled value

delay(15); // waits for the servo to get there

}

/**

  • Display joystick values
    */
    void outputJoystick(){

Serial.print(analogRead(joyH));
Serial.print ("—");
Serial.print(analogRead(joyV));
Serial.println ("----------------");
}

i want the servo be fixed when i lift the joystick

I do not understand what this means.

i want the servo do not move when i did not move a joystick at any direction

PaulS: I do not understand what this means.

He means that the servo should not move when he "lifts" his finger off the joystick, i.e. when he does not move it.

At the central position the joystick will give a certain reading (around 500) and you are constantly sending it to the servo so it will move. If you dont want it to move, use an if statement. If value is in central range, do nothing.

wagdy: i want the servo do not move when i did not move a joystick at any direction

Do you have a link to the servo? Is the servo standard or continuous rotation? There have been a lot of post in the past concerning various types of servo/joystick code. You may find something like you want in the previous post below.

https://www.google.com/search?ie=UTF-8&oe=UTF-8&q=joystick+servo&btnG=search&domains=http%3A%2F%2Fforum.arduino.cc&sitesearch=http%3A%2F%2Fforum.arduino.cc&gws_rd=ssl