ESP32 - DIYables Bluetooth App Slider

Overview

The Bluetooth Slider example provides two independent slider controls accessible through the DIYables Bluetooth STEM app. Designed for ESP32 boards with support for both BLE (Bluetooth Low Energy) and Classic Bluetooth connections. Each slider offers values from 0-100, making them perfect for PWM control, brightness adjustment, motor speed control, and any application requiring analog-like control values.

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.
ESP32 Bluetooth Slider Example - Dual Slider Control Interface Tutorial

Features

  • Dual Sliders: Two independent slider controls (0-100 range each)
  • Real-time Values: Instant value updates via Bluetooth communication
  • PWM Compatible: Values (0-100) easily mapped to analogWrite() functions
  • Visual Feedback: Real-time value display for each slider in the app
  • 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
  • Configurable Range & Step: Customize slider range and step size at runtime

Hardware Used In This Tutorial

1×ESP-WROOM-32 Dev Module
1×Alternatively, ESP32 Uno-form board
1×Alternatively, ESP32 S3 Uno-form board
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×Breadboard
1×Jumper Wires
1×Recommended: Screw Terminal Expansion Board for ESP32
1×Recommended: Breakout Expansion Board for ESP32
1×Recommended: Power Splitter for ESP32

Or you can buy the following kits:

1×DIYables ESP32 Starter Kit (ESP32 included)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links in this section are Amazon affiliate links, meaning we may earn a commission at no additional cost to you if you make a purchase through them. Additionally, some links direct you to products from our own brand, DIYables .

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.
ESP32 DIYables Bluetooth library
  • You will be asked for installing some other library dependencies
  • Click Install All button to install all library dependencies.
ESP32 DIYables Bluetooth dependency

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_Slider example, or copy the above code and paste it to the editor of Arduino IDE
/* * DIYables Bluetooth Library - ESP32 Classic Bluetooth Slider Example * Works with DIYables Bluetooth STEM app on Android * Note: Classic Bluetooth is NOT supported on iOS. Use BLE examples for iOS support. * * This example demonstrates the Bluetooth Slider feature: * - Control values using sliders (0-100) * - Support for dual sliders * - Configurable range and step * * Compatible Boards: * - ESP32 (all variants with Classic Bluetooth) * - ESP32-WROOM-32 * - ESP32-DevKitC * - ESP32-WROVER * * Note: Select "Huge APP (3MB No OTA/1MB SPIFFS)" partition scheme * in Arduino IDE: Tools > Partition Scheme * * Setup: * 1. Upload the sketch to your ESP32 * 2. Open Serial Monitor (115200 baud) to see connection status * 3. Use DIYables Bluetooth App to connect and control sliders * * Tutorial: https://diyables.io/bluetooth-app * Author: DIYables */ #include <DIYables_BluetoothServer.h> #include <DIYables_BluetoothSlider.h> #include <platforms/DIYables_Esp32Bluetooth.h> // Create Bluetooth instances DIYables_Esp32Bluetooth bluetooth("ESP32_Slider"); DIYables_BluetoothServer bluetoothServer(bluetooth); // Create Slider app instance (min=0, max=100, step=1) DIYables_BluetoothSlider bluetoothSlider(0, 100, 1); // Variables to store current slider values int currentSlider1 = 0; int currentSlider2 = 0; // PWM output pins (for LED brightness control example) const int PWM_PIN_1 = 16; const int PWM_PIN_2 = 17; // ESP32 LEDC PWM channels const int PWM_CHANNEL_1 = 0; const int PWM_CHANNEL_2 = 1; void setup() { Serial.begin(115200); delay(1000); Serial.println("DIYables Bluetooth - ESP32 Slider Example"); // Initialize PWM using ESP32 LEDC ledcSetup(PWM_CHANNEL_1, 5000, 8); // 5kHz, 8-bit resolution ledcSetup(PWM_CHANNEL_2, 5000, 8); ledcAttachPin(PWM_PIN_1, PWM_CHANNEL_1); ledcAttachPin(PWM_PIN_2, PWM_CHANNEL_2); // Initialize Bluetooth server with platform-specific implementation bluetoothServer.begin(); // Add slider app to server bluetoothServer.addApp(&bluetoothSlider); // Set up connection event callbacks bluetoothServer.setOnConnected([]() { Serial.println("Bluetooth connected!"); // Send initial slider positions bluetoothSlider.send(currentSlider1, currentSlider2); }); bluetoothServer.setOnDisconnected([]() { Serial.println("Bluetooth disconnected!"); }); // Set up slider callback for value changes bluetoothSlider.onSliderValue([](int slider1, int slider2) { // Store the received values currentSlider1 = slider1; currentSlider2 = slider2; // Print slider values (0-100) Serial.print("Slider 1: "); Serial.print(slider1); Serial.print(", Slider 2: "); Serial.println(slider2); // Map slider values (0-100) to PWM range (0-255) int pwm1 = map(slider1, 0, 100, 0, 255); int pwm2 = map(slider2, 0, 100, 0, 255); // Control LED brightness using ESP32 LEDC ledcWrite(PWM_CHANNEL_1, pwm1); ledcWrite(PWM_CHANNEL_2, pwm2); // TODO: Add your control logic here based on slider values // Examples: // - Servo control: myServo.write(map(slider1, 0, 100, 0, 180)); // - Motor speed: ledcWrite(MOTOR_CHANNEL, pwm1); // - Volume control: setVolume(slider1); // - Brightness control: setBrightness(slider2); }); // Optional: Handle requests for current slider values (when app loads) bluetoothSlider.onGetConfig([]() { // Send the stored slider values back to the app bluetoothSlider.send(currentSlider1, currentSlider2); Serial.print("App requested values - Sent: Slider1="); Serial.print(currentSlider1); Serial.print(", Slider2="); Serial.println(currentSlider2); }); // You can change slider configuration at runtime: // bluetoothSlider.setRange(0, 255); // Change range to 0-255 // bluetoothSlider.setStep(5); // Change step to 5 (coarser control) Serial.println("Waiting for Bluetooth connection..."); } void loop() { // Handle Bluetooth server communications bluetoothServer.loop(); delay(10); }
  • 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:
