Joysticks not returning the correct values

Hi Guys!!
I have recently started out with Arduino and have been facing some problems with my joysticks.
When connect to an Arduino UNO they would give me values of 1023 and 1023 at rest.
moving them in the positive x or positive y direction would cause no change in their values on the other hand moving in the -ve x or -ve y direction would decrement their values as expected.
I then switched to an Arduino Nano and now the joysticks are giving me rest values in the range of 750-820 and the values are quite random when I move the joystick.
My code is quite basic and involves just reading of the joystick values.

void setup(){
  pinMode(A1,INPUT);
  pinMode(A2,INPUT);
  Serial.begin(9600);
}

void loop(){
  Serial.print(analogRead(A1));
  Serial.print('\t');
  Serial.println(analogRead(A2));
  delay(100);
}

Can someone make out the problem here?
Thanks in Advance.

Hello fredi999

Post the current schematic of your project to see how we can help.

You do not need these lines of code.

As mentioned, we need a schematic.

Code seems to be ok.

Those lines could be omited, but it's not the problem here. Just make sure the joystick is wired correctly, if it is ... Are the joysticks new ? They use to wear down with usage. Maybe they're broken internaly


This is mostly the schematic except I connected the X-axis and Y-axis to A1 and A2.

Yeah The joystick is brand new and I got 2 of those Both giving the similar output

Post a schematic , not a Fritzding diagram.

Missing ground.

Sounds like a build problem.
Post a picture of the setup.
Leo..

As @Wawa pointed out, could be a wiring problem.
Post a picture of you breadboard setup

I tested the Joysticks again and they are giving the correct values now.
I guess it was a wiring issue.
Thank you, everyone, for your time on this.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.