Build and code a circuit to control the analog joystick included in the Arm Robot kit. Move the joystick in both of its axis and when you release it, its position values will be displayed on the screen.
DIFFICULTY LEVEL: Beginner.
DURATION OF THE EXERCISE: 20 min.
- 1 Joystick
- 1 Build&Code UNO board
- 1 Sensor Shield
What is an analog joystick?
The joystick is an analog controller that can be moved around 360º and allows you to control many devices. It is mainly used in video game consoles but you can also use it to easily maneuver robots or other kind of machines.
A joystick is composed of a sway system with 2 orthogonal axis attached to 2 potentiometers. These potentiometers measure the joystick X and Y axis position.
One of the axis is set over a micro switch, which allows you to detect when the joystick is pressed down.
A joystick gives an analog signal for each axis and a digital signal when the it is pressed.
- Connect the joystick to the Build&Code sensor shield, which should be connected to the Build&Code UNO board, as indicated in step 14 of the Arm Robot user manual.
- In order to give power to the joystick, connect the Vcc output (red cable) to the V pin of the A0 analog port. Also, connect the GND output to the G pin of the Build&Code analog port.
- Connect the VRx output to the S pin of the A0 analog port (yellow cable). Also, connect the VRy output to the S pin located in the A1 analog port of the Build&Code UNO (green cable)
- In order to check that the connections are correct, go to the Connections section, and Joysticks Connection subsection of the Arm Robot Manual.
You can do this project using the Arduino program or a visual programming software by blocks compatible. Below you will find the necessary code.
Before starting to assemble the Arm Robot, follow these steps:
- Download and install the Arduino IDE program. It is available for Windows, Mac OS and Linux.
- Open the Arduino program and copy the following program in it:
- To see the values on screen, click on the lens icon and a window will open:
If you move the joystick to the right, left, up or down, you will see how the X and Y values change from 0 to 1023.Example:
Code for the visual programming software by blocks compatible
- Download and install the program.
1.1 Open the software.
1.2 Configure the program to save code into the Build&Code UNO board. You will find the instructions in the Arm Robot First Steps guide.
- Open the program and copy the following code. Use the following image as a guide:
RESULT OF THE EXERCISE
When moving the joystick to the right, left, up and down, you will see how the variables in X and Y change between 0 and 1023.
This is the first step to understand how to program the joystick and which kind of data are we receiving, to program the Arm Robot so that is makes the movements we want.