# Using Analog Joystick From 37 Sensors Kit

416

4

1

## Introduction: Using Analog Joystick From 37 Sensors Kit

So you went out and bought a kit of electrical sensors and modules for a good price called "37 Sensors" ( like this one here or others on Amazon), but can't find information on the modules to be able to use them? This series of Instructables will help you out with all of the modules in the 37 Sensors Kit. There are other kits that sell a different number of modules than 37, such as a 20 module kit, and a 45 module kit. These sensors/modules are also available from some online stores individually.

These kits are excellent for STEM (Science, Technology, Engineering, and Mathematics) experimentation and education.

The module from the 37 Sensors Kit called "Analog Joystick" is a joystick module like the one found on many game controllers. The Analog Joystick module might be used in an embedded project for man-machine interfacing such as controlling a robot actuator, drawing onto an LCD display, quad-copter control, and playing computer games.

(Images and information used with permission from 37sensors.com)

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

## Step 1: Analog Joystick Description

The Analog Joystick module is made from two potentiometers that are set at right angles to each other. One potentiometer registers movement in the X direction, the other potentiometer registers movement in the Y direction.

The module needs a ground and power connection to whatever microcontroller you might be interfacing. Voltage can be 5V or 3.3V as with the typical microcontroller.

The Analog Joystick provides a 0-5V (or 0-3.3V) output in that represents both the X and Y position of the two potentiometers. There is a spring in each potentiometer that centers the potentiometer. Thus the joystick stays in the middle position when it is not touched.

Pushing the knob down engages a momentary switch. This Z direction signal isn't analog but instead is a digital output. The Z output of the module can be read by a digital input to the microcontroller.

## Step 2: Analog Joystick Specification

Voltage: 3.3V to 5.0V (No active components with voltage limits, so using other voltages are possible.)

LED: none

X Potentiometer: 10 k ohm, return-to-center

Y Potentiometer: 10 k ohm, return-to-center

Z switch: momentary SPST, pulled to +Voltage on some modules. Active low. Tactile.

Main component datasheet: 252_Series

Size: 25mm X 35mm

There are a number of different sources for these modules. Not every module that looks similar to the ones here behaves exactly the same. Check the specific module that you have for differences in function, voltage levels, pinout, and inactive/active states. Some modules have been found to have incorrectly labeled pins and even poorly soldered components.

Button press (Z switch) is a bit difficult to do without making a substantial change to the X and Y values with the pots centered, and impossible with the pots in some positions.

The unpopulated R5 on the module tested would be the location for the pull-up resistor for the button. If needed, this can be populated with a 10kohm 0805 SMT resistor.

## Step 3: Analog Joystick Experiment Supplies

Just to see the basics of how this module works, this experiment shows how to interface it to a simple-to-understand microcontroller board. This microcontroller board is a \$12.99 kit that can be assembled easily. There is no need for a complicated development system as the 32-bit micro that is part of this board has all of the smarts built in. The board shape even allows it to be used with Arduino Shields.

Code for other microcontroller platforms would likely be in a different language/syntax, but similar in form.

Here is the small list of components for this experiment:

