In this article, you will learn how to connect and use an Analog Joystick with an Arduino.
Contents
This joystick module maybe the best choice for your controller of DIY project. It has two analog input pins to control X, Y axis and also has button input, someone may call it Z axis, but it only input digital signal with 0 or 1.
Components Required
Arduino Uno [ Amazon / Gearbest / Banggood ]
Joystick module [ Gearbest / Amazon / Banggood ]
Jumper wires x5 [ Amazon / Gearbest / Banggood ]
*Please note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!
Joystick Module Pin Diagram
Procedure
Step 1: Build the circuit
Joystick Module Arduino Uno
SW ————————————– D2
VRx ————————————- A0
VRy ————————————- A1
+5V ————————————- 5V
GND ———————————— GND
Step 2: Download the code
Step 3: Upload the code to your Arduino Uno (any Arduino board)
Now, push the rocker and the coordinates of X and Y axes displayed on Serial Monitor will change accordingly, press the button, and the coordinate of Z=0 will also be displayed.
Interfacing Joystick Module with Arduino
Joystick Module with Arduino Circuit Diagram
Arduino Code for Joystick Module
/* For more projects and tutorials visit http://3.7.27.83/category/arduino/ */ // Arduino pin numbers int SW = 2; // digital pin connected to switch output // A0-> X ; A1-> Y; void setup() { pinMode(SW, INPUT); digitalWrite(SW, HIGH); Serial.begin(115200); } void loop() { Serial.print("Switch: "); Serial.print(digitalRead(SW)); Serial.print("\n"); Serial.print("X-axis: "); Serial.print(analogRead(A0)); Serial.print("\n"); Serial.print("Y-axis: "); Serial.println(analogRead(A1)); Serial.print("\n"); delay(500); }
If you have any queries, please comment below. We will reach you soon.