Arduino UNO R4 WiFi Bluetooth Rotator Voorbeeld - Hoekbesturing via BLE Tutorial

Overzicht

Het Bluetooth Rotator voorbeeld biedt hoekpositiebesturing via de DIYables Bluetooth STEM app. Ontworpen voor Arduino UNO R4 WiFi met gebruik van BLE (Bluetooth Low Energy) om rotatiehoeken en servomotoren draadloos te besturen vanaf uw smartphone. Ondersteunt beperkt-bereik en continue rotatiemodi. Perfect voor servobesturing, robotica, pan-tilt mechanismen en hoekpositionering.

Opmerking: De Arduino UNO R4 WiFi ondersteunt alleen BLE (Bluetooth Low Energy). Het ondersteunt geen Klassieke Bluetooth. De DIYables Bluetooth App ondersteunt zowel BLE als Klassieke Bluetooth op Android, en BLE op iOS. Omdat dit board BLE gebruikt, werkt de app op zowel Android als iOS.

Arduino UNO R4 WiFi Bluetooth Rotator Voorbeeld - Hoekbesturing via BLE Tutorial

Functies

  • Beperkte Modus: Stel min/max hoekbereik in (bijv. 0° tot 180°)
  • Continue Modus: Volledige 360° continue rotatie
  • Real-Time Hoek: Ontvang hoekupdates terwijl gebruiker roteert
  • Servo Integratie: Directe servomotorbesturing
  • Initiële Hoek Synchronisatie: Verstuur huidige positie bij verbinding
  • Werkt op Android & iOS: BLE wordt ondersteund op beide platformen
  • Geen Koppelen Vereist: BLE maakt automatisch verbinding zonder handmatige koppeling

Arduino UNO R4 WiFi Code

Snelle Stappen

Volg deze instructies stap voor stap:

  • Als dit uw eerste keer is met de Arduino UNO R4 WiFi, raadpleeg dan de Arduino UNO R4 WiFi aan de slag gids.
  • Verbind het Arduino UNO R4 WiFi board met uw computer via een USB-kabel.
  • Start de Arduino IDE op uw computer.
  • Selecteer Arduino UNO R4 WiFi board en de juiste COM-poort.
  • Navigeer naar het Libraries pictogram in de linker balk van de Arduino IDE.
  • Zoek naar "DIYables Bluetooth", vind vervolgens de DIYables Bluetooth bibliotheek door DIYables
  • Klik op de Install knop om de bibliotheek te installeren.
Arduino UNO R4 DIYables Bluetooth bibliotheek
  • U wordt gevraagd om enkele andere bibliotheekafhankelijkheden te installeren
  • Klik op de Install All knop om alle bibliotheekafhankelijkheden te installeren.
Arduino UNO R4 DIYables Bluetooth afhankelijkheid

BLE Code

  • Ga in Arduino IDE naar File Examples DIYables Bluetooth ArduinoBLE_Rotator voorbeeld, of kopieer de bovenstaande code en plak deze in de editor van Arduino IDE
