My joystick doesn't work

I have Arduino UNO and i found some diy game joystick tutorial on YT
code:

// Arduino pin numbers
const int SW_pin = 2; // digital pin connected to switch output
const int X_pin = 14; // analog pin connected to X output
const int Y_pin = 15; // analog pin connected to Y output

void setup() {
pinMode(SW_pin, INPUT);
digitalWrite(SW_pin, HIGH);
Serial.begin(115200);
}

void loop() {
Serial.print("Switch: ");
Serial.print(digitalRead(SW_pin));
Serial.print("\n");
Serial.print("X-axis: ");
Serial.print(analogRead(X_pin));
Serial.print("\n");
Serial.print("Y-axis: ");
Serial.println(analogRead(Y_pin));
Serial.print("\n\n");
delay(500);
}

scheme:

can you help me? (video: How to connect and use an Analog Joystick with an Arduino - Tutorial - YouTube)

Welcome to the forum

Your topic was MOVED to its current forum category which is more appropriate than the original as it has nothing to do with Installation and Troubleshooting of the IDE

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

Measure the voltage on the vrx and vry control potentiometers with a DMM.

Do you see a 0 to 5v swing.


const int X_pin = 14; // analog pin connected to X output
const int Y_pin = 15; // analog pin connected to Y output

For documentation, use A0 and A1 as you are measuring voltages.

As @LarryD said. You should use A0 and A1 instead of writing 14 &15

@tikulik - Try this simulation. It has your code, and you can save it and change it as you feel. Press the green > button, then mouse-click on the four joystick directions.

Maybe. You never said what was wrong.

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