IoTSimulator

Analog Joystick: How It Works, Wiring, and Example Code

A thumb-controlled input module that gives analog X/Y movement plus a pushbutton for Arduino projects.
M
Muhammad Ichsan
Published 04 May 2026
Analog Joystick

This article is a guide about the Analog Joystick. We will explain how it works, show its wiring, and walk through an Arduino example you can use in your own projects.

Joysticks are useful when a project needs human control instead of a fixed sensor reading. They are often used in game controllers, robot direction control, menu navigation, and small interface panels where the user needs to move something up, down, left, right, or press a button.

Before looking at the pin layout, it helps to know what the module is actually doing inside the housing. That will make the next sections easier to follow.

Description

An analog joystick looks like a small game controller stick, but inside it is really a pair of potentiometers and a pushbutton. When you move the stick, the module changes the voltage on the X and Y output lines. When you press the stick downward, the center switch closes and acts like a button.

Analog joystick module
Analog joystick module

That combination makes it very handy for interactive projects because one part can give both movement and click input. The Arduino can read the analog values to know where the stick is pointing, then read the switch to know when the user pressed it.

In simple projects, the joystick is often used to control direction, choose menu items, or move a cursor. In more advanced projects, the same module can drive motors, control a camera pan, or navigate a small UI on a display.

Features

Here are the main things to know about an analog joystick:

FeatureWhat it means
Two analog axesGives separate X and Y movement values so the Arduino can detect direction.
Center voltageThe idle position sits near VCC/2, which is why the readings usually settle in the middle.
Axis polarityHORZ and VERT move in opposite numeric directions depending on which side you push.
PushbuttonThe stick can also be pressed like a switch through the SEL pin.
Button bounceThe press signal can bounce, so pull-up logic and a small delay help keep it stable.
Dead-zone friendlyThe center can drift slightly, so projects usually ignore a small middle range.
Interactive controlGreat for menus, robot steering, cursor movement, and game input.

The module is simple, but it gives a project a very natural user feel. A single thumb can move the stick, and the board can immediately react to direction, speed, and the press state. That is what makes it feel more like a real controller than a plain sensor.

One helpful detail is that the joystick does not just report "left" or "right" in a binary way. It gives you a moving analog value, so you can decide how far the stick was pushed and use that to control speed, menu scrolling, or cursor movement more smoothly.

How Does It Work?

The joystick works by turning movement into voltage changes. When the stick moves left, right, up, or down, the internal resistive sensors change their output values. The Arduino reads those changes with analogRead() and gets a number that tells it how far the stick moved from the center.

At the center position, the joystick usually sits near the middle of the analog range. On an Arduino Uno, that reading is often around 512 because the board uses a 10-bit analog converter. Wokwi models the idle position as VCC/2, which is a helpful mental model when you are trying to understand why the stick settles in the middle.

How an analog joystick works
How an analog joystick works

The center button works separately from the analog axes. It does not give a number like the X and Y lines do. Instead, it behaves like a switch that tells the Arduino whether the stick is pressed down or not.

Center Position

When you release the joystick, it springs back toward the middle. That resting point is important because many projects treat it as the neutral position. If the stick is not being pushed, the readings should stay close to center.

In practice, the center value can drift a little, so many sketches use a small dead zone around the middle. That keeps tiny hand motion or sensor noise from making the project move when the stick looks like it is still.

X And Y Axes

The X axis changes when you move the stick left or right, and the Y axis changes when you move it up or down. In the Wokwi analog joystick reference, the horizontal output increases toward the left side and the vertical output increases toward the top, so direction handling can feel inverted if you expect the opposite.

That is why joysticks are a good choice for motion controls and menus. The code can compare both values at the same time and decide whether the user wants to move up, down, left, right, diagonal, or stay in the center.

Pushbutton

Pressing the joystick downward closes the center switch. In Arduino code, this is usually read as a digital input with a pull-up resistor, so the value goes LOW when the button is pressed.

That extra button makes the module more flexible than a plain two-axis sensor. You can use the axes for movement and the switch for select, confirm, or action input in the same project.

Direction Mapping

Raw values are useful for debugging, but real projects often map the readings into a smaller range. That makes it easier to decide whether the stick is being pushed a little or a lot. The map() function is often used to convert the analog values into percentages or game-control values.

For example, you might convert the horizontal axis into -100 to 100 so the joystick becomes easier to use for robot steering, cursor movement, or speed control.

Dead Zone

A dead zone is a small center area where the sketch treats the joystick as neutral. This is important because the stick may not return to exactly the same number every time, and tiny drift can make the project feel noisy.

With a dead zone, values near the middle are ignored. That makes the stick much easier to use for menus and movement controls because the project only reacts when the user really pushes it away from center.

Explanation Per Part of Analog Joystick

The joystick module is built from two analog axes and one pushbutton. Each part has a specific job, and understanding those parts makes the module easier to use in any project.

Analog joystick anatomy and pinout
Analog joystick anatomy and pinout

