The Adafruit Mini Analog Thumbstick is a compact joystick module that offers precise two-axis control. It is an ideal input device for DIY electronics projects, including gaming consoles, remote controls, and robotics. Its small form factor and analog output make it versatile for various applications where user input is required for directional control.
Pin Number | Name | Description |
---|---|---|
1 | VCC | Power supply (3.3V to 5V) |
2 | GND | Ground connection |
3 | VRx | Analog output for X-axis |
4 | VRy | Analog output for Y-axis |
5 | SW | Switch (activated by pressing down on the joystick) |
// Define the analog pins connected to the thumbstick
const int xAxisPin = A0;
const int yAxisPin = A1;
const int buttonPin = 2; // Digital pin connected to the thumbstick button
void setup() {
// Initialize the serial communication
Serial.begin(9600);
// Set the button pin as an input with an internal pull-up resistor
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
// Read the analog values from the thumbstick
int xPosition = analogRead(xAxisPin);
int yPosition = analogRead(yAxisPin);
// Read the button state (pressed or not)
bool buttonState = !digitalRead(buttonPin); // Invert because button is active low
// Print the X and Y positions and button state to the serial monitor
Serial.print("X: ");
Serial.print(xPosition);
Serial.print(" | Y: ");
Serial.print(yPosition);
Serial.print(" | Button: ");
Serial.println(buttonState ? "Pressed" : "Not pressed");
// Delay a bit before reading again
delay(100);
}
analogReference()
function in Arduino if you need to adjust the reference voltage for the analog inputs.Q: Can I use this thumbstick with a 3.3V system? A: Yes, the thumbstick can operate at 3.3V.
Q: How can I detect when the joystick is pressed down? A: The SW pin will go LOW when the joystick is pressed. Connect this pin to a digital input on your microcontroller and read its state.
Q: What is the life expectancy of the thumbstick? A: The life expectancy depends on usage, but it is designed to withstand repeated use within its specifications.
Q: Can I use this thumbstick for a commercial product? A: Yes, as long as you adhere to the component's specifications and usage guidelines, it can be integrated into commercial products.