Joystick Button/Switch Issue

So I'm working on a small project with the UNO that requires me to use the analog joystick's button fonctionality. However I just can't seem to get it to work. The joystick only outputs 0's no matter what I do, only rarely but somewhat randomly spitting out a 1.

Here's the code:

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

void loop() { Serial.print(digitalRead(10)); delay(100); }

The joystick is just attached to 5v, GND, and SW to pin 10.

The joystick is just attached to 5v, GND, and SW to pin 10

Are they the only connections to the joystick ? Where did you get the joystick from ?

Have you any idea how the switch is wired in the joystick ? Does it go to 5V or GND when pressed, for instance ?

The joystick it just one of these [attached] it should be outputting a HIGH digital on the SW pin when pressed.

dual-axis-xy-joystick-module-ps2-for-arduino-and-others-joystick-module-500x500.jpg

Try this instead

void setup()
{
  pinMode(10, INPUT_PULLUP);
  Serial.begin(115200);
}

void loop()
{
  Serial.println(digitalRead(10));
  delay(100);
}

Change the baud rate to suit yourself