Introduction: Interfacing Thumb Joystick to Arduino

About: My team has developed a new product. PLEASE CHECK IT OUT ON INDIEGOGO AND SHOW YOUR SUPPORT. CAMPAIGN LINK: https://igg.me/p/2165733/x/17027489. I'm a tech and food enthusiast and also a Soccer Player. I love…

When you hear the word Thumb Joystick or Analog Stick, the first thing that comes to the mind are the game controllers. They are mainly used for playing games, although, in DIY Electronics, there are a lot more fum things to do with the Thumb Joystick.Controlling a robot or a rover, controlling the movement of camera, these are just the tip of the iceberg.

Grove-Thumb Joystick is a Grove Shield compatible module that can be interfaced easily with the Arduino Board and can be used to develop many cool projects. In this Instructable, I will show you how to interface the Thumb Joystick to the Arduino and map the values.

Step 1: About the Grove Base Shield

The Grove shield is basically an adapter to the Arduino which plugs into the latter and maps each and every I/O pins of the Arduino to specific ports on the shield designed for a specific function. If you examine closely, the shield will have dedicated ports for I2C(Controlling Motors), Analog Ports and Digital Ports. This is very helpful for beginners who are learning Arduino. In a nutshell, it makes it easy for the user to plug in the sensors on to the Arduino and start using them right away.

If you have a Grove Kit, you will notice that they come with all the sensors specifically designed for the Base Shield. But you can use other sensors also with the shield. In the same way, you can use the grove modules directly with Arduino or any micro-controller.

Step 2: The Thumb Joystick

This Joystick is similar to the ones you find on a PS4 Controller. The X and Y axes are two ~10k potentiometers which control 2D movement by generating analog signals. The joystick also has a push button that could be used for special applications.

The analog values can be read according to its X and Y axes. Based on the values of the X and Y axes, we shall map it onto which direction it is being pointed in. Usually the output values are in a smaller range i.e. 200-800.

Step 3: Components Required

To learn this Interfacing, you will need:

  • Arduino Uno.
  • Grove Base Shield.
  • Grove Thumb Joystick.
  • Connecting Wire.

That's all you need, so let's get started.

Step 4: The Connections

  1. Plug in the Grove Base Shield into the Arduino.
  2. Now connect the Thumb Joystick to the connector cable.
  3. Plug in the other end of the cable into any analog port of the Base Shield.
  4. Power up the Arduino and you will see a green light turn on on the Base Shield.
  5. That's it, write your code and see what all that can do.

Note: If you are using the Joystick without the Base Shield, then connect individual pins to the Arduino by referring the back side of the Joystick.

Step 5: The Code

I have written the code which maps the analog values automatically and displays whether the Joystick is pointing left or right or any direction.

To get the threshold values, upload the commented part of the code and note down the change in values when pointed different directions.

<p>void setup() {<br>  Serial.begin(9600);
}
 
void loop() {
  int sensorValue1 = analogRead(A0);
  int sensorValue2 = analogRead(A1);
//  Serial.print("The X and Y coordinates are:");
//  Serial.print(sensorValue1, DEC);
//  Serial.print(",");
//  Serial.println(sensorValue2, DEC);
//  Serial.println(" ");
if (sensorValue2 > 500 ){
  Serial.print("Up\n");
  }
  else if(sensorValue2 < 200){
   Serial.print("Down\n"); 
    }
   else if(sensorValue1 < 200){
    Serial.print("Left\n");
    }
   else if(sensorValue1 > 500){
    Serial.print("Right\n");
    }
  delay(500);
}</p>

Step 6: Output

Now after uploading the code, you can see the directions being pointed by the Joystick in the Serial Monitor.

I will use this code to control different stuff in future projects.

That's All Folks !! Stay Tuned for More !!

"There is a way to make it better - find it . ~ Thomas Edison."

Makerspace Contest 2017

Participated in the
Makerspace Contest 2017