Arduino Joystick Module Tutorial

by Utsource in Circuits > Arduino

955 Views, 0 Favorites, 0 Comments

Arduino Joystick Module Tutorial

20191118_102351.jpg
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.

Things You Need

Km5Zu-2RIncAUweU7uG7IhyWPySZ0SqIgAI0-vk9w7767_IkthCPCcsirj2GGmXF4IdQDg8UVpHVLVM6CXnzFsG1hnAdSkK7BIhIOtEldXoZiDsvzsPo-6o0rD6Mda7UyOE=w456-h323-nc.png
images(111).jpg

For this instructables we will need following things :

Arduino uno :


Joystick Module :


Jumper wires :



Breadboard (optional) :

Schmatics

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

Code

images(110).jpg
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
}





Final Step

Screenshot_20191118-102253__01.jpg
Screenshot_20191118-102258__01.jpg
Screenshot_20191118-102302__01.jpg
Screenshot_20191118-102306__01.jpg
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.