Embedded System - Arduino





Joystick (Thum Joystick)


In terms of electrical point of view, Joy stick is a kind of sensor which senses the position of a stick in horizontal and vertical axis. So if you have a good understandings on what's described in Sensor Basics page, it will be much easier to understand what I am talking about this page.


The Joystick may be manufactured as a digital sensor or analog sensor, but the one used in this tutorial is the one functioning as an analog sensor.  This module does not require any specific drivers or header file. That is, you can read the position of the stick purely using the basic Arduino function.


The module and connection to Arduino for this tutorial is shown below. It does not require any external circuit(e.g, external resistors). Just direct cable connection would be OK.



What to buy ?


You may find a lot of Joystick modules from various different sources. The module that I've used is the one from following source (I purchased it at a local electronic shop). Even though you would get it from other company, I think the pin discription and functionality would be almost same.





Pin Descrition of the JoyStick


The pin description of this module is shown below. As you see, it requires one VCC (5V) and a ground, and two Analog inputs and one digital input pin.






Running the program (listed below) and play with the stick, you would get the result as shown below. In this program, used Serial Monitor tool to show the position of the stick. In your application, you only need to translate the position of the stick to whatever you want to do. For example, you can translate the position value to the direction of Motor or brightness of LED etc.




The source codethat I have used is as follows and I don't think I need to put any detailed explained for this since each of these commands are very basic Arduino functionality. If you need any further details, I would suggest you to refer to Serial Communication page and Sensor Basics page.


int Horizontal_X_Pin = A1;

int Vertical_Y_Pin = A0;

int Button_Pin = 2;


int Horizontal_X_Position = 0;

int Vertical_Y_Position = 0;

int Button_Pin_State = 0;


void setup() {




  pinMode(Horizontal_X_Pin, INPUT);

  pinMode(Vertical_Y_Pin, INPUT);


  pinMode(Button_Pin, INPUT);

  digitalWrite(Button_Pin, HIGH);




void loop() {


  Horizontal_X_Position = analogRead(Horizontal_X_Pin);

  Vertical_Y_Position = analogRead(Vertical_Y_Pin);

  Button_Pin_State = digitalRead(Button_Pin);


  Serial.print("Horizontal_X: ");


  Serial.print(" | Vertical_Y: ");


  Serial.print(" | Button_State: ");