Joystick Arduino

Introduction to the Joystick for Arduino

Principle of operation

The joystick for Arduino is an analog control similar to that has the Dualshock de la Play Station, this device allows us to three inputs, two analog variables that control the position in X and and and a digital when the button is pressed. Applications can be as many as we imagine from control any robot, even creating music or as driver for LCD screens.

Here we will show a small program to set and get the values of the device.

Joystick Arduino
Analog joystick for Arduino

 

Connection of the Joystick

It has five two power and three pins that will be the outputs.

  • GND: GND of Arduino.
  • + 5V: power, five 5V Arduino.
  • VRx: Analogue output shaft X 0-5V, while in 2, 5V when it is centered
  • VRy: Output analog axis and, similar to the previous one.
  • SW: (Switch) 0 usually and 1 by pressing the central button.

Characteristics of analog Joystick

Work voltage 5V DC
Dimensions 4.0 cm x 2.6 cm x 3.2 cm

 

Connection of the Joystick analog for Arduino

Design prototyping of the Joystick with Arduino Mega

Prototyping of the Joystick
Example of connection of the analogue Joystick for Arduino

Wiring diagram of Joystick with an Arduino Mega

Electkrico scheme for the Joystic
Wiring diagram of the analog Joystick for Arduino Mega

Programming of the Joystick

Explanation prior

As we can see in the connection, we feed our Joystick using the output + 5V Arduino and the GND, then connect the horizontal and vertical values (or VRx and VRy) according to manufacturer the analogue input 0 to 1 of our Arduino Mega, have used digital 8 pin as input to the central button.

Code

 /*
Reading of the Joystick analog to Araduino
*/
int analogInputPinX = 0; X-axis analog input pin
int analogInputPinY = 1; The psoocion analog input pin 
int digitalInputPin = 8; Input pressing the central button pin

int wait = 1000; 
long analogInputValX;
long analogInputValY;
int digitalInputVal;

void setup()
{
  pinMode (analogInputPinX, INPUT);
  pinMode(analogInputPinY, INPUT);
  pinMode (digitalInputPin, INPUT);
    
  Serial.begin (9600);  
}

void loop()
{
  analogInputValX = analogRead (analogInputPinX);
  analogInputValY = analogRead (analogInputPinY);
  digitalInputVal = digitalRead (digitalInputPin);
  
      Serial.print ("middle button");
      Serial.print (digitalInputVal);
      Serial.print ("X axis");
      Serial.print (analogInputValX);    
      Serial.print("eje Y");
      Serial.print (analogInputValY);    
      Serial.println("");
   
  delay (wait); Pause for retormar the loop
}


Once programmed, we will see changes in the serial monitor.

Video of operation

Source: goodliffe

Among other things I do projects and give courses of Arduino.

 Buy JoyPad for Arduino

You need buy a JoyPad for your projects of Arduino? Click here to see our selection of products.

Summary
Description
Example of as get the data of a Joystick analog with an Arduino Mega for show in the monitor serial this device has large applications
Author
Publisher Name
Drouiz
Publisher Logo

Leave a Reply

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.