ESP32 - DIYables Bluetooth App Joystick
Overview
The Bluetooth Joystick example provides an interactive 2D joystick control accessible through the DIYables Bluetooth STEM app. Designed for ESP32 boards with support for both BLE (Bluetooth Low Energy) and Classic Bluetooth connections. The joystick sends real-time X and Y coordinate values ranging from -100 to +100, making it ideal for robot control, motor driving, servo positioning, and any application requiring directional input.
This example supports two Bluetooth modes:
- ESP32 BLE (Bluetooth Low Energy): Works on both Android and iOS
- ESP32 Classic Bluetooth: Works on Android only. iOS does not support Classic Bluetooth. Use BLE if you need iOS support.

Features
- 2D Control: X and Y axes with values from -100 to +100
- Real-time Updates: Instant position updates via Bluetooth communication
- Auto-Return Option: Configurable auto-return to center position (0, 0)
- Adjustable Sensitivity: Configure minimum movement threshold to filter small changes
- Robot Compatible: Values easily mapped to motor driver inputs
- BLE & Classic Bluetooth: Choose the Bluetooth mode that suits your project
- Cross-Platform: BLE mode works on both Android and iOS; Classic Bluetooth works on Android
- Low Power Option: BLE mode consumes less power than Classic Bluetooth
Hardware Used In This Tutorial
Or you can buy the following kits:
| 1 | × | DIYables ESP32 Starter Kit (ESP32 included) | |
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
ESP32 Code
Quick Instructions
Follow these instructions step by step:
- If this is your first time using the ESP32, refer to the tutorial on setting up the environment for ESP32 in the Arduino IDE.
- Connect the ESP32 board to your computer using a USB cable.
- Launch the Arduino IDE on your computer.
- Select the appropriate ESP32 board and COM port.
- Navigate to the Libraries icon on the left bar of the Arduino IDE.
- Search "DIYables Bluetooth", then find the DIYables Bluetooth library by DIYables
- Click Install button to install the library.

- You will be asked for installing some other library dependencies
- Click Install All button to install all library dependencies.

Choose one of the two Bluetooth modes below depending on your needs:
ESP32 Classic Bluetooth Code (works with app on Android only)
Note: Classic Bluetooth is NOT supported on iOS. If you need iOS support, use the BLE code below.
- On Arduino IDE, Go to File Examples DIYables Bluetooth Esp32Bluetooth_Joystick example, or copy the above code and paste it to the editor of Arduino IDE
- Click Upload button on Arduino IDE to upload code to ESP32
- Open the Serial Monitor
- Check out the result on Serial Monitor. It looks like the below:
ESP32 BLE Code (works with app on both Android and iOS)
- On Arduino IDE, Go to File Examples DIYables Bluetooth Esp32BLE_Joystick example, or copy the above code and paste it to the editor of Arduino IDE
- Click Upload button on Arduino IDE to upload code to ESP32
- Open the Serial Monitor
- Check out the result on Serial Monitor. It looks like the below:
Mobile App
- If you are using the ESP32 Classic Bluetooth code, you need to pair the ESP32 with your Android phone before opening the app:
- Go to your phone's Settings > Bluetooth
- Make sure Bluetooth is turned on
- Your phone will scan for available devices
- Find and tap "ESP32_Joystick" in the list of available devices
- Confirm the pairing request (no PIN required)
- Wait until it shows "Paired" under the device name
- If you are using the ESP32 BLE code, no pairing is needed. Just proceed to the next step.
- Open the DIYables Bluetooth App
- When opening the app for the first time, it will ask for permissions. Please grant the following:
- Nearby Devices permission (Android 12+) / Bluetooth permission (iOS) - required to scan and connect to Bluetooth devices
- Location permission (Android 11 and below only) - required by older Android versions to scan for BLE devices
- Make sure Bluetooth is turned on on your phone
- On the home screen, tap the Connect button. The app will scan for both BLE and Classic Bluetooth devices.

- Find and tap your device in the scan results to connect:
- For Classic Bluetooth: tap "ESP32_Joystick"
- For BLE: tap "ESP32BLE_Joystick"
- Once connected, the app automatically goes back to the home screen. Select the Joystick app from the app menu.

Note: You can tap the settings icon on the home screen to hide/show apps on the home screen. For more details, see the DIYables Bluetooth App User Manual.
- Move the joystick in any direction to send X/Y coordinate values

