Arduino UNO R4 WiFi Bluetooth Analoge Meter Voorbeeld - Meter Weergave via BLE Tutorial

Overzicht

Het Bluetooth Analoge Meter voorbeeld biedt een visuele analoge-stijl meter weergave via de DIYables Bluetooth STEM app. Ontworpen voor Arduino UNO R4 WiFi met BLE (Bluetooth Low Energy) — geef elke analoge waarde weer op een mooie meter met configureerbaar bereik en eenheid op uw smartphone. Perfect voor snelheidsmeters, drukmeters, RPM displays, en elke waarde die baat heeft bij een wijzerplaat-visualisatie.

Opmerking: De Arduino UNO R4 WiFi ondersteunt alleen BLE (Bluetooth Low Energy). Het ondersteunt geen Classic Bluetooth. De DIYables Bluetooth App ondersteunt zowel BLE als Classic 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 Analoge Meter Voorbeeld - Meter Weergave via BLE Tutorial

Functies

  • Analoge Meter Weergave: Mooie wijzerplaat-stijl meter op smartphone
  • Configureerbaar Bereik: Stel minimum en maximum waarden in
  • Aangepaste Eenheid: Geef km/h, RPM, PSI, of elke aangepaste eenheid weer
  • Snelle Updates: Tot 5 updates per seconde (200ms interval)
  • On-Demand Verzoek: App kan huidige waarde opvragen
  • Werkt op Android & iOS: BLE wordt ondersteund op beide platformen
  • Geen Koppeling Vereist: BLE verbindt automatisch 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 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 icoon in de linker balk van de Arduino IDE.
  • Zoek "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 bibliotheek afhankelijkheden te installeren
  • Klik op de Install All knop om alle bibliotheek afhankelijkheden te installeren.
Arduino UNO R4 DIYables Bluetooth afhankelijkheid

BLE Code

  • Ga in Arduino IDE naar File Examples DIYables Bluetooth ArduinoBLE_AnalogGauge voorbeeld, of kopieer de bovenstaande code en plak het in de editor van Arduino IDE
/* * DIYables Bluetooth Library - Bluetooth Analog Gauge Example * Works with DIYables Bluetooth STEM app on Android and iOS * * This example demonstrates the Bluetooth Analog Gauge feature: * - Display values on an analog meter/gauge * - Configurable range and unit * - Perfect for sensor monitoring (speed, pressure, voltage, etc.) * * 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: Analog sensor (potentiometer, pressure sensor, etc.) * * Setup: * 1. Upload the sketch to your Arduino * 2. Open Serial Monitor to see connection status * 3. Use DIYables Bluetooth App to connect and view the gauge * * Tutorial: https://diyables.io/bluetooth-app * Author: DIYables */ #include <DIYables_BluetoothServer.h> #include <DIYables_BluetoothAnalogGauge.h> #include <platforms/DIYables_ArduinoBLE.h> // BLE Configuration const char* DEVICE_NAME = "Arduino_Gauge"; 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 Analog Gauge app instance (min=0, max=100, unit="km/h") DIYables_BluetoothAnalogGauge bluetoothGauge(0.0, 100.0, "km/h"); // Variables for gauge value float currentValue = 0.0; unsigned long lastUpdate = 0; const unsigned long UPDATE_INTERVAL = 200; // Update every 200ms // Optional: Analog input pin for sensor const int ANALOG_PIN = A0; // Function to read sensor value float readSensorValue() { // TODO: Replace with actual sensor reading // Examples: // - Pressure sensor: readPressure() // - Voltage sensor: analogRead(A0) * (5.0 / 1023.0) // - Speed sensor: calculateSpeed() // Option 1: Read from analog pin and map to gauge range // int rawValue = analogRead(ANALOG_PIN); // return map(rawValue, 0, 1023, 0, 100); // Option 2: Simulated data (sine wave) static float phase = 0; phase += 0.05; if (phase > 2 * PI) phase = 0; return 50 + 50 * sin(phase); // Oscillates between 0-100 } void setup() { Serial.begin(9600); while (!Serial); Serial.println("DIYables Bluetooth - Analog Gauge Example"); // Optional: Initialize analog pin // pinMode(ANALOG_PIN, INPUT); // Initialize Bluetooth server with platform-specific implementation bluetoothServer.begin(); // Add gauge app to server bluetoothServer.addApp(&bluetoothGauge); // Set up connection event callbacks bluetoothServer.setOnConnected([]() { Serial.println("Bluetooth connected!"); // Send initial value currentValue = readSensorValue(); bluetoothGauge.send(currentValue); Serial.print("Initial value sent: "); Serial.print(currentValue); Serial.print(" "); Serial.println(bluetoothGauge.getUnit()); }); bluetoothServer.setOnDisconnected([]() { Serial.println("Bluetooth disconnected!"); }); // Optional: Handle requests for current value bluetoothGauge.onValueRequest([]() { currentValue = readSensorValue(); bluetoothGauge.send(currentValue); Serial.print("Value requested - Sent: "); Serial.print(currentValue); Serial.print(" "); Serial.println(bluetoothGauge.getUnit()); }); // You can change gauge configuration at runtime: // bluetoothGauge.setRange(0.0, 200.0); // Change range to 0-200 // bluetoothGauge.setUnit("mph"); // Change unit to mph // bluetoothGauge.setRange(0.0, 5.0); // For voltage (0-5V) // bluetoothGauge.setUnit("V"); Serial.println("Waiting for Bluetooth connection..."); Serial.print("Gauge range: "); Serial.print(bluetoothGauge.getMin()); Serial.print(" - "); Serial.print(bluetoothGauge.getMax()); Serial.print(" "); Serial.println(bluetoothGauge.getUnit()); } void loop() { // Handle Bluetooth server communications bluetoothServer.loop(); // Send gauge updates periodically (only when connected) if (bluetooth.isConnected() && millis() - lastUpdate >= UPDATE_INTERVAL) { lastUpdate = millis(); // Read sensor value currentValue = readSensorValue(); // Send to Bluetooth app bluetoothGauge.send(currentValue); // Print to Serial Monitor Serial.print("Gauge: "); Serial.print(currentValue, 1); Serial.print(" "); Serial.println(bluetoothGauge.getUnit()); } delay(10); }
  • Klik op de Upload knop in Arduino IDE om code naar Arduino UNO R4 WiFi te uploaden
  • Open de Serial Monitor
  • Bekijk het resultaat in Serial Monitor. Het ziet er als volgt uit:
