Industrial manufacturing
Industrial Internet of Things | Industrial materials | Equipment Maintenance and Repair | Industrial programming |
home  MfgRobots >> Industrial manufacturing >  >> Manufacturing Technology >> Industrial Technology

Build an Arduino Joystick Module: A Step-by-Step Guide

  Build an Arduino Joystick Module: A Step-by-Step Guide

Joystick Module

Are you currently handling projects related to motion and robotics? Then, there’s a chance that you’ve probably heard about the Arduino Joystick module, but you don’t know how to make one. 

Or perhaps you want to get more information about how an Arduino joystick module works?

Then, you’re in the right place.

The goal of an Arduino Joystick is to communicate motion to an Arduino. And it does this in 2-D (2-axis), making it suitable for motion and robotics applications.

So, in this article, you’ll learn everything about the Arduino joystick module, how it works, and how to make an easy Arduino joystick circuit.

Are you ready? Let’s jump in!

What is a Joystick Module?

There’s hardly any robotic project that doesn’t require a joystick. It’s sometimes difficult to get a controller that would work for your projects, and it might even be expensive. But, a joystick module provides a more affordable way to achieve that same result.

Also, the joystick module works similarly to the joysticks found in analog gamepads. Its key components are two potentiometers tilted at 90-degree angles. Furthermore, there’s a connection between a short stick (with springs at the center) and the potentiometers.

Build an Arduino Joystick Module: A Step-by-Step Guide

Potentiometers

The joystick module can output around 2.5V from the X and Y axis when it’s resting. Now, when you move the Joystick, the output will vary from 0V to 5V. However, this depends on the direction. 

Plus, if you use a microcontroller with the joystick module, the real value in the resting position would be around 512. Thus, when you move this Joystick, you can see the values change from 0 to 1023, but this depends on its position.

Pin Configuration

Here is the pin configuration for the joystick module:

Pin No.Pin NameDescription
1GNDThe module’s ground terminal
2+5VThe module’s positive supply terminal
3VRxThe voltage proportional to the X-axis
4VRyThe voltage proportional to the Y-axis
5SWThe switch of the module

Features

Here are the key features of the Arduino joystick module:

Technical Specifications

The specifications of the joystick module include:

Schematic Diagram

The image below shows the complete schematics of the joystick module. As we previously mentioned, the module features two potentiometers that control the X and Y-axis.

Build an Arduino Joystick Module: A Step-by-Step Guide

Schematics for Joystick Module

Plus, both potentiometers (10k) move independently. In other words, you can move them individually and in their directions. Also, there’s an internal connection of the switch (SW) pin to the push button.

Interfacing Joystick with Arduino 

Joystick modules are compatible with many microcontrollers like Raspberry Pi, Arduino, and others. Plus, it’s easy to interface, and you first have to connect the VRx and VRy axis pins to the microcontroller’s ADC pins. 

Also, if you plan on using a switch, then you should connect the button to the microcontroller’s digital pins. 

Check out the diagram below to understand how to connect the joystick module to any microcontroller.

Build an Arduino Joystick Module: A Step-by-Step Guide

Joystick Module to Microcontroller

Now, the following diagram will show you how to interface a joystick module with an Arduino. With this diagram, you’ll be able to connect the module to the Arduino. Also, you’ll get an output depending on the direction you move the joystick knob.

Build an Arduino Joystick Module: A Step-by-Step Guide

Joystick Module to Arduino

Once you’re done interfacing, we’ll find that each direction has a fixed output range. The following image will show you the output for the X and Y-axis depending on the movement of the joystick module in the four directions, +X, -X, +Y, and –Y. There’ll also be some analog values when you diagonally move the knob.

Build an Arduino Joystick Module: A Step-by-Step Guide

Movement Directions

If you want to know when you press your Joystick knob down, you can also connect the SW pin to digital pin 8 of the Arduino.

Additionally, the Joystick requires power to work correctly. So, connect the VCC pin to the Arduino’s 5V terminal and the GND to the Arduino’s GND terminal.

Arduino Code

