How to connect and use an Analog Joystick with an Arduino

In this article, you will learn how to connect and use an Analog Joystick with an Arduino.

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

joystick module pin diagram

Interfacing Joystick Module with Arduino

Joystick Module with Arduino Circuit Diagram

arduino joystick circuit

Arduino Code for Joystick Module

/* For more projects and tutorials visit
   https://electronicsprojectshub.com/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.

 

Leave a Reply