This circuit utilizes an Arduino UNO microcontroller and an Analog Joystick to read the joystick's position and button state. The joystick provides two analog outputs for vertical and horizontal movement, as well as a digital output for a button press. The Arduino processes these inputs and outputs the values to the serial monitor for debugging and monitoring purposes.
5V: Connected to the VCC pin of the Analog Joystick.
GND: Connected to the GND pin of the Analog Joystick.
A0: Connected to the VERT pin of the Analog Joystick (reads vertical position).
A1: Connected to the HORZ pin of the Analog Joystick (reads horizontal position).
D2: Connected to the SEL pin of the Analog Joystick (reads button press).
VCC: Connected to the 5V pin of the Arduino UNO (provides power).
GND: Connected to the GND pin of the Arduino UNO (common ground).
VERT: Connected to the A0 pin of the Arduino UNO (analog input for vertical movement).
HORZ: Connected to the A1 pin of the Arduino UNO (analog input for horizontal movement).
SEL: Connected to the D2 pin of the Arduino UNO (digital input for button press).
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, as well as the button state, and prints these values to the serial monitor every half second.