Controlling servos with Joysticks

Hello everyone,

firstly sorry for my bad englisch :confused:

I need help controlling my servos. I am using the Programm you can see in the bottom. My mainproblam is that the Servos move back in their former Position after they moved. My aim is that the servos stay in the position they went by using the Joystick. For example, the servo should rotate slowly leftwards while i am pushing the Joystick to the left, and rotate also slowly rightwards while i am pushing the controller to the right. The movement should stop when the Joystick move back in the starting position.

int ServoHorizontalPin = 3; int ServoVerticalPin = 4; int HorizontalPotPin = A0; int VerticalPotPin = A1; int ServoH_Min = 0; int ServoH_Max = 180; int ServoV_Min = 0; int ServoV_Max = 180;

Servo HorizontalServo; Servo VerticalServo;

int HorizontalPotValue; int HorizontalServoPosition; int VerticalPotValue; int VerticalServoPosition;

void setup() {

HorizontalServo.attach(ServoHorizontalPin); VerticalServo.attach(ServoVerticalPin); }

void loop() { HorizontalPotValue = analogRead(HorizontalPotPin); VerticalPotValue = analogRead(VerticalPotPin); HorizontalServoPosition = map(HorizontalPotValue, 0, 1023, ServoH_Min , ServoH_Max); VerticalServoPosition = map(VerticalPotValue, 0, 1023, ServoH_Min , ServoH_Max); HorizontalServo.write(HorizontalServoPosition); VerticalServo.write(VerticalServoPosition); delay(20); }

I hope you can help me to solve my perhaps easy Problem!

best regards flyingeagle1998

My aim is that the servos stay in the position they went by using the Joystick.

You push the joystick. You want the servos to move. You let go of the joystick, and the spring moves the joystick. You want the servos to not move. How is the Arduino supposed to know if it is you moving the joystick or the spring moving the joystick?

When you can answer that question, you can make the servos move, or not move, as you want.

PS. Hundreds of other people have asked the same thing. Find out how some of them handled the issue (usually by posting in the Robotics section).

Have a look at reply #12 here.