# Joystick

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-b3d296389f4ede893e90114b9ecf56336e12a085%2Fimage.png?alt=media)

**Introduction**

Lots of robot projects need joystick. This module provides an affordable solution. By simply connecting to two analog inputs, the robot is at your commands with X, Y control. It also has a switch that is connected to a digital pin. This joystick module can be easily connected to Arduino by IO Shield.

**Specification**

* Supply Voltage: 3.3V to 5V
* Interface: Analog x2, Digital x1

**Connection Diagram**\\

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-ef191c5cc721cc034f1a282b3ac67b7c28e8a4d7%2Fimage.png?alt=media)

**Sample Code**

```
int JoyStick_X = 0; //x
int JoyStick_Y = 1; //y
int JoyStick_Z = 3; //key
  void setup() 
{
  pinMode(JoyStick_Z, INPUT); 
  Serial.begin(9600); // 9600 bps
}
void loop() 
{
  int x,y,z;
  x=analogRead(JoyStick_X);
  y=analogRead(JoyStick_Y);
  z=digitalRead(JoyStick_Z);
  Serial.print(x ,DEC);
  Serial.print(",");
  Serial.print(y ,DEC);
  Serial.print(",");
  Serial.println(z ,DEC);
  delay(100);
}
```

**Result**

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-46c6487cd40b285e8dfab1f8301b384b37aac6ee%2Fimage.png?alt=media)

Wiring well and uploading the code, open the serial monitor and set the baud rate to 9600, push the joystick, you will see the value shown below.

![](https://451694785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPda5vaSVRKTQ6AoAmb%2Fuploads%2Fgit-blob-4d8fd8b05e36fd56c6a403943e9118eea8e156ab%2Fimage.png?alt=media)
