Help needed using a small joystick to move mouse pointer

I'm using this small joystick:

I'm starting out just trying to move the stick and read the values in the serial the code is pretty simple right now.

The serial window displays 1023x1023 all the time! It never changes even when I move the joystick around.

What am I forgetting to do?


const int joystickYpin = 14; // analog A0
const int joystickXpin = 15; // analog A1

int mouseX = 0;
int mouseY = 0;

void setup()
  pinMode(joystickYpin, INPUT);
  pinMode(joystickXpin, INPUT);

void loop()
  mouseX = analogRead(joystickXpin); // will be 0-1023
  mouseY = analogRead(joystickYpin); // will be 0-1023

Check the ground (GND) connection between your Arduino and your joystick.

If you have a meter, check the two voltages from the joystick are about 2.5V when the joystick is central.

Do you have an Arduino Mega? - Only Mega has analog inputs up to pin 15, most others only 0-7.

Try changing the pin definitions to use the analogue name/number and not the digital number.

const int joystickYpin = A0; // analog A0