Built-in project · Arduino Uno R3

Joystick on A0, A1 and pin 8, on an Arduino Uno

A joystick module with X on A0, Y on A1 and its switch on pin 8 (internal pull-up): the sketch prints both axes and whether the stick is pressed. The whole build, an Arduino Uno and 1 more part, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Beginner Runs in your browser. Free, and no account needed.

Joystick on A0, A1 and pin 8 · Arduino Uno R3live0.000 s 0.00x
Drag the joystick
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · Arduino Uno R3
// A joystick: X on A0, Y on A1, the press switch on pin 8.
//
//   VCC -> 5V   GND -> GND   VRx -> A0   VRy -> A1   SW -> pin 8
//
// Each axis is a potentiometer: centered it reads about 512, pushed to the
// ends near 0 or 1023. The switch joins SW to ground when the stick is
// pressed, so pin 8 uses the internal pull-up and reads LOW while pressed.
//
// Drag the stick, or click it.

const int X_PIN = A0;
const int Y_PIN = A1;
const int SW_PIN = 8;

void setup() {
  pinMode(SW_PIN, INPUT_PULLUP);
  Serial.begin(9600);
  Serial.println("Mokxi Uno: joystick on A0, A1 and pin 8");
}

void loop() {
  Serial.print("X: ");
  Serial.print(analogRead(X_PIN));
  Serial.print("  Y: ");
  Serial.print(analogRead(Y_PIN));
  Serial.print("  Z: ");
  Serial.println(digitalRead(SW_PIN) == LOW ? "pressed" : "up");
  delay(500);
}

Parts list

3 parts, plus the jumper wires. Every one is in the editor's parts bin.

How it is wired

5 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.

  • Ground: Arduino Uno R3 pin GND; Thumb stick pin GND
  • Arduino Uno R3 pin 8; Thumb stick pin SW
  • Arduino Uno R3 pin 5V; Thumb stick pin VCC
  • Arduino Uno R3 pin A0; Thumb stick pin VRX
  • Arduino Uno R3 pin A1; Thumb stick pin VRY

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.