joystick not accurate

Greetings all

I'm trying work with joysticks, but it seems that the read value changes even I'm not touching it.

In theory, the joystick is nothing more than two potentiometers from 0 to 1023.

but I find when I use the analogRead, the center value goes between 470 to 530, and the edge value is like about 40 and 900.

What's the problem? how can I fix it?

Thanks

this is the joystick I'm working with. http://www.vetco.net/catalog/images/VUPN5940-1.jpg

Which Arduino are you using. How are you powering it.

The A/D uses the 5volt supply as analogue reference. If that 5volt supply is not stable, A/D readings also could become unstable. Leo..

Wawa: Which Arduino are you using. How are you powering it.

The A/D uses the 5volt supply as analogue reference. If that 5volt supply is not stable, A/D readings also could become unstable. Leo..

I'm using a mega. and the joystick is powered by 5v pin on the board.

How are you powering the Mega. USB, DC jack, Vin, batteries. If not via USB, e.g DC jack, what voltage.

Post the code used for the joystick (inside code tags). Leo..

the mega is powered via USB from my computer.

const int xAxis = A3;
const int yAxis = A2;

int x = 0;
int y = 0;

void setup()
{
  pinMode(A3,INPUT);
  pinMode(A2,INPUT);

  Serial.begin(9600);
}

void loop()
{
  x = analogRead(xAxis);
  y = analogRead(yAxis);
  Serial.print(x);
  delay(1000);
}

the code is really nothing special, I deleted the yaxis part because I find the problem.

When you make A3 and A2 "INPUT", using 'pinMode()', you're configuring them as digital inputs instead of analogue inputs.

Remove both 'pinMode()' statements.