Category:PCB Arduino

Group Administrators: 1 | Group Member: 81 | Group Threads: 86

Arduino is an open-source electronics platform based on easy-to-use hardware and software. It's intended for anyone making interactive projects. About Arduino and Arduino Projects sharing are appreciated.

Thread Reply
Use Arduino Joystick Shield Reply 2017-02-08 04:40:19
744 views
1 comments
141 likes

Broderick

Leave A Message

Follow

In this tutorial we are going to see how to use Arduino Joystick Shield. There are different versions but we'll be using v2.4, which has some interesting features and some extra buttons which can be used in your application in different ways.
The Arduino Joystick Shield v2.4 provides seven momentary pushbutton switches (six separate pushbuttons and and a pushbutton under the joystick) and a thumb joystick with two potentiometers. This shield gives your Arduino the functionality found on the old Nintendo controllers. The joystick can be used for controlling outputs such as a melody or pixels on a screen. The buttons can be used for navigation or game control.
Note: The standard Arduino board will not support a joystick shield with a Nokia 5110 LCD. This is because the standard Arduino 3.3 V supply is only capable of supply 50 mA, and the Nokia 5110 backlight requires more current.
Experiment 1: Read joystick values
The joystick has two potentiometers, which you connect to analog pins A0 and A1 on your Arduino. The value of A0 corresponds to the X position. The value of A1 corresponds to the Y position. To read these analog values, use the AnalogRead() function.
Hardware
1 x Arduino Uno
1 x Arduino Joystick Shield v2.4
Steps:
  1. Attach your joy stick shield to the Arduino board.
  2. Connect your arduino board to your PC.
  3. The LED will light on your joystick shield, showing that it’s working properly.
  4. Write the sketch and compile it before uploading to your board; it's good practice to compile your sketch before uploading.
  5. After the sketch is uploaded, run the serial monitor to observe the values.
  6. Move joystick in different directions and you will notice that the values on serial monitor will change.
You can move the joystick in 8 directions: up, right-up, right, right-down, down, down-left, left, left-up. If the values change on your serial monitor, your shield is working properly.
This code will display something like this if the shield is connected to 5 V.
Experiment 2: Using the joystick to control motion
To control motion along the X-axis, you first have to read the postion of the X-axis potentiometer and determine if the user is pressing the the control to the right or the left, or not pressing it at all. When not being pressed either right or left, the value of A0 will typically be 523. In order to account for some variation in that reading between different shield units, we'll set a tolerance of 30. That means that when we read a value of between 493 and 553, we will assume that the user is not pressing the joystick. A reading of less than 493 will mean that the user is pressing the joystick to the left and wants the object being controlled to move left. A reading of greater than 553 means that the user is pressing the joystick to the right and wants the object being controlled to move right.
This code will display something like this:
Steps
  1. Attach your joy stick shield over arduino board.
  2. Connect your arduino board to your PC.
  3. Led will turn on, on your joystick shield showing that it’s working properly.
  4. Write the sketch and compile it before uploading to your board, it is just a good practice to compile your sketch before uploading.
  5. After the sketch is uploaded run serial monitor to observe the values.
  6. As you move joystick, serial monitor will tell you the direction in which you move your joystick.
The code below that will display the direction that the user is pressing the joystick instead of displaying analog values.
Experiment 3: Read joystick pushbutton switches
The pushbutton switches are simply connected to Arduino digital I/O pins as shown in the table below:
When Key A is pressed a digital signal will be sent to D2 and so on. We will use the digitalRead() function to determine the state of the buttons.
Since there are no resistors connected to these buttons on joystick shield you have to enable pull up resistors on your Arduino. Below is the code to enable the pullup resistors and read the digital values.
Whenever a user presses a pushbutton, the Arduino will display the button value on the serial monitor.
Steps
  1. Attach your joystick shield over arduino board.
  2. Connect your arduino board to your PC.
  3. Led will light on your joystick shield showing that it’s working properly.
  4. Write the sketch and compile it before uploading to your board (it's good practice to compile your sketch before uploading).
  5. After the sketch is uploaded, run serial monitor to observe the values.
  6. Press any button on your joystick and it will display which button is pressed.
141 likes
Statement: This post is only the personal view of the author and does not represent the opinions of ALLPCB.com.

leonard.roussel

Leave A Message

Follow

Good resource for new beginners.
ThreadReply