/* * DIYables Bluetooth Library - Bluetooth Rotator Example * Works with DIYables Bluetooth STEM app on Android and iOS * * This example demonstrates the Bluetooth Rotator feature: * - Rotatable disc/knob control (0-360 degrees) * - Continuous or limited angle range * - Perfect for servo control, compass display, volume knobs * * 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 * * Optional: Servo motor for visual feedback * * Setup: * 1. Upload the sketch to your Arduino * 2. Open Serial Monitor to see connection status * 3. Use DIYables Bluetooth App to connect and rotate the knob * * Tutorial: https://diyables.io/bluetooth-app * Author: DIYables */ #include <DIYables_BluetoothServer.h> #include <DIYables_BluetoothRotator.h> #include <platforms/DIYables_ArduinoBLE.h> // BLE Configuration const char* DEVICE_NAME = "Arduino_Rotator"; 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 Rotator app instance // Option 1: Continuous mode (0-360, wraps around) // DIYables_BluetoothRotator bluetoothRotator(ROTATOR_MODE_CONTINUOUS); // Option 2: Limited mode (constrained angle range) DIYables_BluetoothRotator bluetoothRotator(ROTATOR_MODE_LIMITED, 0, 180); // Variables to store current angle float currentAngle = 0.0; // Optional: Servo control (uncomment if using Servo library) // #include <Servo.h> // Servo myServo; // const int SERVO_PIN = 9; void setup() { Serial.begin(9600); while (!Serial); Serial.println("DIYables Bluetooth - Rotator Example"); // Optional: Initialize servo // myServo.attach(SERVO_PIN); // myServo.write(0); bluetoothServer.begin(); bluetoothServer.addApp(&bluetoothRotator); bluetoothServer.setOnConnected([]() { Serial.println("Bluetooth connected!"); bluetoothRotator.send(currentAngle); }); bluetoothServer.setOnDisconnected([]() { Serial.println("Bluetooth disconnected!"); }); bluetoothRotator.onRotatorAngle([](float angle) { currentAngle = angle; Serial.print("Rotator angle: "); Serial.print(angle); Serial.println("°"); // TODO: Add your control logic here based on angle // Examples: // - Servo control: servo.write(map(angle, 0, 360, 0, 180)); // - Stepper motor: stepper.moveTo(angleToSteps(angle)); // - LED ring: setLEDPosition(angle); // - Volume control: setVolume(map(angle, 0, 360, 0, 100)); }); Serial.println("Waiting for Bluetooth connection..."); } void loop() { bluetoothServer.loop(); delay(10); }
  • Klik op de Upload knop in Arduino IDE om code te uploaden naar Arduino UNO R4 WiFi
  • Open de Serial Monitor
  • Bekijk het resultaat in Serial Monitor. Het ziet er als volgt uit:
COM6
Send
DIYables Bluetooth - Rotator Example Waiting for Bluetooth connection...
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Mobiele App

  • Installeer de DIYables Bluetooth App op uw smartphone: Android | iOS

Opmerking: De DIYables Bluetooth App ondersteunt zowel BLE als Klassieke Bluetooth op Android, en BLE op iOS. Omdat de Arduino UNO R4 WiFi BLE gebruikt, werkt de app op zowel Android als iOS. Handmatige koppeling is niet nodig voor BLE — scan gewoon en maak verbinding.

  • Open de DIYables Bluetooth App
  • Bij het eerste gebruik vraagt de app om toestemmingen. Verleen de volgende:
    • Nearby Devices toestemming (Android 12+) / Bluetooth toestemming (iOS) - vereist om Bluetooth-apparaten te scannen en verbinden
    • Location toestemming (alleen Android 11 en lager) - vereist door oudere Android versies om BLE-apparaten te scannen
  • Zorg ervoor dat Bluetooth is ingeschakeld op uw telefoon
  • Tik op het beginscherm op de Connect knop. De app zal scannen naar BLE-apparaten.
DIYables Bluetooth App - Beginscherm met Scan Knop
  • Zoek en tik op "Arduino_Rotator" in de scanresultaten om verbinding te maken.
  • Eenmaal verbonden gaat de app automatisch terug naar het beginscherm. Selecteer de Rotator app uit het app menu.
DIYables Bluetooth App - Beginscherm met Rotator App

Opmerking: U kunt op het instellingenpictogram op het beginscherm tikken om apps op het beginscherm te verbergen/tonen. Voor meer details, zie de DIYables Bluetooth App Gebruikershandleiding.

  • U ziet een draaiknop die 0° tot 180° toont
  • Draai de knop om hoekwaarden naar de Arduino te sturen
DIYables Bluetooth App - Rotator Scherm

Kijk nu terug naar de Serial Monitor in Arduino IDE. U ziet:

