Electronic components: Analog Joystick

The analog joystick is one of those electronic components you have certainly used while playing video games:

You can move the joystick around, and you can also click it from top to bottom:

Any action performed will send the appro…


This content originally appeared on flaviocopes.com and was authored by flaviocopes.com

The analog joystick is one of those electronic components you have certainly used while playing video games:

You can move the joystick around, and you can also click it from top to bottom:

Any action performed will send the appropriate electronic signals to the circuit it’s connected to.

The 5 pins of the joystick are:

  • GND, the input LOW signal
  • +5V, the input HIGH signal, can also be 3.3V when using a 3.3V based device
  • VRx, the analog signal that represents the position of the joystick on the x axis
  • VRy, the analog signal that represents the position of the joystick on the y axis
  • SW, short for switch, is the digital value LOW when pressed, otherwise HIGH

You connect VRx and VRy to an analog input pin to get their value.

Analog inputs range from 0 to 1023 since they use a 10 bits resolution.

When watching the joystick with the pins on the left, the X axis values assumes values from 0 (full left) to 1023 (full right) and 498 in the middle. The Y axis values assumes values from 0 (top) to 1023 (bottom) and 498 in the middle.

Assuming VRx is connected to A0 and VRy to A1:

int x = analogRead(A0);
int y = analogRead(A1);

A simple program that prints the values is this:

void setup() {
  Serial.begin(9600);
}

void loop() {
  int x = analogRead(A0);
  int y = analogRead(A1);
  Serial.print("X = ");
  Serial.print(x);
  Serial.print("\tY = ");
  Serial.println(y);
  delay(100);
}

You can also think of them as voltage values. Assuming a 5V positive voltage, you can multiply the value you get by 5.0, and then divide it by 1023 to get a 0 to 5 range:

x = analogRead(A0);
y = analogRead(A1);

float x_val = (x * 5.0) / 1023;

You can perform a similar calculation to get the values relative to a 3.3V Vcc.


This content originally appeared on flaviocopes.com and was authored by flaviocopes.com


Print Share Comment Cite Upload Translate Updates
APA

flaviocopes.com | Sciencx (2021-03-15T05:00:00+00:00) Electronic components: Analog Joystick. Retrieved from https://www.scien.cx/2021/03/15/electronic-components-analog-joystick/

MLA
" » Electronic components: Analog Joystick." flaviocopes.com | Sciencx - Monday March 15, 2021, https://www.scien.cx/2021/03/15/electronic-components-analog-joystick/
HARVARD
flaviocopes.com | Sciencx Monday March 15, 2021 » Electronic components: Analog Joystick., viewed ,<https://www.scien.cx/2021/03/15/electronic-components-analog-joystick/>
VANCOUVER
flaviocopes.com | Sciencx - » Electronic components: Analog Joystick. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/03/15/electronic-components-analog-joystick/
CHICAGO
" » Electronic components: Analog Joystick." flaviocopes.com | Sciencx - Accessed . https://www.scien.cx/2021/03/15/electronic-components-analog-joystick/
IEEE
" » Electronic components: Analog Joystick." flaviocopes.com | Sciencx [Online]. Available: https://www.scien.cx/2021/03/15/electronic-components-analog-joystick/. [Accessed: ]
rf:citation
» Electronic components: Analog Joystick | flaviocopes.com | Sciencx | https://www.scien.cx/2021/03/15/electronic-components-analog-joystick/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.