Home SensorsKit Arduino and KY-023 Joystick

Arduino and KY-023 Joystick

by shedboy71

In this article, we connect an KY-023 Joystick to an Arduino Uno

The (KY-023) module is an input device for gaming, controlling stepper motors, servos, and remote control robotics projects.

These module has both analog (AO) and digital (DO) output options. It can also be known as the Ps2 joystick module

Parts Required

You can connect to the module using dupont style jumper wire.

This should work with other Arduino board – I have tried an Uno and Mega

Name   Link
Arduino Uno
37 in one sensor kit
Connecting cables

 

Schematic/Connection

I used pin 2 for the switch and A1 and A2 for the analog x and y axis – you can change these but will need to change the code if you want to do this

Code Example

// Arduino pin numbers - you can change these
const int SW_pin = 2; // digital pin connected to switch output
const int X_pin = 0; // analog pin connected to X output
const int Y_pin = 1; // analog pin connected to Y output
 
void setup() 
{
  pinMode(SW_pin, INPUT);
  digitalWrite(SW_pin, HIGH);
  Serial.begin(115200);
}
 
void loop() 
{
  Serial.print("Switch:  ");
  Serial.print(digitalRead(SW_pin));
  Serial.print("\n");
  Serial.print("X-axis: ");
  Serial.print(analogRead(X_pin));
  Serial.print("\n");
  Serial.print("Y-axis: ");
  Serial.println(analogRead(Y_pin));
  Serial.print("\n\n");
  delay(500);
}

 

Serial Monitor Output

Switch: 1
X-axis: 231
Y-axis: 0

Switch: 1
X-axis: 547
Y-axis: 704

Switch: 1
X-axis: 797
Y-axis: 1023

Switch: 0
X-axis: 267
Y-axis: 0

Switch: 0
X-axis: 174
Y-axis: 57

Switch: 1
X-axis: 113
Y-axis: 0

Links

github repo link

 

 

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More