How the five-way navigation button module works with the Arduino

How the five-way navigation button module works with the Arduino

Hello, welcome back. In this tutorial, we will learn what is the five-way navigation button module and how it works with Arduino. Also, this module includes five buttons on one navigation button. That is, UP, DOWN, LEFT, RIGHT and MIDDLE. These act as push buttons. Also, these buttons can be controlled one by one. Therefore, you can use this module primarily to build remote controllers and gaming consoles. Click this link to learn more info about the other joystick module.

How the five-way navigation button module works with the Arduino

PIN structure of this joystick module

How the five-way navigation button module works with the Arduino

We also need to use either “Pull up” or “Pull down” to get input from the buttons in this module. For this, we need five pins on the Arduino board. But today we will do it using one of the analog pins on the Arduino board.

OK, let’s learn how to connect this joystick module with Arduino step by step. The required components are given below.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Step 1

Firstly, identify these components.

Arduino Nano board

How the five-way navigation button module works with the Arduino

Joystick module

How the five-way navigation button module works with the Arduino

10k Resistors

How the five-way navigation button module works with the Arduino

180-ohm Resistors

How the five-way navigation button module works with the Arduino

LEDs

How the five-way navigation button module works with the Arduino

Breadboard

How the five-way navigation button module works with the Arduino

Jumper wires

How the five-way navigation button module works with the Arduino

Step 2

Secondly, connect these components. To do this, use the circuit diagram below.

How the five-way navigation button module works with the Arduino

Step 3

Thirdly, let’s create the program for this project. It is as follows.

  • The complete program of this project – Download
/* Five-way navigation button module
   
Home Page
*/ #define Joystick A1 #define LED1 2 #define LED2 3 #define LED3 4 #define LED4 5 #define LED5 6 #define Umax 1023 #define Umin 900 #define Dmax 514 #define Dmin 490 #define Lmax 342 #define Lmin 330 #define Rmax 356 #define Rmin 240 #define Mmax 205 #define Mmin 180 void setup() { Serial.begin(9600); pinMode(LED1, OUTPUT); digitalWrite(LED1, HIGH); pinMode(LED2, OUTPUT); digitalWrite(LED2, HIGH); pinMode(LED3, OUTPUT); digitalWrite(LED3, HIGH); pinMode(LED4, OUTPUT); digitalWrite(LED4, HIGH); pinMode(LED5, OUTPUT); digitalWrite(LED5, HIGH); } void loop() { int value = analogRead(Joystick); Serial.println(value); if (value < Dmax && value > Dmin) { digitalWrite(LED1, LOW); } else if (value < Umax && value > Umin) { digitalWrite(LED2, LOW); } else if (value < Lmax && value > Lmin) { digitalWrite(LED3, LOW); } else if (value < Rmax && value > Rmin) { digitalWrite(LED4, LOW); } else if (value < Mmax && value > Mmin) { digitalWrite(LED5, LOW); } else { digitalWrite(LED1, HIGH); digitalWrite(LED2, HIGH); digitalWrite(LED3, HIGH); digitalWrite(LED4, HIGH); digitalWrite(LED5, HIGH); } }

Code explanation

Firstly, the joystick module pin and LED pins are defined.

#define Joystick A1
#define LED1 2
#define LED2 3
#define LED3 4
#define LED4 5
#define LED5 6

Secondly, let’s include the button’s analog values. For that, select board and port. Afterward, upload this code to the Arduino board.

How the five-way navigation button module works with the Arduino
How the five-way navigation button module works with the Arduino
How the five-way navigation button module works with the Arduino
How the five-way navigation button module works with the Arduino

Now, run the serial monitor. Then, click on the buttons one by one to get the analog values and enter those values into the program at maximum and minimum. If you do not understand this, the full guide in the video below.

  • UP button — 1023/900
  • Down button — 514/490
  • Left button — 342/330
  • Right button — 256/240
  • Middle button — 205/180
How the five-way navigation button module works with the Arduino

In the setup function, the LED pins are set as output pins. Also, all LEDs are turned off.

void setup() {
Serial.begin(9600);
pinMode(LED1, OUTPUT); digitalWrite(LED1, HIGH);
pinMode(LED2, OUTPUT); digitalWrite(LED2, HIGH);
pinMode(LED3, OUTPUT); digitalWrite(LED3, HIGH);
pinMode(LED4, OUTPUT); digitalWrite(LED4, HIGH);
pinMode(LED5, OUTPUT); digitalWrite(LED5, HIGH);
}

In the loop function, get the button analog values and include them in the integer variable. Then, these values are checked using the IF condition and the LED bulbs are turned ON and OFF according to the relevant values.

void loop() {
int value = analogRead(Joystick);
Serial.println(value);

if (value < Dmax && value > Dmin) {
digitalWrite(LED1, LOW);
} else if (value < Umax && value > Umin) {
digitalWrite(LED2, LOW);
} else if (value < Lmax && value > Lmin) {
digitalWrite(LED3, LOW);
} else if (value < Rmax && value > Rmin) {
digitalWrite(LED4, LOW);
} else if (value < Mmax && value > Mmin) {
digitalWrite(LED5, LOW);
} else {
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, HIGH);
digitalWrite(LED4, HIGH);
digitalWrite(LED5, HIGH);
}
}

Step 4

Lastly, upload this code back to the Arduino board.

How the five-way navigation button module works with the Arduino

OK, enjoy this project. The full video guide is given below. So, we will meet in the next tutorial. Have a good day.

How the five-way navigation button module works with the Arduino

Similar Posts

Leave a Reply

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