Project
Reading Joystick Values with KY-023 on Raspberry Pi Pico
Overview
Learn how to read X-axis, Y-axis, and button values from a KY-023 analog joystick using a Raspberry Pi Pico. This project is useful for robot control, menu navigation, and simple game controllers.
Instructions
Step by step
1. Connect the joystick VCC pin to 3.3V.
2. Connect the joystick GND pin to GND.
3. Connect the VRX pin to GP26.
4. Connect the VRY pin to GP27.
5. Connect the SW pin to GP16.
6. Run the code and open the Serial/console output.
7. Move the joystick sliders in the simulator to change X and Y values.
8. Click the joystick button to change the SW value.
Code
Source code
from machine import ADC, Pin
import utime
vrx = ADC(Pin(26))
vry = ADC(Pin(27))
sw = Pin(16, Pin.IN, Pin.PULL_UP)
while True:
x_value = vrx.read_u16()
y_value = vry.read_u16()
button_value = sw.value()
print("X:", x_value, "Y:", y_value, "Button:", button_value)
utime.sleep(0.5)
Related