Joystick is basically a gaming controller. They are used for playing games. It is an input device. It is also called Control stick. In Electronics, you can do a lot of fun with it. Like controlling a robot, a car, controlling the movement of camera etc.
Joystick is similar like two potentiometer are connected together 1 for x-axis and the other for y-axis.
Components :
- Arduino Uno
- Jumper wires
- Joystick
Joystick pinout :
- VCC –> 5V
- GND –> GND
- VRx –> A0
- VRy –> A1
- SW –> D2
Circuit Diagram :
Code :
#define joyX A0
#define joyY A1
#define SW 2
double xValue = 0;
double yValue = 0;
void setup() {
Serial.begin(9600);
pinMode(SW, INPUT_PULLUP);
}
void loop() {
xValue = analogRead(joyX);
yValue = analogRead(joyY);
// xValue = map(xValue, 0, 1023, 0, 10000);
// yValue = map(yValue, 0, 1023, 0, 10000);
Serial.print ("xValue");
Serial.print (xValue,0);
Serial.print ("\t");
Serial.print ("yValue");
Serial.println (yValue,0);
if(digitalRead(SW) == LOW)
Serial.print("\n\n Button pressed \n\n");
}
Good day! I just want to offer you a big thumbs up for your excellent information you have got here on this post. Ill be coming back to your blog for more soon.