COM6
Send
Bluetooth connected! Angle changed: 45.00° Angle changed: 90.00° Angle changed: 135.00°
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Creatieve Aanpassing - Pas de Code aan voor Uw Project

Rotatiemodi

// Beperkte modus: specificeer min en max hoek DIYables_BluetoothRotator bluetoothRotator(bluetoothServer, ROTATOR_MODE_LIMITED, 0, 180); // Continue modus: volledige 360° rotatie DIYables_BluetoothRotator bluetoothRotator(bluetoothServer, ROTATOR_MODE_CONTINUOUS);

Behandel Hoekveranderingen

bluetoothRotator.onRotatorAngle([](float angle) { Serial.print("Angle: "); Serial.println(angle); // Bestuur een servomotor myServo.write((int)angle); });

Verstuur Huidige Hoek

// Verstuur huidige hoek naar de app (bijv. bij verbinding) bluetoothRotator.sendAngle(currentAngle);

Programmeervoorbeelden

Servomotorbesturing

#include <Servo.h> Servo myServo; float currentAngle = 90; void setup() { myServo.attach(9); myServo.write(currentAngle); bluetoothRotator.onRotatorAngle([](float angle) { currentAngle = angle; myServo.write((int)angle); Serial.print("Servo: "); Serial.println(angle); }); } void loop() { bluetoothServer.loop(); }

Pan-Tilt Camera Mount

Servo panServo; Servo tiltServo; // Gebruik twee rotator instanties voor pan en tilt // Of gebruik een enkele rotator voor één as // en een slider voor de andere void setup() { panServo.attach(9); tiltServo.attach(10); bluetoothRotator.onRotatorAngle([](float angle) { panServo.write((int)angle); Serial.print("Pan: "); Serial.println(angle); }); }

Probleemoplossing

Veelvoorkomende Problemen

1. Kan het apparaat niet vinden in de app

  • Zorg ervoor dat de Arduino UNO R4 WiFi is ingeschakeld en de sketch is geüpload
  • Controleer of Bluetooth op uw telefoon is ingeschakeld
  • Op Android 11 en lager, schakel ook Locatiediensten in

2. Servo reageert niet

  • Controleer of de servo is aangesloten op de juiste pin
  • Controleer of de servo bibliotheek is opgenomen en attach() is aangeroepen
  • Zorg voor adequate voeding voor de servo

3. Hoekbereik lijkt verkeerd

  • Controleer de min/max waarden in de constructor
  • Zorg ervoor dat u ROTATOR_MODE_LIMITED gebruikt voor begrensd bereik

4. Draaiknop reset naar 0 bij herverbinding

  • Verstuur de huidige hoek met sendAngle() wanneer het apparaat opnieuw verbindt
  • De voorbeeldcode behandelt dit in de onRotatorAngle callback

5. Upload mislukt of board niet herkend

  • Installeer het nieuwste Arduino UNO R4 board pakket via Board Manager
  • Probeer een andere USB-kabel of poort

Projectideeën

  • Servomotor controller
  • Pan-tilt camera mount
  • Robotarm gewrichtbesturing
  • Draaiknop-gebaseerde thermostaat besturing
  • Kompas/richting display

Volgende Stappen

Na het beheersen van het Bluetooth Rotator voorbeeld, probeer:

  1. Bluetooth Slider - Voor lineaire waardebesturing
  2. Bluetooth Joystick - Voor 2D positiebesturing
  3. Bluetooth Analog Gauge - Voor visuele feedback
  4. Meerdere Bluetooth Apps - Combineren van rotator met andere apps

Ondersteuning

Voor extra hulp:

※ ONZE BERICHTEN

  • U bent welkom om de link naar deze tutorial te delen. Gebruik onze inhoud echter niet op andere websites. We hebben veel moeite en tijd gestoken in het maken van de inhoud, respecteer alstublieft ons werk!