HUM: JOYSTICK MODULE PS2
You are a beginner with Croduino. Or electronics? A specific module caught your eye, but you do not know how to use it? Do not worry, HUM is here for you! How to Use Module (HUM) is a blog tutorials series by e-radionica where you will find all you need in order to begin working with your favorite module. Tutorials include: technical characteristics, work principle, instructions on how to connect module with Croduino and the basic code. Everything else is left to your imagination.
PS2 joystick is another very simple input module for Croduino. It provides analog readings of X and Y direction, along with the angle and digital reading of the push button. The module is an optimal solution for menu navigation, controlling robots or playing games. This tutorial can also be used with the module you have “taken out” of an old PS2 joystick.
Dimensions: 35 x 35 x 35mm
BASIC WORK PRINCIPLE
The module itself has two potentiometers which move depending on how we move the analog stick on the joystick. One of them is connected to the x axis, and the other to y. Let’s take the x axis as an example: if we move the analog stick completely to the left, the potentiometer will provide readings closer to the ground. If we move it to the right, the reading will be closer to the voltage to which we have connected the module. Of course, readings themselves are analog (we get the value from 0-1023) and it is possible to precisely determine the stick’s position. The push button works on a principle of sending HIGH (1) when it is inactive and LOW (0) when it is active. This means that the push button has a built-in pull-up resistor.
What generates analog values are two potentiometers below the part where joystick’s analog stick is located. Current flows through both of them, and the output voltage will depend on the amount of resistance given by potentiometers. Resistance decreases or increases depending on the position of joystick. By observing both potentiometers, this joystick can determine the exact angle under which it is located.
HOW TO CONNECT THE MODULE TO CRODUINO?
The module has a total of 9 pins, we do not have to use all of them. Each direction, each push button has its own GND and Vcc pins, it is sufficient to connect just one Vcc and one GND to the same ones on the Croduino.
S-X – A0 analog pin of the Croduino
S-Y – A1 analog pin of the Croduino
S-k – digital PIN6 of the Croduino
Vcc – +5V
GND – gnd
/* (c) e-radionica.com 2015 - http://www.e-radionica.com/licenca */
/* [email protected] */
/* This code shows the position of x and y directions, and key activation */
/* PS2 JOYSTICK on the CROduino - HUM tutorial */
x = A0;
//S-X of the module to Croduino's analog pin A0
y = A1;
//S-Y of the module to Croduino's analog pin A1
tipka = 6;
//S-K of the module to Croduino's digital PIN6
//sufficient to connect one Vcc and GND of the module to Croduino
pauza = 0;
// pause in milliseconds between readings
pp, vrijednostX, vrijednostY;
//defining variables as input parameters
//not necessary to define analog input pins of the Croduino as INPUT in pinMode function
// starting serial communication
// reading analog values
// save LOW as HIGH, and vice versa
// printing analog readings in the Serial Monitor
" |Y= "
" |push= "
Products used in this tutorial
No products found