Skip to content

Electronic components: Analog Joystick

New Course Coming Soon:

Get Really Good at Git

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:

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() {

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

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.

Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. A course that helps you feel less frustrated with Git. Launching Summer 2024. Join the waiting list!

Here is how can I help you: