Joystick weird z reading

Hi guys,

I’ve recently purchased two keyes_SJoys:

Reading out the x and y values work perfectly.

But reading out the switch causes problems. I noticed that the signal is low when the button is pressed. But when the button is not pressed, it seems to switch between high and low signal. When I attached the switch to an analog input, I noticed the value is not stable.
Does anyone have an idea why my value is fluctuating? see attached image.

My arduino uno is powered by USB. I checked and the joystick receives 5V on the corresponding pin. I checked and double checked the wiring, and there shouldn’t be a problem there. Again, i get a good reading from the x and y data.

Thanks in advance.

pinMode(joySw, INPUT_PULLUP);

That will cause the internal pullup resisitor toforce the pin high when it's not switched low.

JimboZA: you are my hero, thank you!

It works perfectly.