Joystick with Arduino :

Joystick is basically a gaming controller. They are used for playing games. It is an input device. It is also called Control stick. In Electronics, you can do a lot of fun with it. Like controlling a robot, a car, controlling the movement of camera etc.

Joystick

Joystick is similar like two potentiometer are connected together 1 for x-axis and the other for y-axis.

working of Joystick

Components :

  • Arduino Uno
  • Jumper wires
  • Joystick

Joystick pinout :

Joystick Pinout
  • VCC –> 5V
  • GND –> GND
  • VRx –> A0
  • VRy –> A1
  • SW –> D2

Circuit Diagram :

Code :

#define joyX A0
#define joyY A1
#define SW 2
double xValue = 0;
double yValue = 0;


void setup() {
  Serial.begin(9600);
  pinMode(SW, INPUT_PULLUP);
}

void loop() {

  xValue = analogRead(joyX);
  yValue = analogRead(joyY);


//  xValue = map(xValue, 0, 1023, 0, 10000);
//  yValue = map(yValue, 0, 1023, 0, 10000);
  Serial.print ("xValue");
  Serial.print (xValue,0);
  Serial.print ("\t");
  Serial.print ("yValue");
  Serial.println (yValue,0);
  if(digitalRead(SW) == LOW)
  Serial.print("\n\n Button pressed \n\n");
}

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Facebook
YouTube
× Contact us