Joystick PinPart RoleSignal Type
VCCPowers the modulePower
GNDShared electrical referenceGround
VERTVertical movement outputAnalog
HORZHorizontal movement outputAnalog
SELCenter press switchDigital

For a beginner build, this is a very friendly component to understand. Once you know what each part does, the wiring and sketch logic become much easier to follow.

Arduino With Analog Joystick

This wiring example connects the joystick to an Arduino Uno in the most common way: power and ground go to the board first, the vertical and horizontal outputs go to analog inputs, and the press switch goes to a digital pin with pull-up logic.

The layout below is easy to remember. VCC powers the module, GND completes the circuit, VERT maps to A0 for vertical movement, HORZ maps to A1 for horizontal movement, and SEL maps to D2 for the click action.

SCL
SDA
AREF
GND.1
D13
D12
D11
D10
D9
D8
D7
D6
D5
D4
D3
D2
D1
D0
IOREF
RESET
3V3
5V
GND.2
GND.3
VIN
A0
A1
A2
A3
A4
A5
VCC
VERT
HORZ
SEL
GND

This circuit shows the joystick connected to an Arduino Uno in the same way many beginner projects are wired. The Arduino reads the two axes as analog signals and the press switch as a digital input, so you can use the same wiring for menus, robot control, or cursor movement.

Code

This sketch reads the X axis, Y axis, and button state, then prints them to Serial Monitor. That makes it easy to test the module before you connect it to a motor, a menu, or a game control. The example also adds a small dead zone so the center position stays calm instead of jumping around.

C++ Source
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

The sketch is intentionally small so you can see the raw input values clearly. Once you understand the readings, you can convert them into direction commands, menu movement, or movement speed in your own project.

How The Code Works, Part By Part

Let's break the sketch into smaller pieces so each part is easier to understand.

Pin Setup

First, the sketch stores the joystick pins in variables. That makes the code easier to read and easier to change later if you want to move the module to different pins.

C++ Source
1
2
3
4
5
6
7
8

Reading The Axes

analogRead() reads the X and Y voltages and returns a number from 0 to 1023 on the Arduino Uno. The center position is usually near the middle of that range, while movement in either direction pushes the values up or down.

C++ Source
1
2
3
4
5

Reading The Button

The button uses INPUT_PULLUP, so the input stays HIGH when it is not pressed and becomes LOW when the stick is pushed down. That is why the code checks for LOW to decide whether the button is pressed.

C++ Source
1
2
3
4
5

Mapping The Range

After reading the raw values, many projects map them into a smaller range. That gives your sketch a cleaner control signal for speed, position, or menu movement.

C++ Source
1
2

Printing The Values

Finally, the sketch sends the readings to Serial Monitor. That gives you a quick way to see whether the joystick is moving correctly and whether the button press is working.

C++ Source
1
2
3
4
5
6
7
8

Dead Zone And Calibration

Real joysticks do not always return exactly the same center value every time. The springs inside the module, tiny manufacturing differences, and small hand movements can all push the reading a little away from the true middle. A dead zone helps the sketch ignore that small drift so the control feels calm instead of jumpy.

A good dead zone is usually just wide enough to cover the tiny noise near the center, but not so wide that the stick feels lazy. If the dead zone is too small, the cursor or robot may move when you think the joystick is resting. If it is too large, the stick will feel unresponsive until you push it much farther away from the center.

Calibration is the step where you measure the center value from your own module and use that number as the baseline. Different joysticks can sit a little above or below 512, so using your real center reading makes the project feel smoother and more accurate. Many sketches store the center once at startup or use the first few samples to find a stable baseline.

Calibration Step

To calibrate the joystick, read the X and Y pins while the stick is untouched, then save those numbers as the neutral point. After that, compare future readings against the saved values instead of assuming the center is always exactly 512.

That approach is helpful for menu controls, cursor movement, and robot steering because it keeps the control behavior consistent across different joystick modules.

Dead Zone Tuning

Once the center is known, you can define a small range around it and treat that range as neutral. Inside the range, the joystick does nothing. Outside the range, the sketch begins to react and convert movement into direction or speed.

This is the part that turns a raw analog reading into a comfortable user interface. A well-tuned dead zone makes the joystick feel stable, predictable, and much easier to use in a real project.

Wrapping Up

The analog joystick is a simple but powerful input module. It gives you two movement axes and a press button in one part, which makes it very useful for interactive Arduino projects.

Once you understand the analog readings, the center position, and the button logic, you can use the joystick for controls, menus, games, and robot movement with confidence.

New

Wait! We're building more...

Our laboratory is currently preparing a lot of exciting new projects using Analog Joystick. Stay tuned for the upcoming massive update!

Projects Using Analog Joystick

Explore practical implementations

No official projects found for this component yet.

Muhammad Ichsanul Fadhil
About Writer

Muhammad Ichsanul Fadhil

"I'm a developer and hardware enthusiast with a passion for IoT. I love experimenting with new components and writing down everything I learn to help others build their own projects."

Share this article

Share it with your favorite channel.