Joystick Potentiometer

Hey, I need to understand how can I control servo via joystick potentiometer, I have this one http://tinyurl.com/ods2tny .

I have connected this potentiometer just like normal circuit as shown in Arduino examples, so when I control it, it works fine, its moving like 90 to 180 degree when I move potentio to the right side and 90 to 0 when on the left.

Now what my problem is that, when I move potentio to the left and then release it, it retracts to its original position and so servo. I dont want servo to go back to its original position when potentio goes back, instead when I move potentio to the right, then the servo should move.

in simple, I want to move servo left or right when I move potentio left or right without servo going back to its original position.

Can I do this?

You will need to develop an algorithm in your code to determine when the joystick is being moved "back to home", and not move the servo when that happens.

Since you didn't post any code, it is difficult to suggest how to implement that.

Also, your URL doesn't seem to work (or at least it isn't at the moment.)

in simple, I want to move servo left or right when I move potentio left or right without servo going back to its original position. Can I do this?

Sure, don't let go of the joystick. Otherwise you can remove the return springs in the joystick. You can make some code workarounds, but they also introduce other issues.

One of the tricky parts would be for the sketch to recognise that you've let go, and that you've actually positioned the servo at its final position.

A possibility which I've thought about but never got round to trying, is to activate a switch- my joystick has a pushbutton on top, for example, not sure if yours has one, or you could use a separate button. You could have the servo/s only move while the button is pressed: press and hold the button, move joystick which moves servo, release button, release joystick, and because the button isn't pressed, the servo doesn't move.

Immediate problem I see, of course, is that as soon as you press the button for the next move, the servo will centre..... but it might give you some ideas? As I say, I've not tried this, just been pondering it.

What you want to do does not sound too difficult.
Let's assume that the servo and stick start at the centre position

start of loop
  set moved flag to false
  
  if stick has moved further left than previous position and previous position was to the left
    set moved flag to true
  end if
  
  else if stick has moved further right than previous position and previous position was to the right
    set moved flag to true
  end if
  
  if moved is true
    move servo to match stick position
    save current position as previous position 
  end if
  
end of loop

You can tell that the stick has moved further left or right because the value returned by analogRead() will increase or decrease and can tell that the previous position was left or right by its value.

I used the example code, but like you said, an algorithm, seems complicated and time consuming, but I,ll sure test some different ways, but if anybody has already develop any technique, that would save my time.

// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>

#include <Servo.h>
 
Servo myservo;  // create servo object to control a servo
 
int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin
 
void setup()
{
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}
 
void loop()
{
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180)
  myservo.write(val);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there
}

here is the picture.

AND

UKHeliBob:
What you want to do does not sound too difficult.
Let’s assume that the servo and stick start at the centre position

start of loop

set moved flag to false

if stick has moved further left than previous position and previous position was to the left
set moved flag to true
end if

else if stick has moved further right than previous position and previous position was to the right
set moved flag to true
end if

if moved is true
move servo to match stick position
save current position as previous position
end if

end of loop


You can tell that the stick has moved further left or right because the value returned by analogRead() will increase or decrease and can tell that the previous position was left or right by its value.

:open_mouth: , Im sure I,ll do it, but I was wondering some quick codes so I can save sometime.

Thanks for the help.