Introduction: Arduino Joystick Module Tutorial

Hi guys in this instructables we will learn how to use joystick module with Arduino and how we can read the data from joystick module using arduino uno on the serial monitor.

Step 1: Things You Need

For this instructables we will need following things :

Arduino uno :


Joystick Module :


Jumper wires :



Breadboard (optional) :

Step 2: Schmatics

Connect everything According to the shown schmatics in the image and everything will be good.

Step 3: Code

Please copy the following code and upload it to the arduino Board :


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

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

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);

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

//activate pull-up resistor on the push-button pin
pinMode(buttonPin, INPUT_PULLUP);

// For versions prior to Arduino 1.0.1
// pinMode(buttonPin, INPUT);
// digitalWrite(buttonPin, HIGH);

}

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); // add some delay between reads
}





Step 4: Final Step

After connecting everything together and uploading the code to arduino, you can connect the cable to pc and open the serial monitor and on serial monitor whenever you will move the joystick you can see the changed joystick's Potentiometer X & potentiometer Y values on your serial monitor.