Joystick (2 axes) with TinkerPie
Read X on one pin and Y on another. The push button goes to a digital pin.
| Type | Analog sensors |
|---|---|
| Connect to | VRx and VRy to two of P10-P13 |
| Gives | -100 to 100 per axis |
| Simulator | Yes: a control appears under the simulated board |
How it works
A joystick has two knobs (potentiometers) inside, one for left-right (X) and one for up-down (Y), plus a push button under the stick. TinkerPie turns each axis into a number from -100 to 100, with 0 in the middle.
How to wire it
Plug the module's A0 / OUT into P10 (or P11-P13 when Wi-Fi is off), VCC to 3.3 V, GND to GND.
Code
In blocks: Accessories category in TinkerPie Studio. As code:
// JavaScript
sensors.joystick(Pin.P10)
// Arduino C++
sensors::joystick(Pin::P10) Good to know
- Connect X and Y to analog pins and the button to a digital pin.
- The middle is rarely exactly 0, so ignore small values (a "dead zone").
- Perfect for driving robots and moving dots on the matrix.
Projects with the Joystick (2 axes)
Similar modules
- Potentiometer (knob)
- Soil moisture sensor
- Light sensor module (LDR)
- Sound sensor module
- Gas / smoke sensor MQ-2
- Air quality sensor MQ-135
- Rain drop sensor
- Water level sensor
More projects to try
Questions
Can I try the Joystick (2 axes) without buying one?
Yes. In TinkerPie Studio the simulator shows a control for it under the board, so you can test your program before you build it.
Why does my robot move slowly when I am not touching the joystick?
The stick does not rest at exactly 0. Treat values between -10 and 10 as 0 in your code.