help i'm new

Hello guys i’m new programing arduino and i want a joystick with 3 axis moving on arduino uno, but just the Z axis active, can someone tell me if my code is wrong or i miss something. Image at Attchments thanks

Being new does not excuse posting code as an image...

Please post here using code tags

Also explain how you wired everything

J-M-L:
Being new does not excuse posting code as an image…

Please post here using code tags

Also explain how you wired everything

int xPin = A1;
int yPin = A0;
int buttonPin = 2;

int xPosition = 0;
int yPosition = 0;
int buttonState = 0;

void setup() {
Serial.begin(9600);

pinMode(xPin, INPUT);
pinMode(yPin, INPUT);

pinMode(buttonPin, INPUT_PULLUP);

}

void loop() {
xPosition = analogRead(xPin);
yPosition = analogRead(yPin);
buttonState = digitalRead(buttonPin);

Serial.print("X: “);
Serial.print(xPosition);
Serial.print(” | Y: “);
Serial.print(yPosition);
Serial.print(” | Button: ");
Serial.println(buttonState);

delay(100);
}

Works perfectly for me... x and y pots both display 512 in the middle and go from 0 to 1023 as expected.

const byte xPin = A1;
const byte yPin = A0;
const byte buttonPin = 2;

void setup() {
 Serial.begin(9600); 

 pinMode(buttonPin, INPUT_PULLUP); 
}

void loop() {
 int xPosition = analogRead(xPin);
 int yPosition = analogRead(yPin);
 int buttonState = digitalRead(buttonPin);

 Serial.print("X: ");
 Serial.print(xPosition);
 Serial.print(" | Y: ");
 Serial.print(yPosition);
 Serial.print(" | Button: ");
 Serial.println(buttonState);

 delay(100);
}

No point in making things longer than they have to be.

Also, note the code tags.

should work - double check your wiring - if all is fine there, then your unit is defective probably...

thanks guys.