5 Direction Joystick Button Module with Arduino

1,129 views

Introduction

The 5-direction joystick button module is a versatile input device that can be used in a variety of projects ranging from robotics to gaming. The module is easy to use and can be interfaced with popular microcontrollers such as Arduino.

In this article, we will explore how to interface the “5 Direction Joystick Button Module” with the Arduino and control various devices using its analog and digital output signals.

What is Joystick Button Module?

The 5-direction joystick button module is an input device that consists of a joystick and five push buttons. The joystick can move in four directions (up, down, left, right) and has a central click function. The five push buttons are located on the top surface of the module and are labeled A, B, C, D, and E.

5-Direction-Joystick-Button-Module
5-Direction-Joystick-Button-Module

Hardware Components

To interface 5 Direction Joystick Button Module with Arduino, you’ll need the following hardware components to get started:

ComponentsValueQty
Arduino UNO1
USB Cable Type A to B1
DC Power for Arduino1
Joystick Button Module1
Jumper Wires1

Joystick Button Module Pinout

5-Direction-Joystick-Button-Module-Pinout
5-Direction-Joystick-Button-Module-Pinout
Pin NamePin Description
COMCommon pin
UPUp
DWNDown
LFTLeft
RHTRight
MIDMiddle
SETSet Pin
RESReset Pin

5 Direction Joystick Button Module Circuit

Make connections according to the circuit diagram given below.

Wiring / Connections

ArduinoJoystick Button Module
GNDGND
D8UP
D7DWN
D6LFT
D5RHT
D4MID
D3SET
D2RST

Installing Arduino IDE

First, you need to install Arduino IDE Software from its official website Arduino. Here is a simple step-by-step guide on “How to install Arduino IDE“.

Code

Now copy the following code and upload it to Arduino IDE Software.

const int buttonPin_RST = 2;     // the number of the reset button pin
const int buttonPin_SET = 3;     // the number of the set button pin
const int buttonPin_MID = 4;     // the number of the middle button pin
const int buttonPin_RHT = 5;     // the number of the right button pin
const int buttonPin_LFT = 6;     // the number of the left button pin
const int buttonPin_DWN = 7;     // the number of the down button pin
const int buttonPin_UP = 8;      // the number of the up button pin


void setup() {
  Serial.begin(9600);
  
  pinMode(buttonPin_RST, INPUT_PULLUP);
  pinMode(buttonPin_SET, INPUT_PULLUP);
  pinMode(buttonPin_MID, INPUT_PULLUP);
  pinMode(buttonPin_RHT, INPUT_PULLUP);
  pinMode(buttonPin_LFT, INPUT_PULLUP);
  pinMode(buttonPin_DWN, INPUT_PULLUP);
  pinMode(buttonPin_UP, INPUT_PULLUP);
}

void loop() {
  if(digitalRead(buttonPin_RST) == LOW) {
    delay(250);
    Serial.println("Reset Pin Is Pressed.");
    while(digitalRead(buttonPin_RST) == LOW);
  }
  
  if(digitalRead(buttonPin_SET) == LOW) {
    delay(250);
    Serial.println("Set Pin Is Pressed.");
    while(digitalRead(buttonPin_SET) == LOW);
  }
  
  if(digitalRead(buttonPin_MID) == LOW) {
    delay(250);
    Serial.println("Middle Pin Is Pressed.");
    while(digitalRead(buttonPin_MID) == LOW);
  }
  
  if(digitalRead(buttonPin_RHT) == LOW) {
    delay(250);
    Serial.println("Right Pin Is Pressed.");
    while(digitalRead(buttonPin_RHT) == LOW);
  }
  
  if(digitalRead(buttonPin_LFT) == LOW) {
    delay(250);
    Serial.println("Left Pin Is Pressed.");
    while(digitalRead(buttonPin_LFT) == LOW);
  }
  
  if(digitalRead(buttonPin_DWN) == LOW) {
    delay(250);
    Serial.println("Down Pin Is Pressed.");
    while(digitalRead(buttonPin_DWN) == LOW);
  }
  
  if(digitalRead(buttonPin_UP) == LOW) {
    delay(250);
    Serial.println("Up Pin Is Pressed.");
    while(digitalRead(buttonPin_UP) == LOW);
  }
}
 

Code Explanation

This Arduino code defines the pins connected to the 5-direction joystick button module’s buttons (up, down, left, right, middle) as well as the reset and sets buttons. In the setup function, all the pins are initialized as INPUT_PULLUP, which means that they will read a HIGH signal when the buttons are not pressed, and a LOW signal when the buttons are pressed.

In the loop function, the code checks if each button is pressed using digitalRead(). If a button is pressed, the code prints a message to the serial monitor indicating which button is pressed. It also includes a delay(250) to debounce the button and a while loop to wait until the button is released before checking again.

This code can be used as a starting point to control different devices based on which button is pressed on the 5-direction joystick button module. By modifying the code inside each if statement, different actions can be taken based on the input from the buttons.

Applications

Here are some applications where the 5-Direction Joystick Button Module can be used:

  • Gaming controllers for PCs or gaming consoles
  • Robotics applications to control the movement of robotic arms or robots
  • Industrial machinery controls different functions such as movement, speed, or direction
  • Smart homes and home automation systems to control lights, appliances, and other devices
  • Virtual reality applications control the movement and interactions in a virtual environment
  • Musical instruments such as synthesizers or MIDI controllers control different parameters like pitch, volume, or effects
  • Drones control the flight direction and altitude
  • Accessibility devices for people with disabilities to control different functions such as wheelchair movement or communication devices
  • Educational projects to teach programming and electronics by using the module as an input interface.

Conclusion

Interfacing the 5-direction joystick button module with Arduino is a great way to add an intuitive and precise input interface to your projects. Whether you are building a robot or a gaming controller, this module can provide you with a range of input signals that can be easily processed by Arduino.