So I was trying to connect an Arduino Nano to a joystick module and get the joystick's output. Turns out it is outputting seemingly random values.
So I connected the 5V of the joystick to the 5V of the arduino, the GND to GND and the X and Y to the A0 and A1 pins. I will put the code below. Now when I run the program It seems to output random values that start at 1023, stay that way for a few seconds and then go abruptly down to 0 and stay that way and then suddenly back to 1023 and the cycle goes on and on. It somehow worked for like 20 seconds even though I hadn't changed anything at all. I doubt the problem is in the Arduino, since I tested the same thing with two potentiometers and it works just fine.
Any ideas?
So I connected the 5V of the joystick to the 5V of the arduino, the GND to GND and the X and Y to the A0 and A1 pins. I will put the code below. Now when I run the program It seems to output random values that start at 1023, stay that way for a few seconds and then go abruptly down to 0 and stay that way and then suddenly back to 1023 and the cycle goes on and on. It somehow worked for like 20 seconds even though I hadn't changed anything at all. I doubt the problem is in the Arduino, since I tested the same thing with two potentiometers and it works just fine.
Any ideas?
Code:
void setup() {
Serial.begin(9600);
pinMode(A0,INPUT);
pinMode(A1,INPUT);
}
void loop() {
Serial.print("X: ");
Serial.print(analogRead(A0));
Serial.print(" Y: ");
Serial.print(analogRead(A1));
delay(300);
}