![How to use Thumb Joystick with Arduino](https://blog.techshopbd.com/wp-content/uploads/2023/11/How-to-use-Thumb-Joystick-with-Arduino.jpg)
![How to use Thumb Joystick with Arduino](https://blog.techshopbd.com/wp-content/uploads/2023/11/How-to-use-Thumb-Joystick-with-Arduino.jpg)
আরডুইনো ও জয়স্টিক দিয়ে তৈরি করুন গেমিং কন্ট্রোলার
আজকে একটা মজার প্রজেক্ট করব। আজকের প্রজেক্টটিও আরডুইনো ভিত্তিক। ডিসপ্লে হিসেবে থাকছে একটি LCD display। আরডুইনোর সাথে আরও যুক্ত থাকবে একটি Thumb Joystick। এলসিডিতে একটি মানুষের প্রতিকৃতি দেখা যাবে। Thumb Joystick এর মাধ্যমে আমরা মানুষটির দুটি হাত উপরে তুলতে , দুইহাত নিচে নামাতে , ডান হাত উপরে তুলতে এবং বাম হাত উপরে তুলতে পারব।
এই প্রজেক্ট থেকে আমরা শিখবঃ
- কিভাবে Thumb Joystick কে আরডুইনোর সাথে যুক্ত করা যায়।
- কিভাবে LCD display তে Custom Character তৈরী করা এবং দেখানো যায়।
- এই দুটি ব্যপার জানা থাকলে এলসিডি এবং Thumb Joystick দিয়ে বিভিন্ন গেম এবং অন্যান্য প্রজেক্ট আমরা তৈরী করতে পারব।
প্রয়োজনীয় যন্ত্রপাতি | পরিমাণ | লিংক |
Arduino UNO R3/Arduino Mega 2560 | 1 | link |
16×2 LCD with header | 1 | link |
Thumb Joystick | 1 | link |
Male to male jumpers | 17 | link |
Male to female jumpers | 4 | link |
Variable POT 103 | 1 | link |
Breadboard (830 points) | 1 | link |
সার্কিট কানেকশনঃ
![Connection between Arduino and LCD](https://blog.techshopbd.com/wp-content/uploads/2023/11/Connection-between-Arduino-and-LCD-720x398.jpg)
![Connection between Arduino and LCD](https://blog.techshopbd.com/wp-content/uploads/2023/11/Connection-between-Arduino-and-LCD-720x398.jpg)
![Connection of Arduino and Thumb joystick](https://blog.techshopbd.com/wp-content/uploads/2023/11/Connection-of-Arduino-and-Thumb-joystick-720x424.jpg)
![Connection of Arduino and Thumb joystick](https://blog.techshopbd.com/wp-content/uploads/2023/11/Connection-of-Arduino-and-Thumb-joystick-720x424.jpg)
কানেকশন চার্টঃ
Arduino Mega | LCD |
GND | VSS,K,1st pin of variable POT |
5V | VDD,A,2nd pin of variable POT |
V0, 3rd pin of variable POT | |
GND | RW |
12 | RS |
11 | E |
5,4,3,2 | D4,D5,D6,D7 |
Arduino | Thumb joystick with module |
5v | 5v |
GND | GND |
A0 | VRx |
A1 | VRy |
![Actual circuit setup](https://blog.techshopbd.com/wp-content/uploads/2023/11/Actual-circuit-setup-720x540.jpg)
![Actual circuit setup](https://blog.techshopbd.com/wp-content/uploads/2023/11/Actual-circuit-setup-720x540.jpg)
Thumb Joystick কি এবং কিভাবে কাজ করে?
গেমিং কনসোলগুলোতে আমরা Thumb Joystick অহরহ দেখতে পাই। জয়স্টিক হচ্ছে একধরণের মোমেন্টারি সুইচ। সুইচটি পাঁচটি ভিন্নভিন্ন দিকে যেতে পারে। এই পাঁচটি দিক হল- Left, Right, Up, Down ,Middle। জয়স্টিকের নব ছেড়ে দেওয়া অবস্থায় এটি Middle পজিশনে থাকে। নবটিকে বৃদ্ধা আঙ্গুল দিয়ে ডানে, বামে,উপরে এবং নিচে জয়স্টিককে ঘোরানো যায়। এভাবে ঘোরানোর ফলে X এবং Y- অক্ষ বরাবর জয়স্টিকের অবস্থান পরিবর্তিত হয়। অবস্থান পরিবর্তনের সাথে সাথে VRx এবং VRY পিনের ভোল্টেজ পরিবর্তিত হয়। এই ভোল্টেজ দুটির মান সবসময় ০ থেকে ৫ ভোল্টের মধ্যে।আমরা জানি, Arduino UNO কিংবা Mega এর ADC এর Resolution হল 10-bit। এই ভোল্টেজের অ্যানালগ ভ্যালু 0 থেকে 1023 পর্যন্ত হয়।
জয়স্টিক যখন Middle পজিশনে থাকে, তখন এই দুই পিনের ভোল্টেজের মান থাকে ২.৫ ভোল্ট বা তার কাছাকাছি। অর্থ্যাৎ, X এবং Y-দুই অক্ষেরই অ্যানালগ ভ্যালু থাকে 512 বা তার আশেপাশে।
Left পজিশনে X=0,Y=512 (or Approx.)
Right পজিশনে X=1023(or Approx.),Y=512 (or Approx.)
UP পজিশনে X=512 (or Approx.),Y= 0
Down পজিশনে X=512 (or Approx.),Y=1023(or Approx.)
নিচের চিত্রের মাধ্যমে জয়স্টিকের বিভিন্ন পজিশনে ভোল্টেজের অ্যানালগ ভ্যালুর মানগুলো দেখানো হয়েছে।
![Voltage variation of two axes of Thumb joystick at different positions](https://blog.techshopbd.com/wp-content/uploads/2023/11/Voltage-variation-of-two-axes-of-Thumb-joystick-at-different-positions-720x584.jpg)
![Voltage variation of two axes of Thumb joystick at different positions](https://blog.techshopbd.com/wp-content/uploads/2023/11/Voltage-variation-of-two-axes-of-Thumb-joystick-at-different-positions-720x584.jpg)
সুতরাং, আমরা যদি VRX এবং VRY পিনদুটিকে আরডুইনোর দুটি অ্যানালগ পিনের সাথে কানেক্ট করি, তাহলে analogRead() ফাংশনের মাধ্যমে পিনদুটির ভ্যালু রিড করতে পারব। এই রিডিংগুলো দেখেই আমরা বুঝতে পারব, জয়স্টিককে কোন দিকে মুভ করানো হয়েছে।
প্রোগ্রামঃ
আমাদের প্রোগ্রামে এলসিডির কাস্টম ক্যারেক্টার তৈরী করতে আমরা ব্যবহার করেছি LCD custom character generator ।
![LCD custom character generator](https://blog.techshopbd.com/wp-content/uploads/2023/11/LCD-custom-character-generator-720x414.jpg)
![LCD custom character generator](https://blog.techshopbd.com/wp-content/uploads/2023/11/LCD-custom-character-generator-720x414.jpg)
নিচের প্রোগ্রামটি আরডুইনো আইডিইতে লিখুন এবং আরডুইনোতে আপলোড করুন।
#include <LiquidCrystal.h> // initialize the library by associating any needed LCD interface pin // with the arduino pin number it is connected to const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; LiquidCrystal lcd(rs, en, d4, d5, d6, d7); // These constants won't change. They're used to give names to the pins used: const int analogInPinx = A0; // Analog input pin that the potentiometer is attached to const int analogInPiny = A1; // Analog output pin that the LED is attached to int sensorValuex = 0; // value read from the pot int sensorValuey = 0; // value output to the PWM (analog out) int x; byte armsstraight[8] = { B00100, B01010, B00100, B11111, B00100, B00100, B00100, B01010 }; byte armsDown[8] = { 0b00100, 0b01010, 0b00100, 0b00100, 0b01110, 0b10101, 0b00100, 0b01010 }; byte armsUp[8] = { 0b00100, 0b01010, 0b00100, 0b10101, 0b01110, 0b00100, 0b00100, 0b01010 }; byte armleft[8] = { B00100, B01010, B00100, B01111, B01100, B01100, B00100, B01010 }; byte armright[8] = { B00100, B01010, B00100, B11110, B00110, B00110, B00100, B01010 }; void setup() { // initialize serial communications at 9600 bps: Serial.begin(9600); // initialize LCD and set up the number of columns and rows: lcd.begin(16, 2); lcd.createChar(1, armleft); lcd.createChar(2, armsstraight); lcd.createChar(3, armsDown); // create a new character lcd.createChar(4, armsUp); lcd.createChar(5, armright); } void loop() { // read the analog in value: sensorValuex = analogRead(analogInPinx); sensorValuey = analogRead(analogInPiny); // print the results to the Serial Monitor: Serial.print("x = "); Serial.print(sensorValuex); Serial.print("\t y = "); Serial.println(sensorValuey); // wait 2 milliseconds before the next loop for the analog-to-digital // converter to settle after the last reading: delay(2); if(sensorValuex==0) { lcd.clear(); lcd.setCursor(0, 0); lcd.print("My left arm!"); lcd.setCursor(7, 1); lcd.write(1); } else if(sensorValuex>=1020) { lcd.clear(); lcd.setCursor(0, 0); lcd.print("My right arm!"); lcd.setCursor(7, 1); lcd.write(5); } else if(sensorValuey==0) { lcd.clear(); lcd.setCursor(0, 0); lcd.print("Arms Up!"); lcd.setCursor(7, 1); // draw him arms up: lcd.write(4); } else if(sensorValuey>=1020) { lcd.clear(); lcd.setCursor(0, 0); lcd.print("Arms down!"); lcd.setCursor(7, 1); // draw the little man, arms down: lcd.write(3); } else { lcd.clear(); lcd.setCursor(0, 0); lcd.print("Move my arms!"); lcd.setCursor(7, 1); // draw the little man, arms straight: lcd.write(2); } }
পরীক্ষাঃ
Thumb Joystick কে বিভিন্ন দিকে ঘুরিয়ে আরডুইনোর সিরিয়াল মনিটরে X এবং Y-অক্ষের ভোল্টেজের পরিবর্তন দেখুন এবং এলসিডির মানুষটির দুই বাহুর নড়াচড়া লক্ষ্য করুন।
![Thumb Joystick is in normal mode](https://blog.techshopbd.com/wp-content/uploads/2023/11/Thumb-Joystick-is-in-normal-mode-720x540.jpg)
![Thumb Joystick is in normal mode](https://blog.techshopbd.com/wp-content/uploads/2023/11/Thumb-Joystick-is-in-normal-mode-720x540.jpg)
![Serial monitor data when Thumb Joystick knob is in normal position (Middle)](https://blog.techshopbd.com/wp-content/uploads/2023/11/Serial-monitor-data-when-Thumb-Joystick-knob-is-in-normal-position-Middle-720x316.jpg)
![Serial monitor data when Thumb Joystick knob is in normal position (Middle)](https://blog.techshopbd.com/wp-content/uploads/2023/11/Serial-monitor-data-when-Thumb-Joystick-knob-is-in-normal-position-Middle-720x316.jpg)
![The man on the LCD is standing with both arms spread out](https://blog.techshopbd.com/wp-content/uploads/2023/11/The-man-on-the-LCD-is-standing-with-both-arms-spread-out-720x540.jpg)
![The man on the LCD is standing with both arms spread out](https://blog.techshopbd.com/wp-content/uploads/2023/11/The-man-on-the-LCD-is-standing-with-both-arms-spread-out-720x540.jpg)
![The Thumb Joystick knob is on the left](https://blog.techshopbd.com/wp-content/uploads/2023/11/The-Thumb-Joystick-knob-is-on-the-left-720x540.jpg)
![The Thumb Joystick knob is on the left](https://blog.techshopbd.com/wp-content/uploads/2023/11/The-Thumb-Joystick-knob-is-on-the-left-720x540.jpg)
![Serial monitor data when Thumb Joystick knob is left](https://blog.techshopbd.com/wp-content/uploads/2023/11/Serial-monitor-data-when-Thumb-Joystick-knob-is-left-720x317.jpg)
![Serial monitor data when Thumb Joystick knob is left](https://blog.techshopbd.com/wp-content/uploads/2023/11/Serial-monitor-data-when-Thumb-Joystick-knob-is-left-720x317.jpg)
![The man on the LCD is showing his left hand](https://blog.techshopbd.com/wp-content/uploads/2023/11/The-man-on-the-LCD-is-showing-his-left-hand-720x540.jpg)
![The man on the LCD is showing his left hand](https://blog.techshopbd.com/wp-content/uploads/2023/11/The-man-on-the-LCD-is-showing-his-left-hand-720x540.jpg)
![The Thumb Joystick knob is on the right](https://blog.techshopbd.com/wp-content/uploads/2023/11/The-Thumb-Joystick-knob-is-on-the-right-720x540.jpg)
![The Thumb Joystick knob is on the right](https://blog.techshopbd.com/wp-content/uploads/2023/11/The-Thumb-Joystick-knob-is-on-the-right-720x540.jpg)
![Serial monitor data when the Thumb Joystick knob is on the right](https://blog.techshopbd.com/wp-content/uploads/2023/11/Serial-monitor-data-when-the-Thumb-Joystick-knob-is-on-the-right-720x314.jpg)
![Serial monitor data when the Thumb Joystick knob is on the right](https://blog.techshopbd.com/wp-content/uploads/2023/11/Serial-monitor-data-when-the-Thumb-Joystick-knob-is-on-the-right-720x314.jpg)
![The man on the LCD is showing his right hand](https://blog.techshopbd.com/wp-content/uploads/2023/11/The-man-on-the-LCD-is-showing-his-right-hand-720x540.jpg)
![The man on the LCD is showing his right hand](https://blog.techshopbd.com/wp-content/uploads/2023/11/The-man-on-the-LCD-is-showing-his-right-hand-720x540.jpg)
![Thumb Joystick knob upwards](https://blog.techshopbd.com/wp-content/uploads/2023/11/Thumb-Joystick-knob-upwards-720x540.jpg)
![Thumb Joystick knob upwards](https://blog.techshopbd.com/wp-content/uploads/2023/11/Thumb-Joystick-knob-upwards-720x540.jpg)
![Serial monitor data when Thumb Joystick knob is up](https://blog.techshopbd.com/wp-content/uploads/2023/11/Serial-monitor-data-when-Thumb-Joystick-knob-is-up-720x316.jpg)
![Serial monitor data when Thumb Joystick knob is up](https://blog.techshopbd.com/wp-content/uploads/2023/11/Serial-monitor-data-when-Thumb-Joystick-knob-is-up-720x316.jpg)
![The LCD man raised his hands](https://blog.techshopbd.com/wp-content/uploads/2023/11/The-LCD-man-raised-his-hands-720x540.jpg)
![The LCD man raised his hands](https://blog.techshopbd.com/wp-content/uploads/2023/11/The-LCD-man-raised-his-hands-720x540.jpg)
![Thumb Joystick knob is down](https://blog.techshopbd.com/wp-content/uploads/2023/11/Thumb-Joystick-knob-is-down-720x540.jpg)
![Thumb Joystick knob is down](https://blog.techshopbd.com/wp-content/uploads/2023/11/Thumb-Joystick-knob-is-down-720x540.jpg)
![Serial monitor data when Thumb Joystick knob is down](https://blog.techshopbd.com/wp-content/uploads/2023/11/Serial-monitor-data-when-Thumb-Joystick-knob-is-down-720x314.jpg)
![Serial monitor data when Thumb Joystick knob is down](https://blog.techshopbd.com/wp-content/uploads/2023/11/Serial-monitor-data-when-Thumb-Joystick-knob-is-down-720x314.jpg)
![The LCD man lowered his hands](https://blog.techshopbd.com/wp-content/uploads/2023/11/The-LCD-man-lowered-his-hands-720x540.jpg)
![The LCD man lowered his hands](https://blog.techshopbd.com/wp-content/uploads/2023/11/The-LCD-man-lowered-his-hands-720x540.jpg)
এভাবে খুব সহজে আরডুইনোর সাথে জয়স্টিক ব্যবহার করতে পারবেন। এই টিউটোরিয়াল থেকে ধারণা নিয়ে চাইলে গেমিং কন্ট্রোলার তৈরি করতে পারবেন বা রোবটিক্স বিভিন্ন প্রজেক্টে ব্যবহার করতে পারেন। আরডুইনো ভিত্তিক আরও টিউটোরিয়াল পড়তে এই লিংক ভিজিট করুন। আজ এখানেই শেষ করছি, ধন্যবাদ এতক্ষন এতক্ষণ ধৈর্যসহকারে টিউটোরিয়ালটি পড়ার জন্য।