Free Shipping over ₹1199

ESP32-S3 Joystick with Arduino IDE

Introduction

The Joystick module consists of two potentiometers (X and Y axes) and a push-button switch.
It outputs analog values for movement along the X and Y axes, and a digital signal for the button press.
Commonly used in robotics, gaming, and interactive control systems.
We’ll read the analog values and detect button presses using the ESP32-S3 and Arduino IDE.

Required Components

  • ESP32-S3 Board
  • Joystick module
  • Jumper wires
  • Breadboard (optional)

Pinout

Circuit Diagram / Wiring

  • Joystick (5V) → ESP32-S3 3.3
  • Joystick (GND) → ESP32-S3 GND
  • Joystick (VRx) → ESP32-S3 GPIO 15
  • Joystick (VRy) → ESP32-S3 GPIO 16
  • Joystick (SW) → ESP32-S3 GPIO 17

Code / Programming

/*
Filename: ol_joystick_read.ino  
Description: Reads X and Y analog values and button state from a joystick module  
Author: www.oceanlabz.in  
Modification: 1/4/2025  
*/
  
// Define pin connections
const int joyX = 15;        // Analog pin for X-axis
const int joyY = 16;        // Analog pin for Y-axis
const int buttonPin = 17;   // Digital pin for joystick button
  
void setup() {
  Serial.begin(115200);                  // Initialize serial monitor
  pinMode(buttonPin, INPUT_PULLUP);     // Enable internal pull-up for button
}
  
void loop() {
  int xValue = analogRead(joyX);               // Read X-axis analog value
  int yValue = analogRead(joyY);               // Read Y-axis analog value
  int buttonState = digitalRead(buttonPin);    // Read button state
  
  Serial.print("X: ");
  Serial.print(xValue);
  Serial.print(" | Y: ");
  Serial.print(yValue);
  Serial.print(" | Button: ");
  Serial.println(buttonState == LOW ? "Pressed" : "Released");
  
  delay(300);  // Short delay for stability
}

Explanation

  • The joystick outputs analog signals from the X and Y axes, read using analogRead() on ESP32-S3 ADC pins.
  • The built-in button outputs a digital LOW signal when pressed, read using digitalRead().
  • Commonly used for controlling direction, speed, and interactive inputs in robotics or games.

Troubleshooting

  • Ensure the joystick’s VCC is connected to 3.3V, not 5V (ESP32-S3 is 3.3V logic).
  • Use only ADC-compatible pins like GPIO15, 16, or 17 for analog input.
  • If the button always shows “pressed”, try using INPUT_PULLUP and check wiring to SW and GND.

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Need Help?