Ozeki 10
IR Transceiver IR Transceiver | Arduino Mega Arduino Mega

How to use an Arduino Joystick

In the following guide, you will learn about the Arduino Joystick. The Analog Joystick is similar to two potentiometers connected together, it can be very handy for retro gaming, robot control or RC cars. The guide contains some basic information about how an Arduino joystick works, then you will be able to see how you can work with a joystick connected to your Ozeki 10. First, let's start with the basics of Arduino joystick.

What is an Arduino Joystick?

The joystick in the picture is nothing but two potentiometers that allow us to messure the movement of the stick in 2-D. Potentiometers are variable resistors and, in a way, they act as sensors providing us with a variable voltage depending on the rotation of the device around its shaft.

How does an Arduino joystick work?

The joystick sends two analog values to the Arduino board. These values represent the position of the joystick on the X and Y axes from the range of 0 to 1023. This means, when the joystick is in the middle, these values are 511,511. If you turn the joystick on the horizontal line, the X value changes between the range and the Y value changes when you turn the joystick on the vertical line.

How to use an Arduino joystick?

To work with an Arduino joystick, you need to connect some wires to your Arduino as the wiring diagram (Figure 1) shows it. The GND pin from the joystick needs to be connected to the ground (Gnd). The +5V pin goes to the 5V pin of the Arduino. Then, the VRx and VRy pins go to two analog inputs and lastly, the SW pin connects to a digital input.

Arduino Joystick wiring diagram

wiring diagram of arduino joystick
Figure 1 - Wiring diagram of Arduino Joystick

How to use an analog joystick in Ozeki

Analog Joystick connections guarantee that all of the joystick interactions are forwarded to a selected connection in your Ozeki software. You can test your own joystick through the GUI as you can see in the 3rd video below. Most analog joystick has a top button as well which can be handled by this connection. To use the Arduino Joystick in Ozeki, you first need to download Ozeki Robot Developer. Ozeki Robot Developer will install the Arduino libraries needed to use this sensor efficiently.

Download Ozeki Robot Developer

Download Ozeki Robot Developer

After Ozeki Robot developer is installed, you need to upload the Joystick control code to your Arduino. You can find the code and download instructions on the following pages. The upload process includes two steps: first you need to format the EEPROM of the arduino, then you need to upload the control code. The procedure is very simple, it only takes a few seconds.

Upload the Joystick code to Arduino Uno
Upload the Joystick code to Arduino Mega 2560
Upload the Joystick code to Arduino Nano

The arduino joystick and Ozeki will communicate over the USB port using the Ozeki Joystick protocol. This protocol makes it possible for you to use the joystick directly on your PC. You will be able to control this joystick through the web based user interface or you will be able to communicate with it using Ozeki Chat. You can read more about chat control on the following page.

How to communicate with the Joystick using chat

It is important to understand chat control, because when you build a robot, the way you wish to control this joystick is by sending and receiving messages. If you open the Ozeki Robot Developer app, you will see, who you can write a C#.Net program to work with this joystick.

Connection steps

  1. Follow the wiring diagram to wire the joystick to the Arduino
  2. Connect the Arduino to your computer using an USB data cable
  3. Check the COM ports in Windows device list
  4. Open the Arduino application on your computer
  5. Upload example code to the Arduino
  6. Open Ozeki 10 GUI in your browser
  7. Select the connection of Arduino joystick
  8. Move the joystick and check the movements in Ozeki 10

System overview

The system we suggest consists of a joystick, that is wired to the analog port of your Arduino. The Arduino will be responsible for reading data from this device in real-time. The brain of the system will be running on a PC (Figure 2). On the PC, Ozeki 10 will be able to manage the communication. You can easily run Ozeki 10 using a webbrowser

setup joystick to pc using arduino
Figure 2 - System configuration of joystick connecting to PC using Arduino

Prerequisites

  • Analog joystick
  • 1kΩ resistor
  • Ozeki 10 installed on your computer
  • Programmable board (Arduino Mega/Nano/Uno)
  • USB cable between the board and your computer

Step 1 - Wire the analog joystick to your Arduino

You can see how to wire the analog joystick to any of the following boards:

After wiring, please plug the board to your computer!

Step 2 - Upload code to the microcontroller

(Here is the code to upload)

Step 3 - Start Ozeki 10 to try the joystick

Step 4 - Configure your joystick in Ozeki 10

In order to configure your joystick (attached to your Arduino) in Ozeki 10, that is installed on your computer, you need to open the graphical user interface (GUI) of Ozeki 10. You can open the GUI by entering the URL of the computer into your webbrowser. For example, if our PC has an IP address of 192.168.1.5, we would enter http://192.168.1.5:9513 into our webbrowser.

Step 5 - Understand the jostick protocol

The Analog Joystick Controller can communicate with Ozeki through the following protocol.

References:
https://www.arduino.cc
https://exploreembedded.com

Copyright © 2000- - Ozeki Ltd | info@ozeki.hu
Home > Products > Ozeki 10 > Connections > Arduino > Joystick
Legal | Privacy | Terms of use | 2988
35.172.233.215 | 92.118.27.157 | Login