Arduino SA
Search…
Joystick
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
Sample Code
1
int JoyStick_X = 0; //x
2
int JoyStick_Y = 1; //y
3
int JoyStick_Z = 3; //key
4
void setup()
5
{
6
pinMode(JoyStick_Z, INPUT);
7
Serial.begin(9600); // 9600 bps
8
}
9
void loop()
10
{
11
int x,y,z;
12
x=analogRead(JoyStick_X);
13
y=analogRead(JoyStick_Y);
14
z=digitalRead(JoyStick_Z);
15
Serial.print(x ,DEC);
16
Serial.print(",");
17
Serial.print(y ,DEC);
18
Serial.print(",");
19
Serial.println(z ,DEC);
20
delay(100);
21
}
Copied!
Result
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.
Last modified 4mo ago
Copy link