It’s pretty easy to code this program on Arduino IDE. So, to get the best results, you’ll be measuring the motion of the Joystick from one digital input pin and two analog inputs. Then, the Arduino will display the impact on your monitor. 

Here’s the best part

You don’t need a library to code this program. It simply reads the analog input and displays the values it gets from it. Plus, it also shows the output from the button push.

Here’s the raw sketch of the code:

  1. #define joyX A0
  2. #define joyY A1
  3.  
  4. void setup() {
  5.   Serial.begin(9600);
  6. }
  7.  
  8. void loop() {
  9.   // put your main code here, to run repeatedly:
  10.   xValue = analogRead(joyX);
  11.   yValue = analogRead(joyY);
  12.  
  13.   //print the values with to plot or view
  14.   Serial.print(xValue);
  15.   Serial.print(”\t”);
  16.   Serial.println(yValue);

Build an Arduino Joystick Module: A Step-by-Step Guide

Image showing the Arduino code

Mapping

Sometimes, it’s not all about reading analog values, and there might be a need to map your module to a display or other interfaces. So, to help you with that, we’ll show you how to map the values of the above code to an 8×8 led matrix. 

Build an Arduino Joystick Module: A Step-by-Step Guide

Arduino Mapping

The result of this process is to move the pixels on display with the Joystick. Also, it’s easy to change the code to map it to an OLED or graphic display.

  1. #include “LedControl.h”
  2. #define joyX A0
  3. #define joyY A1
  4.  
  5. int xMap, yMap, xValue, yValue;
  6. LedControl lc=LedControl(12,11,10,1);
  7.  
  8. void setup() {
  9.   Serial.begin(115200);
  10.  
  11.   lc.shutdown(0,false);
  12.   /* Set the brightness to a medium values */
  13.   lc.setIntensity(0,8);
  14.   /* and clear the display */
  15.   lc.clearDisplay(0);
  16. }
  17.  
  18. void loop() {
  19.   // put your main code here, to run repeatedly:
  20.   xValue = analogRead(joyX);
  21.   yValue = analogRead(joyY);
  22.   xMap = map(xValue, 0,1023, 0, 7);
  23.   yMap = map(yValue,0,1023,7,0);
  24.   lc.setLed(0,xMap,yMap,true);
  25.   lc.clearDisplay(0);
  26.  
  27. }
Build an Arduino Joystick Module: A Step-by-Step Guide

Image of code required to map the Arduino to an OLED or graphic display

Note: the above code shows that you can use the map() function to map the ranges to fit your preferences.

So, if you get everything right, the output on your serial monitor should look like this:

Applications

Here are some applications of the Arduino Joystick module:

Build an Arduino Joystick Module: A Step-by-Step Guide

Robot Drone

Build an Arduino Joystick Module: A Step-by-Step Guide

Movable Camera

Rounding Up

When you hear the word Joystick, the first thing that might come to mind would be game controllers. However, there are so many exciting applications of the joystick module when it comes to DIY electronics.

Build an Arduino Joystick Module: A Step-by-Step Guide

Game Controllers

Plus, these modules primarily work for DIY projects based On Arduino and robot control. As we earlier discussed, the joystick module first released analog output to feed the analog input depending on the horizontal or vertical movement of the stick.

Well, that rounds up this article. If you have any questions or suggestions, feel free to contact us. We’re always happy to help.


Industrial Technology

  1. Create a Custom Punchable Keyboard Button with Arduino: A Step-by-Step Guide
  2. Build a Custom Arduino Joystick Steering Wheel for Gaming
  3. Create Musical Tones with Arduino: A Step‑by‑Step Guide
  4. DIY Guide: Build Your Own DC Motor Controller
  5. Build an Arduino Proximity Sensor: Step‑by‑Step Guide with Components
  6. Build a Reliable DIY RFID Reader: Step-by-Step Guide
  7. Tachometer Circuit Explained: Function, Design, and Build Guide
  8. Build Your Own LED Driver: Benefits, Safety Tips, and Step‑by‑Step Guide
  9. Digital TV Antennas Demystified: Types, Easy Installation, and DIY Construction
  10. Build a Simple Arduino Speaker – Step‑by‑Step Guide