1. Analog Joystick from 37 Sensors Kit. (This experiment's source: CircuitGizmos) Kits also available at Amazon and online in many places.
2. Jumper Wires, female to female "DuPont" style. (This experiment's source: CircuitGizmos) Jumpers of this type are also available online.
3. Microcontroller Board. (This experiment's source: CircuitGizmos for the \$12.99 kit. An assembled board of a more capable but similar device is also available.)
4. Power supply. The board accepts 7-10VDC through barrel jack or 5V/3.3V through the connector.
5. USB serial Interface. A USB connection to a PC and 3.3V level connection for ground, transmit, and receive for the board.

A PC with a serial terminal application is used to communicate with the board. One such free and useful program is Beagle Term.

With all of this, you can perform an experiment to test the Analog Joystick.

## Step 4: Analog Joystick Experiment Hookup

The assembled microcontroller board is attached to the Analog Joystick as follows:

1. Ground connection on the module = ground on the microcontroller board
2. +Voltageconnection on the module = 3.3V on the microcontroller board
3. Switch connection on the module = uM6 (microcontroller pin 6) on the microcontroller board
4. X connection on the module = uM4 (microcontroller pin 4) on the microcontroller board
5. Y connection on the module = uM5 (microcontroller pin 5) on the microcontroller board

Connect the USB serial interface to the PC (USB end) and to the serial signal connection of the microcontroller board (near the green power LED). The ground connections between the serial interface and the board connect together, and the transmit signal of one goes to the receive signal of the other.

Power up the microcontroller board. I used a 12VDC supply that worked just fine.

Start Beagle Term on the PC and connect to the serial port number that is appropriate for the USB serial interface. Bitrate needs to be 38400, 8N1 with no flow control. Tap the enter key and you should get a ">" prompt.

## Step 5: Analog Joystick Experiment Code

With the PC connected to a powered microcontroller board, Beagle Term is the window into what is happening on that board. You can enter program code, see the printed results of that code, and even interact by typing information into a running program.

Typing EDIT at the ">" prompt will connect you to the built-in editor. It is in this editor that you will enter the program code. You can save the code that you type in with a Control-Q keystroke. You can save and immediately run the code that is in the editor with Control-W.

Control keys for the program EDIT function. (Function keys don't work right in Beagle Term)

• Control-U - Move to line home
• Control-U Control-U - Move to start of the program
• Control-K - Move to the line end
• Control-K Control-K - Move to end of the program
• Control-P - Page up
• Control-L - Page down
• Control-] - Delete
• Control-N - Insert
• Control-Q - Save the code
• Control-W - Run the code
• Control-R - Find
• Control-G - Repeat find
• Control-T - Mark text
• Control-Y - Paste text
• ESC - Exit from editor abandoning changes.

Enter this experiment's code in the editor:

```SETPIN 6, DIN, PULLUP
SETPIN 4, AIN
SETPIN 5, AIN

DO
PAUSE 200
S = PIN(6)
X = PIN(4)
Y = PIN(5)
PRINT S, X, Y
LOOP```

This code sets the signal lines to analog inputs for X and Y and a digital input for the switch. The digital input is configured with an internal pull-up resistor.

The loop code then reads those inputs and prints them out to the console every 1/5th of a second.

If you run this code you will see the output sent to Beagle Term. That output will change as you move the joystick around. The switch output will change when you depress the joystick knob.

## Step 6: Analog Joystick Experiment Results

The S variable is digital, so the PRINT statement will display either a 1 for unpressed or a 0 for pressed.

The X and Y variables are analog and will display values from 0V to 3.3V.

With the joystick not moved from the center position, both X and Y are at around 1.65V.

## Step 7: Analog Joystick Summary/Feedback

Most of the Analog Joysticks found in 37 Sensors Kits are very similar to the one described here.

If you have any additional information on the specifications or behavior of this type of module, please comment here and I'll include the relevant information. If you know of a module that is similar, but perhaps available singly or in a different kit of modules, please mention that.

The comments area would also be a good place to include small sample code for other microcontroller platforms if you have experimented with this module.

Thanks for reading and contributing to this collection of 37 Sensor Instructables!

Analog Hall-Effect

Analog Joystick

Analog Temperature Sensor

Ball Switch

Bi-color LED

Button

Character LCD

Flame

Hall-effect Switch

Humidity and Temperature

IR Transmitter

LASER

Light Cup

Liquid

Mercury Switch

Microphone

Multicolor Flashing LED

Obstacle Avoidance

Photo Interrupter

Photoresistor

Piezo Driver or Annunciator

Pulse

Reed Switch

RGB LED

Rotary Encoder

Servo

Shock and Impulse

Single Relay

Speaker

Temperature 18B20

Temperature Threshold

Touch Sensor

Tracking

Ultrasonic Distance

46 3.4K
5 1.8K
6 2.3K

## Discussions

Thanks again :)