How To Connect Arduino Joystick In Arduino Uno

Introduction

 
In this article, I am going to explain how to connect Arduino joystick in Arduino Uno. I am going to execute how the joystick will work with Arduino.
 
Parts of lists
  • Arduino Uno
  • Arduino joystick
  • Hook-Up wires.
Parts Explanation
 
Arduino joystick
  • Arduino joystick is a device that can be used to measure the X-axis, Y-axis and Z-axis direction. It is also called the game console. It can be considered as a combination of a potentiometer and one button.
     
     
    Figure 1 - Arduino Joystick.
Connection
  • Connection to Arduino and Arduinojoystick.
  • Connect Vcc of joystick pin to the 5v of Arduino Uno.
  • Connect Gnd of joystick pin to the Gnd of Arduino Uno.
  • Connect I Rx of joystick pin to the 0 of Arduino Uno.
  • Connect I RY Vcc of joystick pin to the 1 of Arduino Uno.
  • Connect SW of joystick pin to the 2 of Arduino Uno.
     
     
    Figure 2 - Connection
Programming
  1. Count int SW - Pin = 2;  
  2. Count intX - Pin = 0;  
  3. Count intY - Pin = 1;  
  4. Void Setup() {  
  5.     PinMode(SW - Pin.INPUT);  
  6.     digitalwrite(SW - Pin, HIGH);  
  7.     Serial.begin(115200);  
  8. }  
  9. Void loop() {  
  10.     Serial.print("Switch: ");  
  11.     Serial.Print(4 digitalread(sw - pin));  
  12.     Serial.print(\n);  
  13.     Serial.print("X-axis: ");  
  14.     Serial.print(analogread(X - axis));  
  15.     Serial.print("Y-axis: ");  
  16.     Serial.print(analogread(Y - axis));  
  17.     Serial.print("\n\n");  
  18.     delay(500);  
  19. }  
Explanation
  • Joystick can show the direction i.e. the movement, which we had given, then it will show in the Serial monitor at what direction it was moving.
  • Subsequently, it can be used for major realtime projects like using truck and traffic signal direction, etc.
Output
 
 
Figure 3 - Output