Now look back at the Serial Monitor on Arduino IDE. You will see:
- Move the joystick in the app and watch the real-time X/Y values in the Serial Monitor
Creative Customization - Adapt the Code to Your Project
Configure Auto-Return and Sensitivity
Set joystick behavior with constructor parameters:
Handle Joystick Position Changes
Use the onJoystickValue() callback to receive X/Y coordinates:
Handle Configuration Request from App
When the app connects and opens the Joystick screen, it requests the joystick configuration from ESP32. You can use the onGetConfig() callback to send the current joystick values to the app at that moment:
Send Values to App
You can send joystick coordinate values from ESP32 to the app:
Handle Connection Events
You can detect when the app connects or disconnects from the ESP32:
How to Use the Joystick
App Interface Controls
The joystick interface in the DIYables Bluetooth App provides:
- Virtual Joystick Pad: Touch and drag to control position
- X Value Display: Shows current horizontal position (-100 to +100)
- Y Value Display: Shows current vertical position (-100 to +100)
Value Ranges
The joystick provides:
- X Axis: -100 (full left) to 0 (center) to +100 (full right)
- Y Axis: -100 (full down) to 0 (center) to +100 (full up)
- Center Position: (0, 0) when joystick is at rest
Programming Examples
Basic Joystick Handler
Two-Wheel Robot Control
Pan-Tilt Servo Control
LED Matrix Direction Indicator
Advanced Programming Techniques
Dead Zone Filter
Speed Ramping
Magnitude and Angle Calculation
Hardware Integration Examples
Mecanum Wheel Robot
Stepper Motor Position Control
BLE vs Classic Bluetooth - Which to Choose?
| Feature | BLE (Esp32BLE_Joystick) | Classic Bluetooth (Esp32Bluetooth_Joystick) |
|---|---|---|
| iOS Support | ? Yes | ? No |
| Android Support | ? Yes | ? Yes |
| Power Consumption | Low | Higher |
| Range | ~30-100m | ~10-100m |
| Data Rate | Lower | Higher |
| Pairing Required | No (auto-connect) | Yes (manual pairing) |
| Best For | Battery-powered, cross-platform | High throughput, Android-only |
Troubleshooting
Common Issues
1. Cannot find the device in the app
- Make sure the ESP32 is powered on and the sketch is uploaded
- For BLE: Ensure your phone's Bluetooth and Location are enabled
- For Classic Bluetooth: Pair the device first in phone's Bluetooth settings
- Check that the correct partition scheme is selected (Huge APP)
2. Joystick not responding
- Check Bluetooth connection status in the app
- Verify connection in Serial Monitor
- Try disconnecting and reconnecting
3. Joystick values seem erratic
- Increase sensitivity value to filter small movements: bluetoothJoystick.setSensitivity(10.0)
- Apply a dead zone filter in your callback
- Check for interference from other Bluetooth devices
4. Connection drops frequently
- Move closer to the ESP32 (reduce distance)
- For BLE: Check for interference from other BLE devices
- For Classic Bluetooth: Ensure stable power supply to ESP32
- Check Serial Monitor for disconnect/reconnect messages
5. Motors don't stop when joystick is released
- Ensure auto-return is enabled: bluetoothJoystick.setAutoReturn(true)
- Add a dead zone check in your motor control code
- Add a safety stop in setOnDisconnected() callback
6. Sketch too large / not enough space
- In Arduino IDE, go to Tools > Partition Scheme and select "Huge APP (3MB No OTA/1MB SPIFFS)" or "No OTA (Large APP)"
- The default partition scheme only provides ~1.2MB for app code, which is not enough for Bluetooth libraries
- This setting gives ~3MB by sacrificing the OTA (over-the-air update) partition
Debug Tips
Add comprehensive debugging:
Project Ideas
Robotics Projects
- Bluetooth-controlled differential drive robot
- Mecanum or omnidirectional wheel robot
- Robotic arm joint control
- Drone ground station controller
Camera Projects
- Pan-tilt camera mount control
- Motorized camera slider positioning
- Surveillance camera remote control
Game Projects
- Bluetooth game controller for ESP32 games
- Maze navigation game
- LED matrix joystick games (Snake, Pong)
Industrial Projects
- CNC jog controller
- Motorized stage or platform positioning
- Crane or winch directional control
Integration with Other Bluetooth Apps
Combine with Bluetooth Slider
Use joystick for direction and sliders for speed limits:
Combine with Bluetooth Monitor
Use joystick for control and monitor for telemetry:
Next Steps
After mastering the Bluetooth Joystick example, try:
- Bluetooth Slider - For precise analog value control
- Bluetooth Digital Pins - For discrete on/off control
- Bluetooth Monitor - For debugging joystick values
- Multiple Bluetooth Apps - Combining joystick with sliders and other controls
Support
For additional help:
- Check the API Reference documentation
- Visit DIYables tutorials
- Arduino community forums