0% found this document useful (0 votes)
19 views

Lesson 12 Analog Joystick Module

This lesson teaches how to use an analog joystick module with an Arduino UNO R3, detailing the required hardware and connections. It explains the joystick's pin configuration and provides sample code for reading joystick movements and button presses. The document also outlines experimental procedures for building the circuit and uploading the code to observe data changes in the Serial Monitor.

Uploaded by

Euronymous
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Lesson 12 Analog Joystick Module

This lesson teaches how to use an analog joystick module with an Arduino UNO R3, detailing the required hardware and connections. It explains the joystick's pin configuration and provides sample code for reading joystick movements and button presses. The document also outlines experimental procedures for building the circuit and uploading the code to observe data changes in the Serial Monitor.

Uploaded by

Euronymous
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Lesson 12 Analog Joystick Module

Introduction

In this lesson, you will learn how to use the analog joystick module to add
some control in your projects.

Hardware Required

 1 * RexQualis UNO R3

 1 * Breadboard

 1 * Joystick module

 5 * F-M Jumper Wire

Principle

Analog Joystick Module

The module has 5 pins: VCC, Ground, X, Y, Key. Note that the labels on yours
may be slightly different, depending on where you got the module from. The
thumb stick is analog and should provide more accurate readings than simple
‘directional’ joysticks tact use some forms of buttons, or mechanical switches.
Additionally, you can press the joystick down (rather hard on mine) to activate
a ‘press to select’ push-button.

We have to use analog Arduino pins to read the data from the X/Y pins, and a
digital pin to read the button. The Key pin is connected to ground, when the
joystick is pressed down, and is floating otherwise. To get stable readings from
the Key /Select pin, it needs to be connected to VCC via a pull-up resistor. The
built in resistors on the Arduino digital pins can be used. For a tutorial on how
to activate the pull-up resistors for Arduino pins, configured as inputs.
We need 5 connections to the joystick.The connections are: Key, Y, X,
Voltage ,and Ground.“Y and X” are Analog and “Key” is Digital. If you don’
t need the switch then you can use only 4 pins.

Code interpretation

//74HC595 pin 9 STCP

const int SW_pin = 3; // input for detecting whether the


jotstick/button is pressed

const int X_pin = A0; // analog pin connected to X output

const int Y_pin = A1; // analog pin connected to Y output

void setup() {

pinMode(SW_pin, INPUT); //setup SW input

digitalWrite(SW_pin, HIGH); //reading button state:1=not


pressed,0=pressed

Serial.begin(9600); //Seput serical connection for


print out to console

} //print out values

void loop() {

Serial.print("Switch: ");

Serial.print(digitalRead(SW_pin));

Serial.print("\n");

Serial.print("X-axis: ");

Serial.print(analogRead(X_pin));
Serial.print("\n");

Serial.print("Y-axis: ");

Serial.println(analogRead(Y_pin));

Serial.print("\n\n");

delay(2000);

Experimental Procedures

Step 1:Build the circuit

We need 5 connections to the joystick.

The connections are: K, Y, X, Voltage and Ground.

“Y and X” are Analog and “K” is Digital. If you only need Any one switch then
you can use only 3 pins.
Schematic Diagram

Step 2: Open the code:Analog_Joystick_Code


Step 3: Attach Arduino UNO R3 board to your computer via
USB cable and check that the 'Board Type' and 'Serial Port' are
set correctly.

Step 4: Upload the code to the RexQualis UNO R3 board.

Step 5: Open the Serial Monitor then you can see the data as
below:

(How to use the Serial Monitor is introduced in details in


Lesson 0 Preface)
Then, Turn the joystick so you can see the data changes on the
monitor.
If it isn’t working, make sure you have assembled the circuit
correctly, verified and uploaded the code to your board. For
how to upload the code and install the library, check Lesson 0
Preface.

You might also like