How to simply interface the Joystick module with Arduino board
Hello there,
In this tutorial we gonna try to interface a Joystick module with an Arduino board, here as usual I’m using an Arduino Uno board. This module permit you to control robots, robots arms, motors… for example: control the motion of a robot (speed, direction), control robot arms positions….
You can check this project where I used this module to control an Arduino camera crane: Control dual axis FPV camera cradle with Joystick module
Learning how to use this module will help you using the PS2 wireless controller which I used for a simple project and for a robot:
The module I’m using has 5 pins (Vcc, GND, Xaxis,Yaxis and the push button pin):

The joystick have 2 centered potentiometers, when powered they deliver an analog signal, and when used with Arduino it has these values: “0-1023”, and since they’re centered at standby they give the values around “512”, and for the button it has a digital output 0/1.
Wirings:
Wiring 1: no button problem
This normally the wiring, in case you don’t have the problem like me with the push button (check the video), it’s simple 5v and GND from the Arduino then we wire the pins X axis and Y axis with analog inputs here I used A0 and A1, and for last we wire the button pin with a Digital I/O here I used D2
Wiring 2: in case you got the same problem as me
Codes:
Here are “.ino” codes I used in the video, you can find X axis alone, Y axis alone and( X and Y), also the button alone, it’s simple to assemble them
Code 1: X axis simple reading
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
//This code is to use with Joystick module, here after wiring the XAxis pin from the module with A0 //We try to get the value of the potentiometer and show it on the serial monitor //Refer to https://surtrtech.com/ for further information int XAxis = 0; //Declaring where the pin is wired void setup() { Serial.begin(9600); //Setting the Serial monitor baude rate and launching pinMode(XAxis, INPUT); //Declaring the pin mode } void loop() { Serial.println(analogRead(XAxis)); //Read and show directly on the serial monitor the value (0-1023) } |
Code 2: Y axis simple reading
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
//This code is to use with Joystick module, here after wiring the YAxis pin from the module with A0 //We try to get the value of the potentiometer and show it on the serial monitor //Refer to https://surtrtech.com/ for further information int YAxis = 1; //Declaring where the pin is wired void setup() { Serial.begin(9600); //Setting the Serial monitor baude rate and launching pinMode(YAxis, INPUT); //Declaring the pin mode } void loop() { Serial.println(analogRead(YAxis)); //Read and show directly on the serial monitor the value (0-1023) } |
Code 3: Button reading
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
//This code is to use with Joystick module, here after wiring the button pin from the module with D2 //We try to get the value of the potentiometer and show it on the serial monitor //Refer to https://surtrtech.com/ for further information int ButtonPin = 2; //Declaring the button pin void setup() { Serial.begin(9600); // Serial monitor baude rate and intializing and pinmode pinMode (ButtonPin,INPUT); } void loop() { Serial.println(digitalRead(ButtonPin)); //Reading the button value and show it on the serial monitor (0-1) } |
Code 4: X and Y axis reading
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
//This code is to use with Joystick module, here after wiring the Xaxis and Yxxis pin from the module with A0 and A1 //We try to get the values of the two potentiometers and show them on the serial monitor //Refer to https://surtrtech.com/ for further information int YAxis = 1; //Delaring where the two pins are wired int XAxis = 0; void setup() { Serial.begin(9600); // Serial monitor baude rate and intializing pinMode(YAxis, INPUT); //pinmodes pinMode(XAxis, INPUT); } void loop() { Serial.print("X Axis: "); //Print on the serial monitor both values as shown in the video Serial.print(analogRead(XAxis)); Serial.print(" Y Axis: "); Serial.println(analogRead(YAxis)); } |
Categories
Yassine View All
Automation and Electrical Engineer, Electronics amateur trying to share my little projects.
2 thoughts on “How to simply interface the Joystick module with Arduino board” Leave a comment ›