We will input the data into the following port. You need to raise the button’s value to +5 V. If you press the button on Arduino’s 3rd port, you’ll see a 0. The standing location for the joystick is 511 for each regulator. The data from the regulators on the X and Y axes can be from 0 to 1023.
#Usb joystick controller with analog inputs code
Next, I will explain how the code works.īelow, there’s a code of getting data from the joystick. You can upload the following example code to your Arduino using the Arduino IDE. Now that you have wired up the joystick it is time to connect the Arduino to the computer and upload some code. In the end, it should look something like the pictures: Analog joystick connected to Arduino Analog joystick connected to Arduino Analog joystick connected to Arduino Example code for the analog joystick with Arduino
#Usb joystick controller with analog inputs how to
The wiring diagram below shows you how to connect the analog joystick to the Arduino. Note: is a participant in the Amazon Services LLC Associates Program SoftwareĪrduino IDE Wiring – Connecting the Joystick to Arduino UNO To follow this tutorial you need the following components: Hardware components: Arduino Uno Analog Joystick Technical Specifications Operating Voltageġ.57 in x 1.02 in x 1.26 in (4.0 cm x 2.6 cm x 3.2 cm)įor more information, you can check out the datasheet here: KY-023 Datasheet Things used in this tutorial If you don’t need the button then you can use only 4 pins. GND – Connect this to your ground line (GND). SW (KEY or SEL) – This is the digital output from the pushbutton, normally open, will connect to GND when the button is pushed. HORIZ (vrX) – This is the horizontal analog output voltage (will be about half of VCC when the joystick is centered). VERT (vrY) – This is the vertical analog output voltage (will be about half of VCC when the joystick is centered). VCC (5v) – Connect this to your positive supply (usually 5V or 3.3V depending on your logic levels). I’ve described the corresponding pin names for various manufacturers below. Analog Joystick Analog Joystick Analog Joystick Be aware that the notation might be different in your module. The module has 5 pins: VCC, GND, HORIZ, VERT, SEL. Meaning when the joystick is in the center, the X and Y coordinate values might be in a range from 490 to 530 and not exactly 512. That’s because the joystick handle doesn’t always return exactly to the central location, so you have to take this into account when programming the handle’s central location as a small range of values, not a specific one. The KY-023 joystick model has its own deficiencies. When connected to analog ports, VRx to A0 and VRy to A1 respectively, they should transmit the values as shown in the image below. The value on every analog channel can vary from 0 to 1023. When the joystick is released, it smoothly returns to its central (0) location. The handle’s angle rotates the regulators and changes the output voltage letting it monitor the handle’s gradient from the central spot. The analog joystick has a handle that is attached to the joint with two regulators that determine the joysticks location on the X and Y-axes and the button on the Z-axis. In this lesson, I’ll show you how to use the analog joystick module with Arduino Uno.
Connecting a joystick to Arduino will let you remotely control a machine or robot with Arduino.