Introduction
In this article, I am going to explain about how to connect Arduino joystick in Arduino Uno. I am going to execute how the joystick will work with Arduino.
Parts of lists
- Arduino Uno
- Arduino joystrick
- Hook-Up wires.
Parts Explanation
Arduino joystick
- Arduino joystick is a device which can be used to measure the X-axis,Y-axis and Z-axis direction. It is also called the game console. It can be considered as the combination of potentiometer and one button.
Figure 1 - Arduino Joystick.
Connection
- Connection to Arduino and Arduinojoystick.
- Connect Vcc of joystick pin to the 5v of Arduino Uno.
- Connect Gnd of joystick pin to the Gnd of Arduino Uno.
- Connect I Rx of joystick pin to the 0 of Arduino Uno.
- Connect I RY Vcc of joystick pin to the 1 of Arduino Uno.
- Connect SW of joystick pin to the 2 of Arduino Uno.
Figure 2 - Connection
Programming- Count int SW - Pin = 2;
- Count intX - Pin = 0;
- Count intY - Pin = 1;
- Void Setup() {
- PinMode(SW - Pin.INPUT);
- digitalwrite(SW - Pin, HIGH);
- Serial.begin(115200);
- }
- Void loop() {
- Serial.print("Switch: ");
- Serial.Print(4 digitalread(sw - pin));
- Serial.print(\n);
- Serial.print("X-axis: ");
- Serial.print(analogread(X - axis));
- Serial.print("Y-axis: ");
- Serial.print(analogread(Y - axis));
- Serial.print("\n\n");
- delay(500);
- }
Explanation
- Joystick can show the direction i.e. the movement, which we had given, then it will show in the Serial monitor at what direction it was moving.
- Subsequently, it can be used for the major realtime projects like using truck and traffic signal direction etc.
Output
Figure 3 - Output