Arduino UNO R4 - DIYables Bluetooth App Slider

Overview

The Bluetooth Slider example provides dual slider controls accessible through the DIYables Bluetooth STEM app. Designed for Arduino UNO R4 WiFi using BLE (Bluetooth Low Energy) to control two independent values with configurable range and step. Perfect for LED brightness, motor speed, servo positioning, and any application requiring adjustable numeric input.

Note: The Arduino UNO R4 WiFi only supports BLE (Bluetooth Low Energy). It does not support Classic Bluetooth. The DIYables Bluetooth App supports both BLE and Classic Bluetooth on Android, and BLE on iOS. Since this board uses BLE, the app works on both Android and iOS.

Arduino UNO R4 WiFi Bluetooth Slider Example - Dual Slider Control via BLE Tutorial

Features

  • Dual Sliders: Two independent slider controls
  • Configurable Range: Set minimum, maximum, and step values
  • Real-Time Updates: Slider values sent instantly on change
  • PWM Ready: Map slider values directly to PWM output
  • Works on Android & iOS: BLE is supported on both platforms
  • No Pairing Required: BLE auto-connects without manual pairing
  • Low Power: BLE consumes less power than Classic Bluetooth

Arduino UNO R4 WiFi Code

Detailed Instructions

Follow these instructions step by step:

  • If this is your first time using the Arduino UNO R4 WiFi, refer to the Arduino UNO R4 WiFi getting started guide.
  • Connect the Arduino UNO R4 WiFi board to your computer using a USB cable.
  • Launch the Arduino IDE on your computer.
  • Select Arduino UNO R4 WiFi board and the appropriate 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.
Arduino UNO R4 DIYables Bluetooth library
  • You will be asked for installing some other library dependencies
  • Click Install All button to install all library dependencies.
Arduino UNO R4 DIYables Bluetooth dependency

BLE Code

  • On Arduino IDE, Go to File Examples DIYables Bluetooth ArduinoBLE_Slider example, or copy the above code and paste it to the editor of Arduino IDE
/* * DIYables Bluetooth Library - Bluetooth 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: * - Arduino UNO R4 WiFi * - Arduino Nano 33 BLE / BLE Sense * - Arduino Nano 33 IoT * - Arduino MKR WiFi 1010 * - Arduino Nano RP2040 Connect * - Any board supporting the ArduinoBLE library * * Setup: * 1. Upload the sketch to your Arduino * 2. Open Serial Monitor 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_ArduinoBLE.h> // BLE Configuration const char* DEVICE_NAME = "Arduino_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_ArduinoBLE 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 (for LED brightness control example) const int PWM_PIN_1 = 9; const int PWM_PIN_2 = 10; void setup() { Serial.begin(9600); while (!Serial); Serial.println("DIYables Bluetooth - 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!"); // 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 analogWrite(PWM_PIN_1, pwm1); analogWrite(PWM_PIN_2, pwm2); // TODO: Add your control logic here based on slider values // Examples: // - Servo control: servo.write(map(slider1, 0, 100, 0, 180)); // - Motor speed: analogWrite(MOTOR_PIN, 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(); // Optional: Update slider positions based on sensor input // Example: Send current values periodically /* static unsigned long lastUpdate = 0; if (millis() - lastUpdate >= 5000) { lastUpdate = millis(); bluetoothSlider.send(currentSlider1, currentSlider2); } */ delay(10); }
  • Click Upload button on Arduino IDE to upload code to Arduino UNO R4 WiFi
  • Open the Serial Monitor
  • Check out the result on Serial Monitor. It looks like the below:
COM6
Send
DIYables Bluetooth - 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

Note: The DIYables Bluetooth App supports both BLE and Classic Bluetooth on Android, and BLE on iOS. Since the Arduino UNO R4 WiFi uses BLE, the app works on both Android and iOS. No manual pairing is needed for BLE — just scan and connect.

  • 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 BLE devices.
DIYables Bluetooth App - Home Screen with Scan Button
  • Find and tap "Arduino_Slider" in the scan results to connect.
  • 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.

  • Drag the sliders to change values
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: 0 Slider 1: 75, Slider 2: 0 Slider 1: 100, Slider 2: 25
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  
  • Adjust the sliders and watch the values change in real time in the Serial Monitor

Creative Customization - Adapt the Code to Your Project

Configure Slider Range

// Constructor: DIYables_BluetoothSlider(min, max, step) DIYables_BluetoothSlider bluetoothSlider(0, 100, 1); // Change range at runtime bluetoothSlider.setRange(0, 255); // Change step size bluetoothSlider.setStep(5); // Coarser control // Read configuration int minVal = bluetoothSlider.getMin(); int maxVal = bluetoothSlider.getMax(); int step = bluetoothSlider.getStep();

Handle Slider 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 to PWM and control output int pwm1 = map(slider1, 0, 100, 0, 255); analogWrite(PWM_PIN_1, pwm1); });

Send Current Values to App