COM6
Send
DIYables Bluetooth - ESP32 Slider Example Waiting for Bluetooth connection...
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

ESP32 BLE Code (works with app on both Android and iOS)

  • On Arduino IDE, Go to File Examples DIYables Bluetooth Esp32BLE_Slider example, or copy the above code and paste it to the editor of Arduino IDE
/* * DIYables Bluetooth Library - ESP32 BLE Slider Example * Works with DIYables Bluetooth STEM app on Android and iOS * * This example demonstrates the Bluetooth Slider feature: * - Control values using sliders (0-100) * - Support for dual sliders * - Configurable range and step * * Compatible Boards: * - ESP32-WROOM-32 * - ESP32-DevKitC * - ESP32-WROVER * - ESP32-S3 * - ESP32-C3 * - Any ESP32 board supporting BLE * * Note: Select "Huge APP (3MB No OTA/1MB SPIFFS)" partition scheme * in Arduino IDE: Tools > Partition Scheme * * Setup: * 1. Upload the sketch to your ESP32 * 2. Open Serial Monitor (115200 baud) to see connection status * 3. Use DIYables Bluetooth App to connect and control sliders * * Tutorial: https://diyables.io/bluetooth-app * Author: DIYables */ #include <DIYables_BluetoothServer.h> #include <DIYables_BluetoothSlider.h> #include <platforms/DIYables_Esp32BLE.h> // BLE Configuration const char* DEVICE_NAME = "ESP32BLE_Slider"; const char* SERVICE_UUID = "19B10000-E8F2-537E-4F6C-D104768A1214"; const char* TX_UUID = "19B10001-E8F2-537E-4F6C-D104768A1214"; const char* RX_UUID = "19B10002-E8F2-537E-4F6C-D104768A1214"; // Create Bluetooth instances DIYables_Esp32BLE bluetooth(DEVICE_NAME, SERVICE_UUID, TX_UUID, RX_UUID); DIYables_BluetoothServer bluetoothServer(bluetooth); // Create Slider app instance (min=0, max=100, step=1) DIYables_BluetoothSlider bluetoothSlider(0, 100, 1); // Variables to store current slider values int currentSlider1 = 0; int currentSlider2 = 0; // PWM output pins const int PWM_PIN_1 = 16; const int PWM_PIN_2 = 17; void setup() { Serial.begin(115200); delay(1000); Serial.println("DIYables Bluetooth - ESP32 BLE Slider Example"); // Initialize PWM pins pinMode(PWM_PIN_1, OUTPUT); pinMode(PWM_PIN_2, OUTPUT); // Initialize Bluetooth server with platform-specific implementation bluetoothServer.begin(); // Add slider app to server bluetoothServer.addApp(&bluetoothSlider); // Set up connection event callbacks bluetoothServer.setOnConnected([]() { Serial.println("Bluetooth connected!"); bluetoothSlider.send(currentSlider1, currentSlider2); }); bluetoothServer.setOnDisconnected([]() { Serial.println("Bluetooth disconnected!"); }); // Set up slider callback for value changes bluetoothSlider.onSliderValue([](int slider1, int slider2) { currentSlider1 = slider1; currentSlider2 = slider2; Serial.print("Slider 1: "); Serial.print(slider1); Serial.print(", Slider 2: "); Serial.println(slider2); // Map slider values (0-100) to PWM range (0-255) int pwm1 = map(slider1, 0, 100, 0, 255); int pwm2 = map(slider2, 0, 100, 0, 255); analogWrite(PWM_PIN_1, pwm1); analogWrite(PWM_PIN_2, pwm2); // TODO: Add your control logic here }); bluetoothSlider.onGetConfig([]() { bluetoothSlider.send(currentSlider1, currentSlider2); Serial.print("App requested values - Sent: Slider1="); Serial.print(currentSlider1); Serial.print(", Slider2="); Serial.println(currentSlider2); }); Serial.println("Waiting for Bluetooth connection..."); } void loop() { bluetoothServer.loop(); delay(10); }
  • 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:
