Raspberry Pi Pico ProjectsRaspberry Pi Projects

Joystick With Raspberry Pi Pico MicroPython Tutorial

Joystick With Raspberry Pi Pico is a great way to control your next project. You can use the joystick to control anything from a simple LED to a complex robotic arm. The joystick is easy to use and can be interfaced with various electronics. This essay will explore how to interface a Raspberry Pi Pico with a Joystick.

We’ll also look at some example projects that you can use to get started with your own Raspberry Pi Pico and Joystick project.

Required Components

  1. Raspberry Pi Pico (Amazon.com)
  2. Joystick Module (Amazon.com)
  3. LEDs (Amazon.com)
  4. Jumper wire (Amazon.com)

What is a Raspberry pi pico board?

Getting Started With Raspberry Pi Pico With Thonny IDE

Raspberry Pi Pico is a new microcontroller board from Raspberry Pi. It’s their smallest and most affordable board yet, at only $4. It’s also their most powerful microcontroller board, with a Cortex-M0+ processor and support for high-speed GPIO, PWM, and ADC.

It is designed for use in a wide range of applications, from simple electronics projects to complex system-on-chip designs.

Analog Joystick Module


A joystick is an input device that consists of a stick that can be tilted in multiple directions to control an on-screen pointer. A joystick module is used to control a computer or video game character by moving a lever in different directions. It is also used to control other devices such as cameras and robots. Joystick modules come in different sizes and shapes. The module can be used to measure the tilt of a joystick on the X and Y axes.

There are two main types of joysticks:

  • Analog – Analog joysticks use potentiometers to measure the position of the stick
  • Digital Digital joysticks use switches to determine the direction the stick is moved.

Joystick module pinout

This joystick module has five pins which are numbered from left to right for reference:

arduino joystick

  1. GND: Pin connected to ground.
  2. +5V: power pin(5v).
  3. VRx: potentiometer reading pin for the x’s axis.
  4. VRy: potentiometer reading pin for the y’s axis.
  5. SW: is an additional pin used for a push button at the bottom.

Connections Joystick With Raspberry Pi Pico

Joystick With Raspberry Pi Pico

Raspberry pi pico Joystick
5V ➡️ +5V
GP27 (PIN 32) ➡️ VRx
GP25 (PIN 31) ➡️ VRy
GP17 (PIN 22) ➡️ SW

Programming – Joystick With Raspberry Pi Pico

Copy all the code and then go to thonny create a new file and paste the below code.

MicroPython Sketch: Reading analog input from Joystick Module

Open Serial Monitor and see the value

Programming - Joystick With Raspberry Pi Pico

Example 2. Schematic Diagram for Controlling LEDs using Joystick with Raspberry Pi pico

Joystick With Raspberry Pi Pico MicroPython Tutorial example 2

  • xAxis = ADC(Pin(27))
  • yAxis = ADC(Pin(26))
  • button = Pin(17,Pin.IN, Pin.PULL_UP)
  • led_left = Pin(14, Pin.OUT)
  • led_middle = Pin(15, Pin.OUT)
  • led_right = Pin(12, Pin.OUT)
  • led_up = Pin(18, Pin.OUT)
  • led_down = Pin(13, Pin.OUT)

Code 2 – Controlling LEDs using Joystick with Raspberry Pi pico

Controlling LEDs using Joystick with Raspberry Pi pico

1_raspberry pi with Joystick

After uploading the code to the Raspberry pi pico and connecting components according to the circuit diagram, you can now control the LEDs with Joystick.

You can turn ON the four LEDs in each direction according to the Joystick shaft movement. The Joystick is having two potentiometers inside it, one is for X-axis movement and another is for Y-axis movement. Each potentiometer is getting 5v from the Raspberry Pi pico.

By moving the joystick, you can see the voltage value will change and the analog value at Analog pins will also change. From the Pico, you can read the analog value for the X and Y axis and turn the LEDs ON according to the axis movement of the Joystick.

A push button switch on the Joystick module is used to control the single LED in the circuit as shown in the video below.

Move the joystick in different directions and you will be able to view the LED

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button

Adblock Detected

Please consider supporting us by disabling your ad blocker