Arduino Nano ESP32 - Web Apps Web Slider
Overview
This tutorial covers the DIYablesWebSliderPage class from the DIYables ESP32 WebApps Library. The page presents two independent sliders in the browser, each with a range of 0 to 255. The Arduino Nano ESP32 receives slider values over WebSocket through a callback. The values are directly usable with analogWrite() for PWM-based control of LEDs, motors, or any 8-bit output.

What This Tutorial Covers
- Receiving slider values in a sketch callback
- Applying slider 1 and slider 2 values to analogWrite() outputs
- Supplying the current slider positions to newly connected browsers
- Setting default initial slider positions
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 WebSlider 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 shows a card for the slider application:

- Select the Web Slider card to open the slider control page:

- The page is also directly accessible at http://192.168.0.2/web-slider.
- Move the sliders and observe the values printed in the Serial Monitor.
Default Slider Values
Track the current slider positions in state variables and set defaults before registering callbacks:
Callbacks
Receiving Slider Changes
Called each time the user moves either slider:
Supplying Values to the Browser
Called when a browser connects and requests the current positions:
Typical Use Cases
LED brightness: Connect slider 1 to a PWM-capable pin with an LED. The 0–255 range maps directly to 0–100% brightness via analogWrite().
Motor speed: Send slider values to a motor driver's speed control input. Scale to the required range inside the callback.
Dual channel control: Slider 1 and slider 2 are fully independent. Use one for speed and one for direction, or one per motor in a dual-drive system.
Troubleshooting
Slider values not received
- Confirm onSliderValueFromWeb is registered before webAppsServer.begin()
- Check the Serial Monitor for incoming values
- Verify the browser shows the WebSocket connection as active
Browser sliders reset on reconnect
- Implement onSliderValueToWeb and call sendToWebSlider() inside it so the browser restores the last positions on connect
No PWM output
- Confirm the pin supports analogWrite() on Arduino Nano ESP32
- Check that pinMode(pin, OUTPUT) is set before analogWrite()