Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Joystick Controller with Serial Output

View and Edit Project In Cirkit DesignerImage of Arduino UNO Joystick Controller with Serial Output

Circuit Documentation

Summary

This circuit utilizes an Arduino UNO microcontroller and an Analog Joystick to read the joystick's position and button state. The Arduino processes the joystick's vertical and horizontal movements and the button press, outputting the values to the serial monitor for debugging or further processing.


Component List

Arduino UNO

Analog Joystick


Wiring Details

Arduino UNO


Documented Code

void setup() {
  Serial.begin(9600); // Start serial communication at 9600 baud
  pinMode(2, INPUT_PULLUP); // Set pin D2 as input with internal pull-up resistor
}

void loop() {
  int vertValue = analogRead(A0); // Read vertical position
  int horzValue = analogRead(A1); // Read horizontal position
  int selValue = digitalRead(2); // Read button press (0 if pressed, 1 if not pressed)

  Serial.print("Vertical: ");
  Serial.print(vertValue);
  Serial.print(" Horizontal: ");
  Serial.print(horzValue);
  Serial.print(" Button: ");
  Serial.println(selValue == LOW ? "Pressed" : "Not Pressed");

  delay(500); // Delay for half a second
}

This code initializes the serial communication and sets up the necessary pin modes. In the loop, it continuously reads the joystick's vertical and horizontal positions and the button state, printing the results to the serial monitor every half second.