INTERFACING JOYSTICK WITH ARDUINO UNO
A joystick is commonly known as a control column. It is an input device consisting of a stick that acts as the central point on which the mechanism turns and gives the output its angle or direction to the device it is controlling. It also acts as a principal control device in many aircraft, either as a central stick or side-stick. In this tutorial you will get to know the interfacing joystick with Arduino Uno.
Joysticks are used to control video games and also used for controlling machines such as cranes, trucks, etc. Interfacing joystick with arduino uno is one of the important part of any such high level project.
MAIN FEATURES OF JOYSTICK INTERFACE
- It has a four-channel controller.
- It requires a minimum amount of external RC components.
- It uses a quad slope ADC multiplier.
- It also has a software-controllable integration cycle and automatic hardware terminations
- It has simple read access and also has a single external interrupt.
- It contains five pins-Ground, 5V, VRx, VRy, SW.
- Operating Voltage:5V
- It has an internal Potentiometer value: 10k.
- Its operating temperature:0 to 70 degrees C.
- It also has two potentiometers independent of each, one for the direction of the x-axis and one for the y-axis.
- Low weight and auto return to the centre position.
WORKING OF JOYSTICK
The working of the joystick is nothing but it consists of 2 potentiometers which help in measuring the movement of the stick in 2-D. Potentiometers act as variable resistors and also in providing variable voltage, speed, etc depending on the rotation of the device. This principle is based on the conversion of physical movement into a digital signal and this starts working when it is connected to the computer or the device.
CONNECTING THE JOYSTICK WITH ARDUINO
The Joystick connection to the ARDUINO is discussed in the following steps:
As we discussed above, there are 5pins on the Joystick sensor.
- Firstly VCC pin on the joystick module is to be connected to the 5V pin on the ARDUINO board.
- Next, connect the GND (ground) pin on the joystick module with the GND on the ARDUINO.
- Now connect the VRx (Variable resistance X) pin on the joystick module to the A0 pin on the ARDUINO board.
- Similarly, now connect VRy (Variable resistance Y) pin on the joystick module to the A1 pin on the ARDUINO board.
- Finally the SW (switch) on the Joystick module to pin 2 on the ARDUINO board.
- This connection from the joystick module to the ARDUINO board is done by using male and female wires.
- Now the power supply is given to the ARDUINO for the functioning of the Joystick sensor.
Finally, the interfacing of Joystick Sensor with ARDUINO is completed and the last step is dumping the code into the ARDUINO board for the functioning of the Joystick sensor and to get the required output.
When the power is supplied the functioning of the sensor starts but it is programmed accordingly to expect a result from it as per our convenience.
ARDUINO PROGRAM OF JOYSTICK SENSOR
int VRx = A0;
int VRy = A1;
int SW = 2;
int xPosition = 0;
int yPosition = 0;
int SW_state = 0;
int mapX = 0;
int mapY = 0;
void setup() {
Serial.begin(9600);
pinMode(VRx, INPUT);
pinMode(VRy, INPUT);
pinMode(SW, INPUT_PULLUP);
}void loop() {
xPosition = analogRead(VRx);
yPosition = analogRead(VRy);
SW_state = digitalRead(SW);
mapX = map(xPosition, 0, 1023, -512, 512);
mapY = map(yPosition, 0, 1023, -512, 512);
Serial.print("X: ");
Serial.print(mapX);
Serial.print(" | Y: ");
Serial.print(mapY);
Serial.print(" | Button: ");
Serial.println(SW_state);
delay(100);
}
FUNCTIONING OF JOYSTICK SENSOR
The functioning of the sensor starts after the successful dumping of code into the ARDUINO development board. The final output values will be visible on the Serial Monitor. When the joystick is in the resting position or middle, it should return a value of about 512. The range of values is from 0 to 1023. So as per the movement of the sensor the output will be displayed on the Serial Monitor.
APPLICATIONS:
- These sensors are used in Camera Pan/Tilt control.
- They are also used in-game Input/control.
- The sensors are mainly used in Robot control.
- They are used widely in DIY projects.
CONCLUSION
The above-discussed information is all about the interfacing of the Joystick sensor with ARDUINO and its functioning and the output result of the Joystick sensor.
This information can be very much helpful in understanding a brief about the joystick sensor with interface with ARDUINO board and very much helpful in dealing with Robotic projects and others by using the Joystick Sensor
Read related articles:
Interfacing ultrasonic sensor with arduino
Touch sensor interfacing with arduino
arduino.cc tutorials