COM6
Send
DIYables Bluetooth - Analog Gauge 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 Classic 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 — gewoon scannen en verbinden.

  • Open de DIYables Bluetooth App
  • Bij het eerste openen van de app wordt u om toestemming gevraagd. Verleen de volgende:
    • Nearby Devices toestemming (Android 12+) / Bluetooth toestemming (iOS) - vereist om Bluetooth-apparaten te scannen en te 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 startscherm op de Connect knop. De app zal scannen naar BLE apparaten.
DIYables Bluetooth App - Startscherm met Scan Knop
  • Zoek en tik op "Arduino_Gauge" in de scanresultaten om te verbinden.
  • Zodra verbonden, gaat de app automatisch terug naar het startscherm. Selecteer de Analog Gauge app uit het app menu.
DIYables Bluetooth App - Startscherm met Analoge Meter App

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

  • U ziet een analoge meter die waarden weergeeft met een vloeiende naaldbeweging, die een snelheidsmeter simuleert
DIYables Bluetooth App - Analoge Meter Scherm

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

COM6
Send
Bluetooth connected! Gauge value: 50.00 km/h Gauge value: 59.76 km/h Gauge value: 68.78 km/h
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Creatieve Aanpassing - Pas de Code aan Uw Project Aan

Configureer Meter Bereik en Eenheid

// Snelheidsmeter: 0-200 km/h DIYables_BluetoothAnalogGauge bluetoothGauge(bluetoothServer, 0.0, 200.0, "km/h"); // Drukmeter: 0-100 PSI DIYables_BluetoothAnalogGauge bluetoothGauge(bluetoothServer, 0.0, 100.0, "PSI"); // RPM meter: 0-8000 RPM DIYables_BluetoothAnalogGauge bluetoothGauge(bluetoothServer, 0.0, 8000.0, "RPM"); // Percentage: 0-100% DIYables_BluetoothAnalogGauge bluetoothGauge(bluetoothServer, 0.0, 100.0, "%");

Verzend Meter Waarden

// Verzend een waarde naar de meter bluetoothGauge.send(75.5); // Lees van sensor en verzend float sensorValue = analogRead(A0) * (100.0 / 1023.0); bluetoothGauge.send(sensorValue);

Behandel Waarde Verzoeken

bluetoothGauge.onValueRequest([]() { float value = readSensor(); bluetoothGauge.send(value); Serial.print("Requested: "); Serial.println(value); });

Programmeervoorbeelden

Potentiometer Meter

DIYables_BluetoothAnalogGauge bluetoothGauge(bluetoothServer, 0.0, 100.0, "%"); void loop() { bluetoothServer.loop(); static unsigned long lastTime = 0; if (millis() - lastTime >= 200) { lastTime = millis(); float percent = analogRead(A0) * (100.0 / 1023.0); bluetoothGauge.send(percent); } }

Batterij Niveau Monitor

DIYables_BluetoothAnalogGauge bluetoothGauge(bluetoothServer, 0.0, 100.0, "%"); float readBatteryLevel() { float voltage = analogRead(A0) * (5.0 / 1023.0) * 2; // spanningsdeler float percent = map(voltage * 100, 300, 420, 0, 100); return constrain(percent, 0, 100); } void loop() { bluetoothServer.loop(); static unsigned long lastTime = 0; if (millis() - lastTime >= 1000) { lastTime = millis(); bluetoothGauge.send(readBatteryLevel()); } }

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
  • Zorg ervoor dat Bluetooth op uw telefoon is ingeschakeld
  • Schakel op Android 11 en lager ook Location services in

2. Meter wordt niet bijgewerkt

  • Controleer of send() wordt aangeroepen in de loop
  • Verifieer de timing van het update interval
  • Zorg ervoor dat bluetoothServer.loop() wordt aangeroepen

3. Meter toont verkeerd bereik

  • Controleer de min/max waarden in de constructor
  • Zorg ervoor dat de eenheid string correct is
  • Waarden buiten het bereik worden afgekapt

4. Naald springt erratisch

  • Voeg afvlakking of gemiddeling toe aan sensor aflezingen
  • Verminder update frequentie indien nodig
  • Controleer op ruis in analoge ingangen

5. Upload mislukt of board niet herkend

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

Projectideeën

  • Snelheidsmeter voor RC auto
  • Drukmeter voor pneumatische systemen
  • Batterij niveau indicator
  • RPM meter voor motoren
  • Signaalsterkte meter

Volgende Stappen

Na het beheersen van het Bluetooth Analoge Meter voorbeeld, probeer:

  1. Bluetooth Temperature - Voor temperatuur-specifieke meter
  2. Bluetooth Plotter - Voor data over tijd
  3. Bluetooth Slider - Voor het instellen van waarden terug naar Arduino
  4. Meerdere Bluetooth Apps - Combineer meter 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!