Tutorial – Joypad module with Arduino

Tutorial –  Joypad module with Arduino

Hi! Today we will learn how to use a joypad module with Arduino!

In this Tutorial you will learn how to make a circuit for a Joypad with Arduino and then we wil make a simple sketch!

You have to learn how to use this module because we want to make our own controller for RC models!

So let’s getting started and learn how to use a joypad module with Arduino

What is a Joypad

A joypad is a module that is used a lot by gamers…of course you know it!

It can be moved on the X, Y axes or a combination of them.

You can also press it, we will use this feature to make a nice controller!

Nowadays is an essential module for all controllers and moreover is very easy to use it!

So let’s make a schematic for it!

Schematic

Follow this schematic, it’s easy, even if there are 5 wirings to do…maybe there will be a jungle of cable but if you make a soldered circuit maybe this won’t be a problem anymore.

Joypad module with Arduino
  • VrX and VrY are for X and Y axis
  • SW is for the press button function. That means that you can press the pad.
  • GND -> Arduino GND
  • 5V -> Arduino 5V

Sketch

A pretty simple sketch. It just print the value, but learning this you can do a lot of things!

So let’s explain it:

We define 3 objects that will be respectively: pin for X axis, pin for Y axis, pin for the press button pad.

#define Xaxis A0
#define Yaxis A1
#define buttonPad 2

Then we have to set the buttonPad pin as an INPUT pin.

void setup()
{
  Serial.begin(9600);
  pinMode(buttonPad, INPUT);
}

In the loop, first of all we define x, y and button variables with the proper value from a analogRead(for the axis) and digitalRead(for the button).

  int x = analogRead(Xaxis);
  int y = analogRead(Yaxis);
  int button = !digitalRead(buttonPad);

Then we just print the results:

  Serial.print("Value:");
  Serial.print("x: " + String(x));
  Serial.print(",\tY:" + String(y));
  Serial.println(",\tB: " + String(button));

Complete Sketch

#define Xaxis A0
#define Yaxis A1
#define buttonPad 2

void setup()
{
  Serial.begin(9600);
  pinMode(buttonPad, INPUT);
}

void loop()
{
  int x = analogRead(Xaxis);
  int y = analogRead(Yaxis);
  int button = !digitalRead(buttonPad);

  Serial.print("Value:");
  Serial.print("x: " + String(x));
  Serial.print(",\tY:" + String(y));
  Serial.println(",\tB: " + String(button));

  delay(100);
}

Davide Busco

Davide Busco is an engineering student at Federico II University of Naples. He uses his passion and studies to create his projects. He loves be a maker and spread his knowledge. Moreover he has gained the second place in a national makers-tournament between Italian's Universities.

Leave a Reply

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

en_GBEnglish (UK)
it_ITItaliano en_GBEnglish (UK)
%d bloggers like this: