• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here: Home » Connecting Arduino With M029 JoyStick : Getting Started

By Abhishek Ghosh November 9, 2017 7:46 am Updated on November 9, 2017

Connecting Arduino With M029 JoyStick : Getting Started

Advertisement

Obviously these are Made in China and costs around $2. Here is a getting started guide around connecting Arduino with M029 JoyStick and testing with basic code. It is a useful thing for robotics. These analog, has 2 axis, PS2 compatible. Exactly like Nokia’s old Symbian mobile phones, we can use this joystick to control a menu, centre click to select or control servo motors. But before doing advanced projects, we need to test with basic code and circuit.

 

Connecting Arduino With M029 JoyStick : Getting Started

 

These joysticks are nothing but 2 potentiometer and one push button. There are 5 connections to the joystick. Two are for electrical connections – one to +5V of Arduino and another to GND. Other three pins are for Key, Y and X.
The key is digital, Y and X are analog. For basic testing, frankly you do not need the Key – the digital one. The names are variables depending on China company manufactured it. Usually the name of the pins are :

Vim
1
2
3
4
5
GND
+5V
VRx
VRy
SW

The VRx and VRy are analog and will connect to Arduino’s A0, A1 pin. Obviously, GND and +5V will connect to respective same named connection. Rest is SW, which we said as Key, that is digital and for our this guide we connected to Pin 2. This is the circuit diagram :

Advertisement

---

Connecting Arduino With M029 JoyStick - Getting Started

You can upload this code :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
int ledPin = 13;
int UD = 0;
int LR = 0;
 
void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}
 
void loop() {
  UD = analogRead(A0);
  LR = analogRead(A1);
  //Map the values
  char x_translate = map(LR, 1021, 0, 7, 0);
  char y_translate = map(UD, 1021, 0, 0, 7);
  //Serial.print("UD = ");
  //Serial.print(UD, DEC);
  //Serial.print(", LR = ");
  //Serial.print(LR, DEC);
  Serial.print("  x = ");
  Serial.print(x_translate, DEC);
  Serial.print("  y = ");
  Serial.println(y_translate, DEC);  
  delay(150); //this to delay correctly
  digitalWrite(ledPin, HIGH);          
  delay(UD);
  digitalWrite(ledPin, LOW);
  delay(LR);
}

and open the Serial Monitor on Arduino IDE/Software on computer. You’ll get this kind of reading :

Vim
1
2
3
4
5
6
7
...
x = 4, Y = 3
x = 4, Y = 3
x = 4, Y = 3
x = 4, Y = 3
x = 4, Y = 3
...

If you move the joystick, you’ll understand that values of X and Y are changing.

There are few lines which are commented out :

Vim
1
2
3
4
  //Serial.print("UD = ");
  //Serial.print(UD, DEC);
  //Serial.print(", LR = ");
  //Serial.print(LR, DEC);

If you make all the lines active, you’ll get raw value too. More easy code I ever found is this :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const int SW_pin = 2;
const int X_pin = 0;
const int Y_pin = 1;
 
void setup() {
  pinMode(SW_pin, INPUT);
  digitalWrite(SW_pin, HIGH);
  Serial.begin(9600);
}
 
void loop() {
  Serial.print("Switch:  ");
  Serial.print(digitalRead(SW_pin));
  Serial.print("n");
  Serial.print("X-axis: ");
  Serial.print(analogRead(X_pin));
  Serial.print("n");
  Serial.print("Y-axis: ");
  Serial.println(analogRead(Y_pin));
  Serial.print("nn");
  delay(500);
}

There is a JoyStick module with stick, I saw them to use this code which somewhat works as the hardware is same :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const byte PIN_ANALOG_X = 0;
const byte PIN_ANALOG_Y = 1;
 
const int X_THRESHOLD_LOW = 300;
const int X_THRESHOLD_HIGH = 380;    
 
const int Y_THRESHOLD_LOW = 300;
const int Y_THRESHOLD_HIGH = 380;    
 
int x_position;
int y_position;
 
int x_direction;
int y_direction;
 
void setup() {
  Serial.begin(9600);
}
 
