Circuit Documentation
Summary
This circuit integrates an Arduino UNO microcontroller with an Analog Joystick (Wokwi Compatible). The joystick provides two-dimensional input by outputting analog signals corresponding to the X (horizontal) and Y (vertical) axes. The Arduino UNO reads these analog signals and outputs the joystick's position through its serial interface. This setup can be used for various control applications, such as robotics or game controllers.
Component List
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- Pins Used:
5V: Power supplyGND: GroundA0: Analog input for vertical axis of joystickA1: Analog input for horizontal axis of joystick
Analog Joystick (Wokwi Compatible)
- Description: A two-axis analog joystick with a push-button.
- Pins Used:
VCC: Power supplyGND: GroundVERT: Vertical axis outputHORZ: Horizontal axis output
Wiring Details
Arduino UNO
5Vconnected to JoystickVCCGNDconnected to JoystickGNDA0connected to JoystickVERT(Vertical Axis)A1connected to JoystickHORZ(Horizontal Axis)
Analog Joystick (Wokwi Compatible)
VCCconnected to Arduino UNO5VGNDconnected to Arduino UNOGNDVERTconnected to Arduino UNOA0HORZconnected to Arduino UNOA1
Documented Code
// Code for Arduino UNO to read joystick values and print them to the serial monitor
const int xPin = A0; // Joystick horizontal axis
const int yPin = A1; // Joystick vertical axis
float xValue, yValue;
void setup() {
pinMode(xPin, INPUT); // Set the joystick horizontal axis as input
pinMode(yPin, INPUT); // Set the joystick vertical axis as input
Serial.begin(9600); // Start serial communication at 9600 baud
}
void loop() {
xValue = analogRead(xPin); // Read the horizontal axis value
yValue = analogRead(yPin); // Read the vertical axis value
// Print the values to the serial monitor
Serial.print("Value of x-axis: ");
Serial.println(xValue);
Serial.print("Value of y-axis: ");
Serial.println(yValue);
delay(100); // Wait for 100 milliseconds before the next read
}
Filename: sketch.ino
This code initializes the Arduino UNO to read the analog values from the joystick's vertical and horizontal axes. It then prints these values to the serial monitor every 100 milliseconds. The xPin and yPin are defined as constants corresponding to the Arduino's analog input pins A0 and A1, respectively. The setup() function initializes the serial communication and configures the joystick pins as inputs. The loop() function continuously reads the analog values from the joystick and outputs them to the serial monitor.
