Arduino Joystick Module Example


Today we will fire the LEDs in a fun way, using the arduino joystick.

 

Joystick Connection

The joystick module has 5 pins for connection.

From these pins, VRx signals on the horizontal axis, VRy signals on the vertical axis, and SW pin allows reading the pin value of the joystick click button. The joystick module generates analog values between 0 and 1023 in the horizontal and vertical axes.

Joystick module to connect arduino;

  • Gnd pin ->Aarduino Gnd pin,
  • Vcc pin -> Arduino 5V pin ,
  • The VRx pin arduino is one of the A0-A5 analog pins,
  • The VRy pin arduino is one of the A0-A5 analog pins,
  • The SW pin must be connected to one of the arduino digital pins.

For example, we will connect pin VRx pin A0, pin VRy pin A1, and pin SW pin pin 2 to the arduino pin.

Arduino Joystick Code

  • We read in this code we printed the Serial screen
  • Joystick position is fixed, the screen output is x position :500.. y position:500..

  • Joystick position is in the right side, the screen output x position:500.. y position:0

  • When the joystick position is in the left side, the screen output x position:500.. y position:1023
  • Joystick position is in the bottom side, the screen output

You install the above codes on the arduino board where you make the joystick connections, you can follow values ranging from 0 to 1023 on the serial monitor screen (Ctrl + Shift + M).

 

Joystick Led Control

Joystick Led Code

Here we will do the operation, according to the joystick coordinates to burn the leds.For example when the joystick is on the right, the right led will light up.

Run Code

 

if you have question do not forget to write from the chat button next to it or from the comment

You may also like...

Leave a Reply

Your email address will not be published.