bluetoothSlider.onGetConfig([]() { bluetoothSlider.send(currentSlider1, currentSlider2); }); // Or send anytime: bluetoothSlider.send(50, 75); // Set both sliders

Handle Connection Events

bluetoothServer.setOnConnected([]() { Serial.println("Bluetooth connected!"); bluetoothSlider.send(currentSlider1, currentSlider2); }); bluetoothServer.setOnDisconnected([]() { Serial.println("Bluetooth disconnected!"); });

Programming Examples

LED Brightness Control

const int LED_PIN_1 = 9; const int LED_PIN_2 = 10; bluetoothSlider.onSliderValue([](int slider1, int slider2) { int brightness1 = map(slider1, 0, 100, 0, 255); int brightness2 = map(slider2, 0, 100, 0, 255); analogWrite(LED_PIN_1, brightness1); analogWrite(LED_PIN_2, brightness2); Serial.print("LED 1: "); Serial.print(brightness1); Serial.print(", LED 2: "); Serial.println(brightness2); });

Servo Control

#include <Servo.h> Servo servo1, servo2; void setup() { servo1.attach(9); servo2.attach(10); bluetoothSlider.onSliderValue([](int slider1, int slider2) { int angle1 = map(slider1, 0, 100, 0, 180); int angle2 = map(slider2, 0, 100, 0, 180); servo1.write(angle1); servo2.write(angle2); Serial.print("Servo 1: "); Serial.print(angle1); Serial.print("°, Servo 2: "); Serial.print(angle2); Serial.println("°"); }); }

Motor Speed with Direction

const int MOTOR_SPEED_PIN = 9; const int MOTOR_DIR_PIN = 8; bluetoothSlider.onSliderValue([](int slider1, int slider2) { // Slider 1: speed (0-100%) // Slider 2: direction threshold (below 50 = reverse, above 50 = forward) int speed = map(slider1, 0, 100, 0, 255); bool forward = (slider2 >= 50); analogWrite(MOTOR_SPEED_PIN, speed); digitalWrite(MOTOR_DIR_PIN, forward ? HIGH : LOW); Serial.print("Speed: "); Serial.print(slider1); Serial.print("%, Direction: "); Serial.println(forward ? "Forward" : "Reverse"); });

Advanced Programming Techniques

Slider with Dead Zone

bluetoothSlider.onSliderValue([](int slider1, int slider2) { // Add dead zone around center (45-55 = stop) if (slider1 >= 45 && slider1 <= 55) { Serial.println("Center - stopped"); analogWrite(MOTOR_PIN, 0); } else { int speed = map(slider1, 0, 100, 0, 255); analogWrite(MOTOR_PIN, speed); } });

Rate Limiting

unsigned long lastSliderAction = 0; const unsigned long SLIDER_COOLDOWN = 50; // 50ms minimum bluetoothSlider.onSliderValue([](int slider1, int slider2) { if (millis() - lastSliderAction >= SLIDER_COOLDOWN) { lastSliderAction = millis(); // Process slider value analogWrite(PWM_PIN, map(slider1, 0, 100, 0, 255)); } });

Troubleshooting

Common Issues

1. Cannot find the device in the app

  • Make sure the Arduino UNO R4 WiFi is powered on and the sketch is uploaded
  • Ensure your phone's Bluetooth is enabled
  • On Android 11 and below, also enable Location services
  • Try restarting Bluetooth on your phone

2. Slider changes not received

  • Check Bluetooth connection status in the app
  • Verify the onSliderValue callback is set up correctly
  • Check Serial Monitor for any error messages

3. PWM output not working

  • Verify the pin supports PWM (pins 3, 5, 6, 9, 10, 11 on UNO R4)
  • Check wiring connections
  • Test with a simple analogWrite sketch first

4. Slider resets to 0 on reconnect

  • Implement onGetConfig callback to send stored values on reconnect
  • Store slider values in variables that persist across connections

5. Connection drops frequently

  • Move closer to the Arduino (reduce distance)
  • Check for interference from other BLE devices
  • Ensure stable USB power supply

6. Upload fails or board not recognized

  • Install the latest Arduino UNO R4 board package via Board Manager
  • Try a different USB cable or port
  • Press the reset button on the board before uploading

Project Ideas

Lighting Control

  • Dual LED brightness controller
  • RGB LED color mixer (use two sliders for hue/saturation)
  • LED strip brightness and color temperature
  • Stage lighting dimmer

Motor Control

  • DC motor speed controller
  • Dual servo positioning
  • Pan-tilt camera mount
  • Robot wheel speed

Audio

  • Volume control
  • Tone frequency and duration
  • Equalizer bands

Next Steps

After mastering the Bluetooth Slider example, try:

  1. Bluetooth Joystick - For 2D directional control
  2. Bluetooth Rotator - For angular/rotational control
  3. Bluetooth Temperature - For temperature gauge display
  4. Multiple Bluetooth Apps - Combining slider with other apps

Support

For additional help:

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!