COM6
Send
DIYables Bluetooth - ESP32 BLE Slider Example Waiting for Bluetooth connection...
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Mobile App

  • Install the DIYables Bluetooth App on your smartphone: Android | iOS
  • 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_Slider" 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.
DIYables Bluetooth App - Home Screen with Scan Button
  • Find and tap your device in the scan results to connect:
    • For Classic Bluetooth: tap "ESP32_Slider"
    • For BLE: tap "ESP32BLE_Slider"
  • Once connected, the app automatically goes back to the home screen. Select the Slider app from the app menu.
DIYables Bluetooth App - Home Screen with Slider App

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 two sliders to control PWM values (0-100)
DIYables Bluetooth App - Slider Screen

Now look back at the Serial Monitor on Arduino IDE. You will see:

COM6
Send
Bluetooth connected! Slider 1: 50, Slider 2: 30 Slider 1: 75, Slider 2: 30 Slider 1: 75, Slider 2: 60 Slider 1: 100, Slider 2: 85
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  
  • Move the sliders in the app and watch the real-time feedback in the Serial Monitor

Creative Customization - Adapt the Code to Your Project

Set Default Slider Values

Configure initial slider positions:

// Current slider values (0-100) int currentSlider1 = 25; // Default 25% int currentSlider2 = 50; // Default 50%

Customize Slider Range and Step

// Create Slider app instance with custom range (min=0, max=255, step=5) DIYables_BluetoothSlider bluetoothSlider(0, 255, 5); // Or change at runtime: bluetoothSlider.setRange(0, 255); // Change range to 0-255 bluetoothSlider.setStep(5); // Change step to 5 (coarser control) // Read current configuration: int currentMin = bluetoothSlider.getMin(); // Get current minimum value int currentMax = bluetoothSlider.getMax(); // Get current maximum value int currentStep = bluetoothSlider.getStep(); // Get current step value

Handle Configuration Request from App

When the app connects and opens the Slider screen, it requests the slider configuration from ESP32. You can use the onGetConfig() callback to send the current slider values to the app at that moment:

