Arduino Joystick Module Tutorial

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.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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.

Be the First to Share

    Recommendations

    • Trash to Treasure Contest

      Trash to Treasure Contest
    • Raspberry Pi Contest 2020

      Raspberry Pi Contest 2020
    • Wearables Contest

      Wearables Contest

    Discussions