![](https://www.robotique.tech/wp-content/uploads/2021/04/joystick-lcd-single-1.png)
A joystick is a type of controller typically used for video games and other applications that involve navigating or controlling movement in a virtual environment. It typically consists of a stick that can be moved in multiple directions, along with one or more buttons for additional inputs. Joysticks can be used to control movement in a variety of different ways, depending on the specific game or application. Some joysticks also include additional features such as vibration or force feedback to provide a more immersive gaming experience.
Using a joystick with an Arduino microcontroller is a simple process that can be accomplished by connecting the joystick‘s potentiometers (or “pots”) to analog input pins on the Arduino board. The potentiometers on a joystick are typically used to measure the position of the stick in the X and Y axes. By reading the values of these potentiometers, the Arduino can determine the position of the stick and use that information to control various aspects of the application.
To use a joystick with an Arduino, you’ll need to connect the potentiometers to the analog input pins on the Arduino board. The specific pins you’ll use will depend on the type of Arduino board you’re using. The Arduino can then read the values of the potentiometers using the analogRead() function and use them to control aspects of the application.
Additionally, the joystick may have additional buttons that can be connected to digital input pins of the Arduino board. By reading the state of these buttons, you can use them as inputs to control different aspects of the application.
In this tutorial we will see how to display the direction of the joystick controller on an LCD I2C 1602 Display with Arduino:
Arduino UNO
The Arduino UNO is a microcontroller board based on the ATmega328P. It has 14 digital input/output pins, 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header, and a reset button. It is the most popular and widely used board among the Arduino boards.
The Arduino UNO can be programmed using the Arduino programming language, which is based on C++. It uses a simple and intuitive programming environment, making it easy for beginners to get started with microcontroller programming.
The Arduino UNO can be connected to various sensors and actuators to control different devices and perform different tasks. For example, it can be used to control motors, read data from sensors, display information on an LCD screen, and communicate with other devices via serial communication protocols such as I2C and SPI.
The Arduino UNO can also be powered by a USB cable or an external power supply, making it easy to use in a wide range of projects and applications. It’s compatible with a wide range of shields (expansion boards) that adds functionality to the board, such as Ethernet, WiFi, and Bluetooth, and it’s widely supported by a strong and active community, which provides a lot of tutorials, examples and libraries to help users to get the most of the board.
Joystick
A joystick is a type of controller typically used for video games and other applications that involve navigating or controlling movement in a virtual environment. It typically consists of a stick that can be moved in multiple directions, along with one or more buttons for additional inputs. Joysticks can be used to control movement in a variety of different ways, depending on the specific game or application. Some joysticks also include additional features such as vibration or force feedback to provide a more immersive gaming experience.
The joystick is composed of two mechanically coupled potentiometers placed in such a way as to detect the horizontal and vertical components of the joystick. Thus the resistance values of the potentiometers vary independently according to the position of the joystick. There is usually a push button that activates when you press the joystick.
LCD I2C 160A display
An LCD I2C 160A display is a type of liquid crystal display that uses the I2C communication protocol to interface with a microcontroller, such as an Arduino. The “160A” in the name refers to the size of the display, which is typically 160×128 pixels. The LCD I2C 160A display is a monochrome display, which means it can only display text and graphics in one color.
To use an LCD I2C 160A display with an Arduino, you will need to install a library that provides functions to control the display. These libraries usually include functions for initializing the display, setting the contrast, and printing text and graphics on the screen.
To get started with the LCD I2C 160A display, you will need to connect the SDA and SCL pins of the display to the corresponding I2C pins of your Arduino board, as well as connecting the power supply and ground. Once the display is connected, you can use the library functions to control it and display text and graphics on the screen.
connecting wires
Connecting wires are used to connect various components in an electronic circuit. They allow for the transfer of electricity, data, or signals between different devices and components.
When connecting wires to an Arduino or other microcontroller, it is important to pay attention to the correct pinout. The pinout refers to the arrangement of pins on the microcontroller and the corresponding function of each pin. The Arduino pinout can be found in the documentation provided by the manufacturer, or in various resources available online.
To make the assembly we connect:
For joystick :
5V pin to 3.3V pin of Arduino
GND pin to GND pin of Arduino
VRx pin to A0 pin of Arduino
VRy pin to A1 pin of Arduino
SW pin to pin 2 of Arduino
For LCD display:
VCC pin to 5V pin of Arduino
GND pin to GND pin of Arduino
SDA pin to A4 of Arduino
SCL pin to A5 pin of Arduino
This program allows the Arduino board to read the different values of the joystick inputs and display the direction of the joystick on the I2C LCD 1602 display.
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 |
#include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 20, 4); int VRx = A0; int VRy = A1; int SW = 2; int xPosition = 0; int yPosition = 0; int SW_state = 0; int mapX = 0; int mapY = 0; void setup() { lcd.init(); pinMode(VRx, INPUT); pinMode(VRy, INPUT); pinMode(SW, INPUT_PULLUP); } void loop() { lcd.backlight(); lcd.clear(); xPosition = analogRead(VRx); yPosition = analogRead(VRy); SW_state = digitalRead(SW); mapX = map(xPosition, 0, 1023, -512, 512); mapY = map(yPosition, 0, 1023, -512, 512); if ((mapX>=-515)&& (mapX<=-510)&&(mapY>=-175)&& (mapY<=-168)) lcd.print("Forward");//When the user points the joystick controller forward, the word “Forward” is displayed. if ((mapX>=168)&& (mapX<=175)&&(mapY>=-175)&& (mapY<=-168)) lcd.print("Backward");//When the user moves the joystick to the rear, the word “Backward” is displayed. if ((mapX<=-166)&& (mapX>=-175)&&(mapY>=-515)&& (mapY<=-510)) lcd.print("Right");//When the user points the joystick to the right, the word “Right” is displayed if ((mapX>=-175)&& (mapX<=-170)&&(mapY>=165)&& (mapY<=175)) lcd.print("Left");//When the user points the joystick to the left, the word “Left” is displayed. if (SW_state==0) lcd.print("Pressed button"); delay(1000); } |
Note: You must download the LiquidCrystal_I2C library(Download).
YouTube Channel Banner Downloader 01-10-2323
Hey There. I found your blog using msn. This is a very well written article. I'll be sure to bookmark it and come back to read more of your useful info. Thanks for the post. I'll certainly return.
pgsoft 01-10-2323
When someone writes an paragraph he/she keeps the plan of a user in his/her mind that how a user can be aware of it. Therefore that's why this piece of writing is perfect. Thanks!
Mortgage Fairfield 19-09-2323
hey there and thank you for your info – I have certainly picked up something new from right here. I did however expertise a few technical points using this web site, as I experienced to reload the website many times previous to I could get it to load properly. I had been wondering if your hosting is OK? Not that I am complaining, but slow loading instances times will sometimes affect your placement in google and can damage your quality score if advertising and marketing with Adwords. Anyway I am adding this RSS to my e-mail and could look out for much more of your respective intriguing content. Ensure that you update this again soon.
Fairfield home mortgage 17-09-2323
What i do not understood is actually how you're not really a lot more smartly-preferred than you might be right now. You're so intelligent. You know therefore considerably in terms of this subject, produced me in my view consider it from so many numerous angles. Its like women and men don't seem to be involved except it's one thing to do with Girl gaga! Your individual stuffs excellent. Always deal with it up!
Koby 26-08-2323
My brother suggested I may like this website. He was once entirely right. This post actually made my day. You cann't consider just how much time I had spent for this info! Thanks! Look at my page; Koby
Epoxy Flooring Supply 23-08-2323
Hello, the whole thing is going fine here and ofcourse every one is sharing facts, that's really excellent, keep up writing.
Rug Cleaning 20-08-2323
Definitely believe that which you stated. Your favorite justification seemed to be at the net the simplest thing to keep in mind of. I say to you, I certainly get irked while other people think about issues that they just don't recognise about. You controlled to hit the nail upon the top and also outlined out the entire thing with no need side effect , people can take a signal. Will likely be again to get more. Thank you
autoslot168.store 14-06-2323
This is very interesting, You are a very skilled blogger. I have joined your rss feed and look forward to seeking more of your excellent post. Also, I've shared your web site in my social networks!
บราซิล999.site 25-05-2323
Hmm it seems like your website ate my first comment (it was super long) so I guess I'll just sum it up what I submitted and say, I'm thoroughly enjoying your blog. I too am an aspiring blog blogger but I'm still new to the whole thing. Do you have any tips and hints for beginner blog writers? I'd certainly appreciate it.
pgslot.place 14-05-2323
Great work! This is the kind of info that should be shared across the web. Shame on Google for no longer positioning this put up upper! Come on over and talk over with my website . Thanks =)
teenoi168.store 13-05-2323
I quite like reading an article that will make men and women think. Also, many thanks for allowing me to comment!
pgoscar.online 09-05-2323
Good day! I could have sworn I've visited this web site before but after browsing through some of the articles I realized it's new to me. Regardless, I'm definitely happy I stumbled upon it and I'll be book-marking it and checking back regularly!
pgworld.store 29-04-2323
Pretty! This has been an incredibly wonderful article. Thank you for supplying these details.
สมัครสล็อต เครดิตฟรี 15-01-2323
It is not my first time to pay a quick visit this web page, i am visiting this site dailly and get nice facts from here all the time.
เซรั่ม 27-12-2222
You could definitely see your enthusiasm within the article you write. The arena hopes for even more passionate writers like you who are not afraid to say how they believe. Always go after your heart.
สล็อต เครดิตฟรี 50 ไม่ต้องแชร์ 27-12-2222
I was very pleased to discover this great site. I need to to thank you for your time for this wonderful read!! I definitely really liked every bit of it and I have you book marked to look at new stuff in your website.
เครดิตฟรี 50 ไม่ต้องฝากไม่ต้องแชร์กดรับเอง 27-12-2222
What's up everyone, it's my first pay a quick visit at this web page, and piece of writing is in fact fruitful in support of me, keep up posting these types of posts.
ทางเข้า pg slot game 25-12-2222
May I just say what a relief to discover a person that really knows what they're discussing online. You actually realize how to bring an issue to light and make it important. More people must read this and understand this side of the story. I can't believe you aren't more popular given that you surely have the gift.
เกมสล็อตค่าย pg เว็บตรง 16-12-2222
I am really impressed with your writing skills as well as with the layout on your weblog. Is this a paid theme or did you customize it yourself? Either way keep up the excellent quality writing, it's rare to see a great blog like this one today.
special 01-12-2222
I will right away grasp your rss as I can't to find your email subscription link or newsletter service. Do you have any? Please let me recognize in order that I may just subscribe. Thanks.
tracfone 2022 28-11-2222
Howdy would you mind sharing which blog platform you're using? I'm planning to start my own blog soon but I'm having a tough time deciding between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your layout seems different then most blogs and I'm looking for something completely unique. P.S My apologies for being off-topic but I had to ask!
Sports Betting 07-11-2222
I am really impressed along with your writing talents and also with the structure on your blog. Is this a paid topic or did you modify it yourself? Anyway stay up the excellent quality writing, it's rare to look a great blog like this one today..
Carina 02-10-2222
Hey there are using Wordpress for your site platform? I'm new to the blog world but I'm trying to get started and create my own. Do you require any html coding knowledge to make your own blog? Any help would be greatly appreciated!
Rolland 02-10-2222
I really like your blog.. very nice colors & theme. Did you create this website yourself or did you hire someone to do it for you? Plz reply as I'm looking to create my own blog and would like to find out where u got this from. thanks
Leslee 12-09-2222
Howdy excellent blog! Does running a blog similar to this require a massive amount work? I have virtually no expertise in programming but I was hoping to start my own blog soon. Anyways, should you have any ideas or techniques for new blog owners please share. I know this is off topic but I just wanted to ask. Kudos!
Nickolas 20-04-2222
May I simply just say what a comfort to uncover a person that genuinely knows what they are discussing over the internet. You actually understand how to bring an issue to light and make it important. More people must check this out and understand this side of your story. I can't believe you are not more popular because you definitely have the gift.
Bryant 05-04-2222
I think that is among the most vital info for me. And i am satisfied reading your article. However wanna remark on few basic issues, The site taste is wonderful, the articles is really nice : D. Excellent activity, cheers
Maryellen 25-03-2222
I all the time used to study post in news papers but now as I am a user of net therefore from now I am using net for content, thanks to web.
Henry 03-01-2222
Hi every one, here every one is sharing these kinds of familiarity, thus it's pleasant to read this webpage, and I used to go to see this web site daily.
Dominga 03-01-2222
Thanks for sharing superb informations. Your site is very cool. I'm impressed by the details that you have on this site. It reveals how nicely you perceive this subject. Bookmarked this website page, will come back for extra articles. You, my pal, ROCK! I found just the info I already searched all over the place and just couldn't come across. What a great site.
Ashly 03-01-2222
Hello there, I discovered your site by way of Google while searching for a similar matter, your web site got here up, it seems good. I've bookmarked it in my google bookmarks.[X-N-E-W-L-I-N-S-P-I-N-X]Hi there, just become aware of your weblog through Google, and located that it's really informative. I am gonna watch out for brussels. I will appreciate should you continue this in future. Lots of other people might be benefited from your writing. Cheers!
Etta 16-12-2121
Hello to every body, it's my first pay a visit of this web site; this weblog includes awesome and actually excellent data designed for visitors.