Simple Way to Integrate 4- Axis Joystick With Arduino

by samiobi in Circuits > Remote Control

4090 Views, 2 Favorites, 0 Comments

Simple Way to Integrate 4- Axis Joystick With Arduino

WhatsApp Image 2021-09-03 at 11.36.45 AM.jpeg

The joysticks are one of the remote control tools preferable to so many users, due to its simplicity and maneuverability. For this reason many applications still use joysticks in their products such as in airplane cockpit surveillance camera, Play station and so on. When a system designer thinks to design a simple system controller the first tool comes to his mind is the joystick. Based on this, it is important to know how to integrate joysticks with other systems.

Joystick comes into different types but technically they can be either analogy or digital format, each one have different usage depends on the application. In this project analogy type joystick will be used , this joystick selected is the 4 axis analogy joystick.

Supplies

Arduino Uno

4 axis analogy joystick

links

bread board

Concept of Operation

The 4- axis joystick has two outputs each one act as a potentiometer (variable resistor ), each one has three pins one for VCC one for ground and one for variable value. The analogy joystick produces variable voltage value correspond to the movement of the joystick, the joystick increases and decreases the voltage level while the user pushes the lever till the end of the lever. The joystick has a resistance of 10K ohm in total, when the lever is in the middle position the resistance is 5K ohm if the user shift the lever for example upwards the 5K increase till it reaches 10K ohm but if the user push the lever downwards the 5K ohm decreases till it reaches 0 ohm. However the input value to the Arduino is a voltage level which correspondence to the resistance difference due to the movement. Based on this the designer can map the value of the variable to the mechanical movement which enables the system to change direction and change the speed accordingly .

Block Diagram

block digram.png

The block diagram shown in the figure explains the interconnection between the joystick and Arduino Uno, as in the diagram the output of the joystick (middle pins) are connected to A0 and A1 of the Arduino. likewise the VCC and GRD are connected from the Arduino to the joystick. The final result is shown in the serial monitor of the Arduino.

Hardware Connections

WhatsApp Image 2021-09-03 at 11.36.45 AM.jpeg
WhatsApp Image 2021-09-03 at 11.36.45 AM (1).jpeg
WhatsApp Image 2021-09-03 at 11.36.46 AM.jpeg
WhatsApp Image 2021-09-03 at 11.36.48 AM.jpeg

The hardware connection shown in the figure begins with soldering the three pins of the joystick as in the figure two and three. Then both VCC in both sides (red color) are connected together to 5V of the Arduino, similarly the negative terminals (black color) are both connected to the ground of the Arduino. The outputs of both sides are the meddle pins and connected to analogy pins of the Arduino A0 and A1. The final connection is shown in the last photo.

Coding

The software coding of this project is simple, the output is presented in the serial monitor the values are corresponds to the movement of the lever in the joystick as will be explained in the last section. The inputs to the Arduino are A0 and A1 both are analogy inputs. The variable values then converted to digital value corresponds to the voltage level. The up down level is presented as (sensor -1) and left right is presented as (sensor-2).

Just copy the code and past it in IDE software and modify it as you wish but the code is ready for this project.

The code:

const int analogInPin = A0; // input up down

const int analogInPin1 = A1; // input left right

int sensorValue = 0; // up and down value

int sensorValue1 = 0; // left and right value

void setup() {

Serial.begin(9600); // enable serial monitor

}

void loop() {

sensorValue = analogRead(analogInPin); // read pin A0

sensorValue1 = analogRead(analogInPin1); // read pin A1

// print the results to the Serial Monitor:

Serial.print("sensor1 = "); // present in serial monitor up and down value

Serial.println(sensorValue);

Serial.print("sensor2 = "); // present in serial monitor left and right value

Serial.println(sensorValue1);

delay(500); } // delay in milliseconds

Final Result

ideal statuts.jpeg
sensor 1 up.jpeg
sensor 1 down.jpeg
sensor 2 right.jpeg
sensor 2 left.jpeg

The result shown in the figures above display the value of output from each variable i.e. sensor 1 and sensor 2 which represents the analogy read from both inputs. First is the ideal position of the joystick lever in the middle location notice in the first figure the reading of sensor -1 is 518 and sensor- 2 is 439 but in ideal situation both values should be 500 but these diversion is due to the use of VCC out from the Arduino and hence the Arduino is powered by my laptop some difference in the value output are expected. Second stage is to move the lever upwards this will cause the value of sensor 1 to increase till it reaches 1023 notice that the output matches the lever position for instance the half way up will give 800 and full way up will give value of 1023. Third is to move the lever downward this will cause sensor -1 to reduce the value from 518 till it reaches 0. Fourth to move the lever to the right notice now sensor-2 start changes its value from 439 to 800 till it reaches 1023. Likewise in the last movement of the lever to the left position the value of sensor -2 decreases from 439 to 0.

in conclusion the project shows the idea of integrating 4 axis joystick with the Arduino from the value presented by each movement the system can be linked with stepper motor , DC motors or any other mechanical system . Hope you have enjoyed this project and if you have any enquiry please do not hesitate to comment, please share your experience.

All the best