bluetoothSlider.onGetConfig([]() { // This is called when the app requests slider configuration // Send current slider values so the app displays them correctly bluetoothSlider.send(currentSlider1, currentSlider2); Serial.println("App requested config - sent current values"); });

Send Values to App

You can send slider values from ESP32 to the app (e.g., to update the app's slider positions):

// Send both slider values to the app bluetoothSlider.send(currentSlider1, currentSlider2); // Send a single value (applied to both sliders) bluetoothSlider.send(50);

Handle Connection Events

You can detect when the app connects or disconnects from the ESP32:

// Called when the app connects to ESP32 bluetoothServer.setOnConnected([]() { Serial.println("Bluetooth connected!"); // Send current slider values to the app bluetoothSlider.send(currentSlider1, currentSlider2); }); // Called when the app disconnects from ESP32 bluetoothServer.setOnDisconnected([]() { Serial.println("Bluetooth disconnected!"); // Optional: stop motors, reset outputs, etc. }); // Check connection status anywhere in your code if (bluetoothServer.isConnected()) { // Do something only when connected }

How to Use the Sliders

App Interface Controls

The slider interface in the DIYables Bluetooth App provides:

  • Slider 1: First control slider with value display
  • Slider 2: Second control slider with value display
  • Value Display: Real-time numeric values for both sliders

Value Ranges

Each slider provides:

  • Default Range: 0 to 100
  • Configurable: Range and step can be customized in code
  • PWM Mapping: Easy mapping to 0-255 for analogWrite()

Programming Examples

Basic Slider Handler

void setup() { // Set up slider callback for value changes bluetoothSlider.onSliderValue([](int slider1, int slider2) { // Store the received values currentSlider1 = slider1; currentSlider2 = slider2; // Print slider values Serial.println("Slider 1: " + String(slider1) + ", Slider 2: " + String(slider2)); // Add your control logic here }); }

LED Brightness Control (BLE Example)

// PWM output pins const int PWM_PIN_1 = 16; const int PWM_PIN_2 = 17; void setup() { // Configure PWM pins as outputs pinMode(PWM_PIN_1, OUTPUT); pinMode(PWM_PIN_2, OUTPUT); bluetoothSlider.onSliderValue([](int slider1, int slider2) { currentSlider1 = slider1; currentSlider2 = slider2; // Map slider values (0-100) to PWM range (0-255) int pwm1 = map(slider1, 0, 100, 0, 255); int pwm2 = map(slider2, 0, 100, 0, 255); // Control LED brightness analogWrite(PWM_PIN_1, pwm1); analogWrite(PWM_PIN_2, pwm2); Serial.println("LED1 Brightness: " + String(pwm1) + ", LED2 Brightness: " + String(pwm2)); }); }

LED Brightness Control (Classic Bluetooth with ESP32 LEDC)

// PWM output pins const int PWM_PIN_1 = 16; const int PWM_PIN_2 = 17; // ESP32 LEDC PWM channels const int PWM_CHANNEL_1 = 0; const int PWM_CHANNEL_2 = 1; void setup() { // Initialize PWM using ESP32 LEDC ledcSetup(PWM_CHANNEL_1, 5000, 8); // 5kHz, 8-bit resolution ledcSetup(PWM_CHANNEL_2, 5000, 8); ledcAttachPin(PWM_PIN_1, PWM_CHANNEL_1); ledcAttachPin(PWM_PIN_2, PWM_CHANNEL_2); bluetoothSlider.onSliderValue([](int slider1, int slider2) { currentSlider1 = slider1; currentSlider2 = slider2; // Map slider values (0-100) to PWM range (0-255) int pwm1 = map(slider1, 0, 100, 0, 255); int pwm2 = map(slider2, 0, 100, 0, 255); // Control LED brightness using ESP32 LEDC ledcWrite(PWM_CHANNEL_1, pwm1); ledcWrite(PWM_CHANNEL_2, pwm2); Serial.println("LED1 Brightness: " + String(pwm1) + ", LED2 Brightness: " + String(pwm2)); }); }

Servo Position Control

#include <ESP32Servo.h> Servo servo1, servo2; void setup() { // Attach servos to pins servo1.attach(16); servo2.attach(17); bluetoothSlider.onSliderValue([](int slider1, int slider2) { currentSlider1 = slider1; currentSlider2 = slider2; // Map slider values (0-100) to servo angles (0-180°) int angle1 = map(slider1, 0, 100, 0, 180); int angle2 = map(slider2, 0, 100, 0, 180); // Move servos to calculated positions servo1.write(angle1); servo2.write(angle2); Serial.println("Servo1: " + String(angle1) + "°, Servo2: " + String(angle2) + "°"); }); }

Motor Speed Control

// Motor driver pins const int MOTOR1_PWM = 16; // Motor 1 speed control const int MOTOR1_DIR1 = 18; // Motor 1 direction pin 1 const int MOTOR1_DIR2 = 19; // Motor 1 direction pin 2 const int MOTOR2_PWM = 17; // Motor 2 speed control const int MOTOR2_DIR1 = 21; // Motor 2 direction pin 1 const int MOTOR2_DIR2 = 22; // Motor 2 direction pin 2 void setup() { // Configure motor pins pinMode(MOTOR1_PWM, OUTPUT); pinMode(MOTOR1_DIR1, OUTPUT); pinMode(MOTOR1_DIR2, OUTPUT); pinMode(MOTOR2_PWM, OUTPUT); pinMode(MOTOR2_DIR1, OUTPUT); pinMode(MOTOR2_DIR2, OUTPUT); // Set initial motor directions (forward) digitalWrite(MOTOR1_DIR1, HIGH); digitalWrite(MOTOR1_DIR2, LOW); digitalWrite(MOTOR2_DIR1, HIGH); digitalWrite(MOTOR2_DIR2, LOW); bluetoothSlider.onSliderValue([](int slider1, int slider2) { currentSlider1 = slider1; currentSlider2 = slider2; // Map slider values (0-100) to PWM range (0-255) int pwm1 = map(slider1, 0, 100, 0, 255); int pwm2 = map(slider2, 0, 100, 0, 255); // Control motor speeds analogWrite(MOTOR1_PWM, pwm1); analogWrite(MOTOR2_PWM, pwm2); Serial.println("Motor1: " + String(slider1) + "%, " + "Motor2: " + String(slider2) + "%"); }); }

RGB LED Color Control

// RGB LED pins const int RED_PIN = 16; const int GREEN_PIN = 17; const int BLUE_PIN = 18; void setup() { pinMode(RED_PIN, OUTPUT); pinMode(GREEN_PIN, OUTPUT); pinMode(BLUE_PIN, OUTPUT); bluetoothSlider.onSliderValue([](int slider1, int slider2) { currentSlider1 = slider1; currentSlider2 = slider2; // Use sliders to control RGB components // Slider 1 controls red intensity // Slider 2 controls blue intensity // Green is calculated based on both sliders int redValue = map(slider1, 0, 100, 0, 255); int blueValue = map(slider2, 0, 100, 0, 255); int greenValue = (redValue + blueValue) / 2; analogWrite(RED_PIN, redValue); analogWrite(GREEN_PIN, greenValue); analogWrite(BLUE_PIN, blueValue); Serial.println("RGB - R:" + String(redValue) + " G:" + String(greenValue) + " B:" + String(blueValue)); }); }

Advanced Programming Techniques

Value Smoothing

class SliderSmoother { private: int currentValue = 0; int targetValue = 0; unsigned long lastUpdate = 0; const int SMOOTH_RATE = 2; // Change per update cycle public: void setTarget(int target) { targetValue = target; } int getCurrentValue() { return currentValue; } bool update() { if (millis() - lastUpdate > 10) { // Update every 10ms bool changed = false; if (currentValue < targetValue) { currentValue = min(currentValue + SMOOTH_RATE, targetValue); changed = true; } else if (currentValue > targetValue) { currentValue = max(currentValue - SMOOTH_RATE, targetValue); changed = true; } lastUpdate = millis(); return changed; } return false; } }; SliderSmoother smoother1, smoother2; void setup() { bluetoothSlider.onSliderValue([](int slider1, int slider2) { // Set target values for smooth transition smoother1.setTarget(slider1); smoother2.setTarget(slider2); }); } void loop() { bluetoothServer.loop(); // Update smoothed values bool changed1 = smoother1.update(); bool changed2 = smoother2.update(); if (changed1 || changed2) { // Map smoothed values (0-100) to PWM (0-255) and apply analogWrite(16, map(smoother1.getCurrentValue(), 0, 100, 0, 255)); analogWrite(17, map(smoother2.getCurrentValue(), 0, 100, 0, 255)); } }

Threshold-Based Control

void setupThresholdControl() { bluetoothSlider.onSliderValue([](int slider1, int slider2) { currentSlider1 = slider1; currentSlider2 = slider2; // Threshold-based control for discrete outputs const int LOW_THRESHOLD = 33; const int MEDIUM_THRESHOLD = 66; // Control digital outputs based on slider 1 thresholds if (slider1 < LOW_THRESHOLD) { // Low level: Turn off all outputs digitalWrite(18, LOW); digitalWrite(19, LOW); digitalWrite(21, LOW); } else if (slider1 < MEDIUM_THRESHOLD) { // Medium level: Turn on first output digitalWrite(18, HIGH); digitalWrite(19, LOW); digitalWrite(21, LOW); } else { // High level: Turn on all outputs digitalWrite(18, HIGH); digitalWrite(19, HIGH); digitalWrite(21, HIGH); } // Use slider 2 for analog PWM control analogWrite(16, map(slider2, 0, 100, 0, 255)); }); }

Preset Value System

// Predefined preset values (0-100 range) const int PRESETS[][2] = { {0, 0}, // Preset 0: Both off {25, 50}, // Preset 1: Low/Medium {50, 50}, // Preset 2: Both medium {100, 50}, // Preset 3: High/Medium {100, 100} // Preset 4: Both maximum }; void applyPreset(int presetNumber) { if (presetNumber >= 0 && presetNumber < 5) { currentSlider1 = PRESETS[presetNumber][0]; currentSlider2 = PRESETS[presetNumber][1]; // Update hardware analogWrite(16, map(currentSlider1, 0, 100, 0, 255)); analogWrite(17, map(currentSlider2, 0, 100, 0, 255)); // Send updated values to the app bluetoothSlider.send(currentSlider1, currentSlider2); Serial.println("Applied preset " + String(presetNumber) + ": " + String(currentSlider1) + ", " + String(currentSlider2)); } }

Hardware Integration Examples

LED Strip Control

// For WS2812B or similar addressable LED strips // (requires additional libraries like FastLED or Adafruit NeoPixel) const int LED_STRIP_PIN = 16; const int NUM_LEDS = 30; void setupLEDStrip() { // Initialize LED strip (depends on library used) bluetoothSlider.onSliderValue([](int slider1, int slider2) { currentSlider1 = slider1; currentSlider2 = slider2; // Slider 1 controls brightness (0-100 mapped to 0-255) // Slider 2 controls color temperature or hue (0-100 mapped to 0-255) uint8_t brightness = map(slider1, 0, 100, 0, 255); uint8_t hue = map(slider2, 0, 100, 0, 255); // Update LED strip (example with conceptual functions) // strip.setBrightness(brightness); // strip.fill(CHSV(hue, 255, 255)); // strip.show(); Serial.println("LED Strip - Brightness: " + String(brightness) + ", Hue: " + String(hue)); }); }

Fan Speed Control

const int FAN1_PIN = 16; const int FAN2_PIN = 17; void setupFanControl() { pinMode(FAN1_PIN, OUTPUT); pinMode(FAN2_PIN, OUTPUT); bluetoothSlider.onSliderValue([](int slider1, int slider2) { currentSlider1 = slider1; currentSlider2 = slider2; // Map slider values (0-100) to PWM (0-255) int pwm1 = map(slider1, 0, 100, 0, 255); int pwm2 = map(slider2, 0, 100, 0, 255); // Control fan speeds with minimum threshold for startup int fan1Speed = (pwm1 > 50) ? map(pwm1, 50, 255, 100, 255) : 0; int fan2Speed = (pwm2 > 50) ? map(pwm2, 50, 255, 100, 255) : 0; analogWrite(FAN1_PIN, fan1Speed); analogWrite(FAN2_PIN, fan2Speed); Serial.println("Fan1: " + String(slider1) + "%, " + "Fan2: " + String(slider2) + "%"); }); }

BLE vs Classic Bluetooth - Which to Choose?

FeatureBLE (Esp32BLE_Slider)Classic Bluetooth (Esp32Bluetooth_Slider)
iOS Support? Yes? No
Android Support? Yes? Yes
Power ConsumptionLowHigher
Range~30-100m~10-100m
Data RateLowerHigher
Pairing RequiredNo (auto-connect)Yes (manual pairing)
Best ForBattery-powered, cross-platformHigh 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. Sliders not responding

  • Check Bluetooth connection status in the app
  • Verify connection in Serial Monitor
  • Try disconnecting and reconnecting

3. Values not reaching full range

  • Check slider range configuration: DIYables_BluetoothSlider(min, max, step)
  • Verify value mapping in callback function
  • Check Serial Monitor for actual values received

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. PWM output not working

  • Verify pins support PWM on your ESP32 variant
  • For ESP32: Use ledcSetup/ledcAttachPin/ledcWrite for hardware PWM
  • Check hardware connections and load requirements

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:

void debugSliderValues(int slider1, int slider2) { Serial.println("=== Slider Debug ==="); Serial.println("Slider 1: " + String(slider1) + "%"); Serial.println("Slider 2: " + String(slider2) + "%"); Serial.println("PWM 1: " + String(map(slider1, 0, 100, 0, 255))); Serial.println("PWM 2: " + String(map(slider2, 0, 100, 0, 255))); Serial.println("==================="); }

Project Ideas

Lighting Control Projects

  • Room lighting brightness control via Bluetooth
  • RGB color mixing interface
  • LED strip animation speed control
  • Wireless stage lighting control

Motor Control Projects

  • Bluetooth-controlled robot speed
  • Wireless fan speed regulation
  • Pump flow control
  • Conveyor belt speed

Audio Projects

  • Wireless volume control
  • Tone/equalizer control
  • Sound effect intensity

Home Automation

  • Wireless climate control (heating/cooling intensity)
  • Bluetooth window blind position control
  • Irrigation system flow control

Integration with Other Bluetooth Apps

Combine with Bluetooth Joystick

Use sliders for speed limits and joystick for direction:

// Global speed limit from sliders int maxSpeed = 100; // In Bluetooth Slider callback bluetoothSlider.onSliderValue([](int slider1, int slider2) { maxSpeed = slider1; // Use slider 1 as global speed limit }); // In Bluetooth Joystick callback bluetoothJoystick.onJoystickValue([](int x, int y) { // Scale joystick values by slider-controlled speed limit int scaledX = map(x, -100, 100, -maxSpeed, maxSpeed); int scaledY = map(y, -100, 100, -maxSpeed, maxSpeed); controlRobot(scaledX, scaledY); });

Combine with Bluetooth Digital Pins

Use sliders to control PWM and digital pins for on/off:

bluetoothSlider.onSliderValue([](int slider1, int slider2) { // Only apply PWM if corresponding digital pins are ON if (digitalRead(18) == HIGH) { analogWrite(16, map(slider1, 0, 100, 0, 255)); } else { analogWrite(16, 0); } if (digitalRead(19) == HIGH) { analogWrite(17, map(slider2, 0, 100, 0, 255)); } else { analogWrite(17, 0); } });

Next Steps

After mastering the Bluetooth Slider example, try:

  1. Bluetooth Joystick - For 2D directional control
  2. Bluetooth Digital Pins - For discrete on/off control
  3. Bluetooth Monitor - For debugging slider values
  4. Multiple Bluetooth Apps - Combining sliders with other controls

Support

For additional help:

※ OUR MESSAGES