HELLO THERE!!!
How are you guys? I hope everyone is fine and in a good mood always. Sorry for the late this week guys as i am a bit busy with my work. So, this week, I would like to share with you guys a simple experiment on arduino and joystick module, In this experiment, our objective is to read the analog and digital values from the joystick. Without wasting any time, let's jump into it.
HARDWARE:
1.Arduino UNO
How are you guys? I hope everyone is fine and in a good mood always. Sorry for the late this week guys as i am a bit busy with my work. So, this week, I would like to share with you guys a simple experiment on arduino and joystick module, In this experiment, our objective is to read the analog and digital values from the joystick. Without wasting any time, let's jump into it.
HARDWARE:
1.Arduino UNO
2.Joystick Module
SOFTWARE:
1. Arduino IDE
CIRCUIT ASSEMBLY
There are 5 pins on the joystick module. The pins are GND,5V,VRx(x movement),VRy(y movement), and SW(button). The connections of these pins to the Arduino is depicted as below:
Joystick Module ---------------> Arduino
GND GND
5V 5V
VRx A0 (or any analog pin)
VRy A1 (or any analog pin)
SW Digital Pin 2 (or any digital pin)
The Schematic of Circuit |
CODING THE ARDUINO
The code is shown as below:
int vx = A0; //connect VRx to analog pin 0
int vy = A1; //connect VRy to analog pin 1
int but = 2; //Connect SW to digital pin 2
int valx;
int valy;
int vbut;// initialize variables
void setup() {
pinMode(but, INPUT);//set the SW pin(button) as input
digitalWrite(but, HIGH);//set initial high
Serial.begin(9600);//baud rate is set at 9600 bos
}
void loop() {
valx = analogRead(vx);//read VRx,VRy and button value
valy = analogRead(vy);
vbut = digitalRead(but);
Serial.print(valx);
Serial.print(",");
Serial.print(valy);
Serial.print(",");
Serial.print(vbut);
Serial.println(" ");//print those values
delay(1000);//delay for a second
}
Upload the code to the Arduino and see the results!!. Move your joystick around and observe the values of VRx and VRy changing. Also test the button of the joystick by clicking it. I had screen captured the result as shown below:
Results obtained |
Well,that's all from me, guys. I hope I can make it this week with another post in which I am planning to use the Arduino Joystick module to replace mouse function. Till then, HAPPY TINKERING!!!
Comments
Post a Comment