void loop () {
  x_direction = 0;
  y_direction = 0;
 
  x_position = analogRead(PIN_ANALOG_X);
  y_position = analogRead(PIN_ANALOG_Y);
 
  if (x_position > X_THRESHOLD_HIGH) {
    x_direction = 1;
  } else if (x_position < X_THRESHOLD_LOW) {
    x_direction = -1;
  }
 
  if (y_position > Y_THRESHOLD_HIGH) {
    y_direction = 1;
  } else if (y_position < Y_THRESHOLD_LOW) {
    y_direction = -1;
  }
 
  if (x_direction == -1) {
      if (y_direction == -1) {
        Serial.println("left-down");
      } else if (y_direction == 0) {
        Serial.println("left");
      } else {
        // y_direction == 1
        Serial.println("left-up");
      }
  } else if (x_direction == 0) {
      if (y_direction == -1) {
        Serial.println("down");
      } else if (y_direction == 0) {
        Serial.println("centered");
      } else {
        // y_direction == 1
        Serial.println("up");
      }
  } else {
      // x_direction == 1
      if (y_direction == -1) {
        Serial.println("right-down");
      } else if (y_direction == 0) {
        Serial.println("right");
      } else {
        // y_direction == 1
        Serial.println("right-up");
      }
  }
}

Everything needs some adjustment of values.

Probably you want to move a dot on 8×8 LED Dot Matrix Display With MAX7219 with the joystick.

You can try this kind of logic, I found it on Github :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
int UD = 0;
int LR = 0; //Setting up controller//
 
#include "LedControl.h" //  need the library
LedControl lc=LedControl(8,10,9,1); //10 is to CLOCK, 9 = CS, 8=DIN//
 
 
void setup() {
  Serial.begin(9600);
 
  lc.shutdown(0,false);// turn off power saving, enables display
  lc.setIntensity(0,8);// sets brightness (0~15 possible values)
  lc.clearDisplay(0);// clear screen
 
}
 
void loop() {
  UD = analogRead(A0);
  LR = analogRead(A1);
  char x_translate = map(LR, 1021, 0, 7, 0); //This maps the values//
  char y_translate = map(UD, 1021, 0, 0, 7);
  
  Serial.print("UD = ");
  Serial.print(UD, DEC);
  Serial.print(", LR = ");
  Serial.print(LR, DEC);
  Serial.print(", x = ");
  Serial.print(x_translate, DEC);
  Serial.print(", y = ");
  Serial.println(y_translate, DEC);
    // not in shutdown mode
    lc.clearDisplay(0);
    lc.setLed(0,x_translate,y_translate,true);  
  delay(150); //Mess with this delay to get your joystick correct//
}

Tagged With stick analogico arduino

This Article Has Been Shared 555 Times!

Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Connecting Arduino With M029 JoyStick : Getting Started

  • Methods and Components To Build Electronic Circuits

    We Have Discussed Some Details On Methods and Components To Build Electronic Circuits Which Are Needed To Create Ammeter Electronic Projects.

  • Arduino Temperature Humidity Sensor : New DHT11, DHT21, DHT22 Test Code

    Here is New Test Codes For Arduino Temperature Humidity Sensor DHT11, DHT21, DHT22 Test Code as Hardware (Not Shields). 2 Libraries Needed.

  • How to Increase the Number of Digital Pins in Arduino (Port Extender)

    13+6 Pins Often a Limitation of Arduino in Projects Where We Need Many Pins. Here is How to Increase the Number of Digital Pins in Arduino.

  • Arduino Fingerprint Scanner Module GT-511C3, GT-511C1R

    Here is Arduino Fingerprint Scanner Module GT-511C3 or GT-511C1R Buying Guide and Basic Details On Unknown Matters Around Fingerprint Scanner.

  • Arduino UNO Prototype Shield Tutorial

    In Arduino UNO Prototype Shield Tutorial We Have Talked How We Can Use to Convert a Project Semi-Permanent With Shield, Components & Solder.

Additionally, performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • How to Do Electrical Layout Plan for Adding Smart Switches January 26, 2023
  • What is a Data Mesh? January 25, 2023
  • What is Vehicular Ad-Hoc Network? January 24, 2023
  • Difference Between Panel Light, COB Light, Track Light January 21, 2023
  • What is COB LED? How LED Chip On Board Works January 20, 2023

About This Article

Cite this article as: Abhishek Ghosh, "Connecting Arduino With M029 JoyStick : Getting Started," in The Customize Windows, November 9, 2017, January 27, 2023, https://thecustomizewindows.com/2017/11/connecting-arduino-with-m029-joystick-getting-started/.

Source:The Customize Windows, JiMA.in

PC users can consult Corrine Chorney for Security.

Want to know more about us? Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT