Arduino Nano ESP32 - Web Apps Web Joystick
Overview
This tutorial covers the DIYablesWebJoystickPage class from the DIYables ESP32 WebApps Library. The browser page renders a touch- and mouse-capable virtual joystick that sends X/Y coordinates to the Arduino Nano ESP32 over WebSocket. The sketch registers a callback that receives these values and can apply them to motor drivers, servo controllers, or any directional hardware.

What This Tutorial Covers
- Instantiating the joystick page with auto-return and sensitivity settings
- Receiving X/Y position values in a sketch callback
- Using coordinates to control a differential-drive motor system
- Returning the current joystick position to the browser on request
Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Steps
Follow these instructions step by step:
- If this is your first time using the Arduino Nano ESP32, refer to the tutorial on setting up the Arduino Nano ESP32 development environment.
- Connect the Arduino Nano ESP32 board to your computer using a USB cable.
- Launch the Arduino IDE on your computer.
- Select the appropriate board (e.g. Arduino Nano ESP32) and COM port.
- Navigate to the Libraries icon on the left bar of the Arduino IDE.
- Search "DIYables ESP32 WebApps", then find the DIYables ESP32 WebApps Library by DIYables
- Click Install button to install the library.
- Search for DIYables ESP32 WebApps created by DIYables and click the Install button.
- You will be asked for installing some other library dependencies
- Click Install All button to install all library dependencies.
- On Arduino IDE, Go to File Examples DIYables ESP32 WebApps WebJoystick example, or copy the above code and paste it to the editor of Arduino IDE
- Update the WiFi credentials in the sketch:
- Click Upload button on Arduino IDE to upload code to Arduino Nano ESP32
- Open the Serial Monitor
- The Serial Monitor output should resemble the following:
- If nothing appears, press the reset button on the board.
- Enter the IP address from the Serial Monitor into a browser on the same network.
- Example: http://192.168.0.2
- The home page displays a card for the joystick application:

- Select the Web Joystick card to open the control page:

- The page is also accessible directly at http://192.168.0.2/web-joystick.
- Drag the joystick and observe the X/Y values printed in the Serial Monitor.
Joystick Configuration
Default Settings
Custom Settings
Coordinate System
- X-axis: –100 (full left) to +100 (full right)
- Y-axis: –100 (full down) to +100 (full up)
- Center: X = 0, Y = 0 (neutral)
Callbacks
Receiving Position Updates
Supplying Position to the Browser
Called when a browser connects and requests the current state:
Motor Control Example
Map joystick X/Y to a differential-drive motor system:
Troubleshooting
Joystick moves in the browser but Serial Monitor shows nothing
- Check that onJoystickValueFromWeb is registered before webAppsServer.begin()
- Confirm the WebSocket status indicator shows "connected" in the browser
Joystick does not snap back to center
- autoReturn must be true in the constructor (it defaults to true)
- The browser handles the snap-back animation; the board only receives position events
Too many updates per second causing lag
- Increase the sensitivity parameter (e.g., change from 5 to 15)
- Add a minimum interval check in the callback before executing hardware actions
Board not reachable
- Both the board and the browser device must be on the same 2.4 GHz network
- Confirm the IP address from the Serial Monitor is correct