ESP32 Bluetooth Digital Pins Beispiel - Pin-Steuerung und Monitor-Interface Tutorial
Das Bluetooth Digital Pins Beispiel bietet ferngesteuerte Steuerung und Überwachung von ESP32 GPIO-Pins über die DIYables Bluetooth STEM App. Entwickelt für ESP32-Boards mit Unterstützung für sowohl BLE (Bluetooth Low Energy) als auch Classic Bluetooth Verbindungen. Konfigurieren Sie Pins als Eingänge oder Ausgänge, schalten Sie Ausgangs-Pins um, lesen Sie digitale und analoge Eingangs-Zustände und erhalten Sie Echtzeit-Pin-Änderungs-Benachrichtigungen — perfekt für Hausautomation, Relais-Steuerung, Button-Monitoring und Sensor-Auslesung.
Dieses Beispiel unterstützt zwei Bluetooth-Modi:
ESP32 BLE (Bluetooth Low Energy): Funktioniert sowohl auf Android als auch iOS
ESP32 Classic Bluetooth: Funktioniert nur auf Android. iOS unterstützt Classic Bluetooth nicht. Verwenden Sie BLE, wenn Sie iOS-Unterstützung benötigen.
Ausgangs-Pin-Steuerung: Schalten Sie digitale Ausgangs-Pins HIGH/LOW über die App
Eingangs-Pin-Überwachung: Lesen Sie digitale und analoge Eingangs-Pin-Zustände
Benutzerdefinierte Pin-Namen: Vergeben Sie benutzerfreundliche Namen für jeden Pin (z.B. "LED", "Btn1", "A34")
Echtzeit-Updates: Automatische Benachrichtigungen bei Änderungen der Eingangs-Pin-Zustände
Bis zu 16 Pins: Unterstützung für bis zu 16 konfigurierbare Pins gleichzeitig
Gemischte Modi: Kombinieren Sie Eingangs- und Ausgangs-Pins im gleichen Setup
BLE & Classic Bluetooth: Wählen Sie den Bluetooth-Modus, der zu Ihrem Projekt passt
Plattformübergreifend: BLE-Modus funktioniert sowohl auf Android als auch iOS; Classic Bluetooth funktioniert auf Android
Oder Sie können die folgenden Kits kaufen:
Offenlegung: Einige der in diesem Abschnitt bereitgestellten Links sind Amazon-Affiliate-Links. Wir können eine Provision für Käufe erhalten, die über diese Links getätigt werden, ohne zusätzliche Kosten für Sie. Wir schätzen Ihre Unterstützung.
Befolgen Sie diese Anweisungen Schritt für Schritt:
Verbinden Sie das ESP32-Board mit Ihrem Computer über ein USB-Kabel.
Starten Sie die Arduino IDE auf Ihrem Computer.
Wählen Sie das entsprechende ESP32-Board und den COM-Port aus.
Navigieren Sie zum Libraries-Symbol in der linken Leiste der Arduino IDE.
Suchen Sie nach "DIYables Bluetooth", dann finden Sie die DIYables Bluetooth-Bibliothek von DIYables
Klicken Sie auf Install, um die Bibliothek zu installieren.
Sie werden nach der Installation einiger anderer Bibliotheks-Abhängigkeiten gefragt
Klicken Sie auf Install All, um alle Bibliotheks-Abhängigkeiten zu installieren.
Wählen Sie einen der beiden Bluetooth-Modi unten, je nach Ihren Anforderungen:
Hinweis: Classic Bluetooth wird NICHT auf iOS unterstützt. Wenn Sie iOS-Unterstützung benötigen, verwenden Sie den BLE-Code unten.
#include <DIYables_BluetoothServer.h>
#include <DIYables_BluetoothPinControl.h>
#include <platforms/DIYables_Esp32Bluetooth.h>
DIYables_Esp32Bluetooth bluetooth("ESP32_Pins");
DIYables_BluetoothServer bluetoothServer(bluetooth);
DIYables_BluetoothPinControl bluetoothPins;
const int LED_PIN = 2;
const int OUTPUT_PIN_1 = 16;
const int OUTPUT_PIN_2 = 17;
const int INPUT_PIN_1 = 18;
const int INPUT_PIN_2 = 19;
const int ANALOG_PIN_1 = 34;
const int ANALOG_PIN_2 = 35;
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("DIYables Bluetooth - ESP32 Pin Control/Monitor Example");
pinMode(LED_PIN, OUTPUT);
pinMode(OUTPUT_PIN_1, OUTPUT);
pinMode(OUTPUT_PIN_2, OUTPUT);
pinMode(INPUT_PIN_1, INPUT_PULLUP);
pinMode(INPUT_PIN_2, INPUT_PULLUP);
bluetoothServer.begin();
bluetoothServer.addApp(&bluetoothPins);
bluetoothPins.enablePin(LED_PIN, BT_PIN_OUTPUT, "LED");
bluetoothPins.enablePin(OUTPUT_PIN_1, BT_PIN_OUTPUT, "Out1");
bluetoothPins.enablePin(OUTPUT_PIN_2, BT_PIN_OUTPUT, "Out2");
bluetoothPins.enablePin(INPUT_PIN_1, BT_PIN_INPUT, "Btn1");
bluetoothPins.enablePin(INPUT_PIN_2, BT_PIN_INPUT, "Btn2");
bluetoothPins.enablePin(ANALOG_PIN_1, BT_PIN_INPUT, "A34");
bluetoothPins.enablePin(ANALOG_PIN_2, BT_PIN_INPUT, "A35");
bluetoothServer.setOnConnected([]() {
Serial.println("Bluetooth connected!");
});
bluetoothServer.setOnDisconnected([]() {
Serial.println("Bluetooth disconnected!");
});
bluetoothPins.onPinWrite([](int pin, int state) {
digitalWrite(pin, state);
Serial.print("Pin ");
Serial.print(pin);
Serial.print(" set to ");
Serial.println(state ? "HIGH" : "LOW");
});
bluetoothPins.onPinRead([](int pin) -> int {
int state;
if (pin == ANALOG_PIN_1 || pin == ANALOG_PIN_2) {
state = analogRead(pin);
Serial.print("Analog pin ");
Serial.print(pin);
Serial.print(" read: ");
Serial.println(state);
} else {
state = digitalRead(pin);
Serial.print("Digital pin ");
Serial.print(pin);
Serial.print(" read: ");
Serial.println(state ? "HIGH" : "LOW");
}
return state;
});
bluetoothPins.onPinModeChange([](int pin, int mode) {
pinMode(pin, mode == BT_PIN_OUTPUT ? OUTPUT : INPUT_PULLUP);
Serial.print("Pin ");
Serial.print(pin);
Serial.print(" mode changed to ");
Serial.println(mode == BT_PIN_OUTPUT ? "OUTPUT" : "INPUT");
});
Serial.println("Waiting for Bluetooth connection...");
Serial.print("Enabled pins: ");
Serial.println(bluetoothPins.getEnabledPinCount());
}
void loop() {
bluetoothServer.loop();
static unsigned long lastInputCheck = 0;
static int lastInputState1 = HIGH;
static int lastInputState2 = HIGH;
static int lastAnalogState1 = 0;
static int lastAnalogState2 = 0;
if (millis() - lastInputCheck >= 100) {
lastInputCheck = millis();
int currentState1 = digitalRead(INPUT_PIN_1);
if (currentState1 != lastInputState1) {
lastInputState1 = currentState1;
bluetoothPins.updatePinState(INPUT_PIN_1, currentState1);
Serial.print("Input pin ");
Serial.print(INPUT_PIN_1);
Serial.print(" changed to ");
Serial.println(currentState1 ? "HIGH" : "LOW");
}
int currentState2 = digitalRead(INPUT_PIN_2);
if (currentState2 != lastInputState2) {
lastInputState2 = currentState2;
bluetoothPins.updatePinState(INPUT_PIN_2, currentState2);
Serial.print("Input pin ");
Serial.print(INPUT_PIN_2);
Serial.print(" changed to ");
Serial.println(currentState2 ? "HIGH" : "LOW");
}
int currentAnalog1 = analogRead(ANALOG_PIN_1);
if (abs(currentAnalog1 - lastAnalogState1) > 50) {
lastAnalogState1 = currentAnalog1;
bluetoothPins.updatePinState(ANALOG_PIN_1, currentAnalog1);
Serial.print("Analog pin ");
Serial.print(ANALOG_PIN_1);
Serial.print(" changed to ");
Serial.println(currentAnalog1);
}
int currentAnalog2 = analogRead(ANALOG_PIN_2);
if (abs(currentAnalog2 - lastAnalogState2) > 50) {
lastAnalogState2 = currentAnalog2;
bluetoothPins.updatePinState(ANALOG_PIN_2, currentAnalog2);
Serial.print("Analog pin ");
Serial.print(ANALOG_PIN_2);
Serial.print(" changed to ");
Serial.println(currentAnalog2);
}
}
delay(10);
}
Klicken Sie auf Upload in der Arduino IDE, um den Code auf den ESP32 hochzuladen
Öffnen Sie den Serial Monitor
Schauen Sie sich das Ergebnis im Serial Monitor an. Es sieht folgendermaßen aus:
DIYables Bluetooth - ESP32 Pin Control/Monitor Example
Waiting for Bluetooth connection...
Enabled pins: 7
#include <DIYables_BluetoothServer.h>
#include <DIYables_BluetoothPinControl.h>
#include <platforms/DIYables_Esp32BLE.h>
const char* DEVICE_NAME = "ESP32BLE_Pins";
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";
DIYables_Esp32BLE bluetooth(DEVICE_NAME, SERVICE_UUID, TX_UUID, RX_UUID);
DIYables_BluetoothServer bluetoothServer(bluetooth);
DIYables_BluetoothPinControl bluetoothPins;
const int LED_PIN = 2;
const int OUTPUT_PIN_1 = 16;
const int OUTPUT_PIN_2 = 17;
const int INPUT_PIN_1 = 25;
const int INPUT_PIN_2 = 26;
const int ANALOG_PIN_1 = 34;
const int ANALOG_PIN_2 = 35;
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("DIYables Bluetooth - ESP32 BLE Pin Control/Monitor Example");
pinMode(LED_PIN, OUTPUT);
pinMode(OUTPUT_PIN_1, OUTPUT);
pinMode(OUTPUT_PIN_2, OUTPUT);
pinMode(INPUT_PIN_1, INPUT_PULLUP);
pinMode(INPUT_PIN_2, INPUT_PULLUP);
bluetoothServer.begin();
bluetoothServer.addApp(&bluetoothPins);
bluetoothPins.enablePin(LED_PIN, BT_PIN_OUTPUT, "LED");
bluetoothPins.enablePin(OUTPUT_PIN_1, BT_PIN_OUTPUT, "Out1");
bluetoothPins.enablePin(OUTPUT_PIN_2, BT_PIN_OUTPUT, "Out2");
bluetoothPins.enablePin(INPUT_PIN_1, BT_PIN_INPUT, "Btn1");
bluetoothPins.enablePin(INPUT_PIN_2, BT_PIN_INPUT, "Btn2");
bluetoothPins.enablePin(ANALOG_PIN_1, BT_PIN_INPUT, "A34");
bluetoothPins.enablePin(ANALOG_PIN_2, BT_PIN_INPUT, "A35");
bluetoothServer.setOnConnected([]() {
Serial.println("Bluetooth connected!");
});
bluetoothServer.setOnDisconnected([]() {
Serial.println("Bluetooth disconnected!");
});
bluetoothPins.onPinWrite([](int pin, int state) {
digitalWrite(pin, state);
Serial.print("Pin ");
Serial.print(pin);
Serial.print(" set to ");
Serial.println(state ? "HIGH" : "LOW");
});
bluetoothPins.onPinRead([](int pin) -> int {
int state;
if (pin == ANALOG_PIN_1 || pin == ANALOG_PIN_2) {
state = analogRead(pin);
Serial.print("Analog pin ");
Serial.print(pin);
Serial.print(" read: ");
Serial.println(state);
} else {
state = digitalRead(pin);
Serial.print("Digital pin ");
Serial.print(pin);
Serial.print(" read: ");
Serial.println(state ? "HIGH" : "LOW");
}
return state;
});
bluetoothPins.onPinModeChange([](int pin, int mode) {
pinMode(pin, mode == BT_PIN_OUTPUT ? OUTPUT : INPUT_PULLUP);
Serial.print("Pin ");
Serial.print(pin);
Serial.print(" mode changed to ");
Serial.println(mode == BT_PIN_OUTPUT ? "OUTPUT" : "INPUT");
});
Serial.println("Waiting for Bluetooth connection...");
Serial.print("Enabled pins: ");
Serial.println(bluetoothPins.getEnabledPinCount());
}
void loop() {
bluetoothServer.loop();
static unsigned long lastInputCheck = 0;
static int lastInputState1 = HIGH;
static int lastInputState2 = HIGH;
static int lastAnalogState1 = 0;
static int lastAnalogState2 = 0;
if (millis() - lastInputCheck >= 100) {
lastInputCheck = millis();
int currentState1 = digitalRead(INPUT_PIN_1);
if (currentState1 != lastInputState1) {
lastInputState1 = currentState1;
bluetoothPins.updatePinState(INPUT_PIN_1, currentState1);
Serial.print("Input pin ");
Serial.print(INPUT_PIN_1);
Serial.print(" changed to ");
Serial.println(currentState1 ? "HIGH" : "LOW");
}
int currentState2 = digitalRead(INPUT_PIN_2);
if (currentState2 != lastInputState2) {
lastInputState2 = currentState2;
bluetoothPins.updatePinState(INPUT_PIN_2, currentState2);
Serial.print("Input pin ");
Serial.print(INPUT_PIN_2);
Serial.print(" changed to ");
Serial.println(currentState2 ? "HIGH" : "LOW");
}
int currentAnalog1 = analogRead(ANALOG_PIN_1);
if (abs(currentAnalog1 - lastAnalogState1) > 40) {
lastAnalogState1 = currentAnalog1;
bluetoothPins.updatePinState(ANALOG_PIN_1, currentAnalog1);
Serial.print("Analog pin ");
Serial.print(ANALOG_PIN_1);
Serial.print(" changed to ");
Serial.println(currentAnalog1);
}
int currentAnalog2 = analogRead(ANALOG_PIN_2);
if (abs(currentAnalog2 - lastAnalogState2) > 40) {
lastAnalogState2 = currentAnalog2;
bluetoothPins.updatePinState(ANALOG_PIN_2, currentAnalog2);
Serial.print("Analog pin ");
Serial.print(ANALOG_PIN_2);
Serial.print(" changed to ");
Serial.println(currentAnalog2);
}
}
delay(10);
}
Klicken Sie auf Upload in der Arduino IDE, um den Code auf den ESP32 hochzuladen
Öffnen Sie den Serial Monitor
Schauen Sie sich das Ergebnis im Serial Monitor an. Es sieht folgendermaßen aus:
DIYables Bluetooth - ESP32 BLE Pin Control/Monitor Example
Waiting for Bluetooth connection...
Enabled pins: 7
Installieren Sie die DIYables Bluetooth App auf Ihrem Smartphone:
Android |
iOS
Wenn Sie den ESP32 Classic Bluetooth Code verwenden, müssen Sie den ESP32 mit Ihrem Android-Telefon vor dem Öffnen der App koppeln:
Gehen Sie zu den Einstellungen > Bluetooth Ihres Telefons
Stellen Sie sicher, dass Bluetooth eingeschaltet ist
Ihr Telefon sucht nach verfügbaren Geräten
Finden und tippen Sie auf "ESP32_Pins" in der Liste der verfügbaren Geräte
Bestätigen Sie die Kopplungsanfrage (keine PIN erforderlich)
Warten Sie, bis "Paired" unter dem Gerätenamen angezeigt wird
Wenn Sie den ESP32 BLE Code verwenden, ist keine Kopplung erforderlich. Fahren Sie einfach mit dem nächsten Schritt fort.
Öffnen Sie die DIYables Bluetooth App
Beim ersten Öffnen der App wird sie nach Berechtigungen fragen. Bitte gewähren Sie folgende:
Nearby Devices Berechtigung (Android 12+) / Bluetooth Berechtigung (iOS) - erforderlich zum Scannen und Verbinden mit Bluetooth-Geräten
Location Berechtigung (nur Android 11 und älter) - erforderlich für ältere Android-Versionen zum Scannen nach BLE-Geräten
Stellen Sie sicher, dass Bluetooth auf Ihrem Telefon eingeschaltet ist
Tippen Sie auf dem Startbildschirm auf Connect. Die App sucht nach BLE- und Classic Bluetooth-Geräten.

Finden und tippen Sie auf Ihr Gerät in den Suchergebnissen, um eine Verbindung herzustellen:
Nach der Verbindung kehrt die App automatisch zum Startbildschirm zurück. Wählen Sie die Digital Pins App aus dem App-Menü.
Hinweis: Sie können das Einstellungssymbol auf dem Startbildschirm antippen, um Apps auf dem Startbildschirm ein-/auszublenden. Weitere Details finden Sie im DIYables Bluetooth App Benutzerhandbuch.
Schauen Sie nun zurück zum Serial Monitor in der Arduino IDE. Sie werden sehen:
Bluetooth connected!
Pin 2 set to HIGH
Pin 16 set to LOW
Input pin 18 changed to LOW
Analog pin 34 changed to 2048
Aktivieren Sie Pins mit benutzerdefinierten Namen und Modi:
bluetoothPins.enablePin(2, BT_PIN_OUTPUT, "LED");
bluetoothPins.enablePin(16, BT_PIN_OUTPUT, "Relay1");
bluetoothPins.enablePin(17, BT_PIN_OUTPUT, "Relay2");
bluetoothPins.enablePin(18, BT_PIN_INPUT, "Button");
bluetoothPins.enablePin(34, BT_PIN_INPUT, "Sensor");
bluetoothPins.disablePin(17);
bool isEnabled = bluetoothPins.isPinEnabled(2);
int mode = bluetoothPins.getPinMode(2);
int count = bluetoothPins.getEnabledPinCount();
Verwenden Sie den onPinWrite() Callback, um Hardware zu steuern, wenn die App einen Pin umschaltet:
bluetoothPins.onPinWrite([](int pin, int state) {
digitalWrite(pin, state);
Serial.print("Pin ");
Serial.print(pin);
Serial.print(" set to ");
Serial.println(state ? "HIGH" : "LOW");
});
Verwenden Sie den onPinRead() Callback, um Pin-Zustände an die App zurückzugeben:
bluetoothPins.onPinRead([](int pin) -> int {
if (pin == 34 || pin == 35) {
return analogRead(pin);
} else {
return digitalRead(pin);
}
});
Verwenden Sie den onPinModeChange() Callback, um Pin-Modi dynamisch zu ändern:
bluetoothPins.onPinModeChange([](int pin, int mode) {
pinMode(pin, mode == BT_PIN_OUTPUT ? OUTPUT : INPUT_PULLUP);
Serial.print("Pin ");
Serial.print(pin);
Serial.print(" mode changed to ");
Serial.println(mode == BT_PIN_OUTPUT ? "OUTPUT" : "INPUT");
});
Senden Sie Pin-Status-Änderungen von Ihrem Code an die App:
int currentState = digitalRead(18);
if (currentState != lastState) {
lastState = currentState;
bluetoothPins.updatePinState(18, currentState);
}
int analogValue = analogRead(34);
if (abs(analogValue - lastAnalogValue) > 50) {
lastAnalogValue = analogValue;
bluetoothPins.updatePinState(34, analogValue);
}
bluetoothServer.setOnConnected([]() {
Serial.println("Bluetooth connected!");
});
bluetoothServer.setOnDisconnected([]() {
Serial.println("Bluetooth disconnected!");
digitalWrite(2, LOW);
digitalWrite(16, LOW);
digitalWrite(17, LOW);
});
Die Digital Pins-Oberfläche in der DIYables Bluetooth App bietet:
Pin-Liste: Zeigt alle aktivierten Pins mit Namen und aktuellen Zuständen
Toggle-Buttons: Tippen Sie auf Ausgangs-Pins, um HIGH/LOW zu schalten
Eingangs-Anzeige: Echtzeit-Anzeige der Eingangs-Pin-Zustände
Analog-Werte: Zeigt rohe Analog-Werte für ADC-Pins
const int RELAY_1 = 16;
const int RELAY_2 = 17;
const int RELAY_3 = 18;
const int RELAY_4 = 19;
void setup() {
pinMode(RELAY_1, OUTPUT);
pinMode(RELAY_2, OUTPUT);
pinMode(RELAY_3, OUTPUT);
pinMode(RELAY_4, OUTPUT);
bluetoothPins.enablePin(RELAY_1, BT_PIN_OUTPUT, "Light");
bluetoothPins.enablePin(RELAY_2, BT_PIN_OUTPUT, "Fan");
bluetoothPins.enablePin(RELAY_3, BT_PIN_OUTPUT, "Pump");
bluetoothPins.enablePin(RELAY_4, BT_PIN_OUTPUT, "Heater");
bluetoothPins.onPinWrite([](int pin, int state) {
digitalWrite(pin, state);
Serial.print("Relay on pin ");
Serial.print(pin);
Serial.println(state ? " activated" : " deactivated");
});
}
const int BUTTON_PINS[] = {18, 19, 21, 22};
const char* BUTTON_NAMES[] = {"Btn1", "Btn2", "Btn3", "Btn4"};
const int NUM_BUTTONS = 4;
int lastButtonStates[4] = {HIGH, HIGH, HIGH, HIGH};
void setup() {
for (int i = 0; i < NUM_BUTTONS; i++) {
pinMode(BUTTON_PINS[i], INPUT_PULLUP);
bluetoothPins.enablePin(BUTTON_PINS[i], BT_PIN_INPUT, BUTTON_NAMES[i]);
}
bluetoothPins.onPinRead([](int pin) -> int {
return digitalRead(pin);
});
}
void loop() {
bluetoothServer.loop();
for (int i = 0; i < NUM_BUTTONS; i++) {
int state = digitalRead(BUTTON_PINS[i]);
if (state != lastButtonStates[i]) {
lastButtonStates[i] = state;
bluetoothPins.updatePinState(BUTTON_PINS[i], state);
}
}
delay(10);
}
void setup() {
bluetoothPins.enablePin(2, BT_PIN_OUTPUT, "LED");
bluetoothPins.enablePin(16, BT_PIN_OUTPUT, "Relay");
bluetoothPins.enablePin(18, BT_PIN_INPUT, "Motion");
bluetoothPins.enablePin(19, BT_PIN_INPUT, "Door");
bluetoothPins.enablePin(34, BT_PIN_INPUT, "Light");
bluetoothPins.enablePin(35, BT_PIN_INPUT, "Temp");
pinMode(2, OUTPUT);
pinMode(16, OUTPUT);
pinMode(18, INPUT_PULLUP);
pinMode(19, INPUT_PULLUP);
bluetoothPins.onPinWrite([](int pin, int state) {
digitalWrite(pin, state);
});
bluetoothPins.onPinRead([](int pin) -> int {
if (pin == 34 || pin == 35) return analogRead(pin);
return digitalRead(pin);
});
}
bool safetyEnabled = true;
bluetoothPins.onPinWrite([](int pin, int state) {
if (pin == 16 && state == HIGH) {
if (digitalRead(18) == LOW) {
bluetoothPins.updatePinState(16, 0);
Serial.println("SAFETY: Operation blocked - safety switch off");
return;
}
}
digitalWrite(pin, state);
});
unsigned long pinTimers[16] = {0};
unsigned long PIN_TIMEOUT = 300000;
bluetoothPins.onPinWrite([](int pin, int state) {
digitalWrite(pin, state);
if (state == HIGH) {
pinTimers[pin] = millis();
} else {
pinTimers[pin] = 0;
}
});
void loop() {
bluetoothServer.loop();
for (int i = 0; i < 16; i++) {
if (pinTimers[i] > 0 && millis() - pinTimers[i] >= PIN_TIMEOUT) {
digitalWrite(i, LOW);
pinTimers[i] = 0;
bluetoothPins.updatePinState(i, 0);
Serial.print("Auto-off: Pin ");
Serial.println(i);
}
}
delay(10);
}
| Feature | BLE (Esp32BLE_PinControl) | Classic Bluetooth (Esp32Bluetooth_PinControl) |
| iOS-Unterstützung | ? Ja | ? Nein |
| Android-Unterstützung | ? Ja | ? Ja |
| Stromverbrauch | Niedrig | Höher |
| Reichweite | ~30-100m | ~10-100m |
| Datenrate | Niedriger | Höher |
| Kopplung erforderlich | Nein (Auto-Connect) | Ja (manuell koppeln) |
| Am besten für | Batteriebetrieb, plattformübergreifend | Hoher Durchsatz, nur Android |
1. Gerät kann in der App nicht gefunden werden
Stellen Sie sicher, dass der ESP32 eingeschaltet und das Sketch hochgeladen ist
Für BLE: Stellen Sie sicher, dass Bluetooth und Standort Ihres Telefons aktiviert sind
Für Classic Bluetooth: Koppeln Sie das Gerät zuerst in den Bluetooth-Einstellungen des Telefons
Prüfen Sie, dass das richtige Partition Scheme ausgewählt ist (Huge APP)
2. Pins erscheinen nicht in der App
Stellen Sie sicher, dass enablePin() vor der Bluetooth-Verbindung aufgerufen wird
Prüfen Sie getEnabledPinCount() im Serial Monitor
Überprüfen Sie, ob Pin-Nummern zwischen 0 und 15 liegen
3. Ausgangs-Pins schalten nicht um
Überprüfen Sie, dass der onPinWrite() Callback digitalWrite() aufruft
Prüfen Sie, dass Pins als BT_PIN_OUTPUT konfiguriert sind
Überprüfen Sie Hardware-Verbindungen
4. Eingangs-Werte aktualisieren sich nicht
Stellen Sie sicher, dass updatePinState() bei Zustandsänderungen aufgerufen wird
Prüfen Sie das Polling-Intervall in der Schleife
Für Analog-Pins, passen Sie die Änderungs-Schwelle an
5. Zu viele Pins verursachen Fehler
Maximum 16 Pins unterstützt (0-15)
Halten Sie Pin-Namen kurz, um Nachrichten-Verkürzung zu vermeiden
Verwenden Sie kürzere Namen, wenn Sie Verkürzungs-Warnungen erhalten
6. Sketch zu groß / nicht genügend Speicherplatz
Gehen Sie in der Arduino IDE zu Tools > Partition Scheme und wählen Sie "Huge APP (3MB No OTA/1MB SPIFFS)" oder "No OTA (Large APP)"
Das Standard-Partition-Schema bietet nur ~1.2MB für App-Code, was für Bluetooth-Bibliotheken nicht ausreicht
Diese Einstellung bietet ~3MB durch Verzicht auf die OTA (Over-the-Air Update) Partition
Fügen Sie umfassendes Debugging hinzu:
void debugPinConfig() {
Serial.println("=== Pin Config Debug ===");
Serial.println("Enabled pins: " + String(bluetoothPins.getEnabledPinCount()));
for (int i = 0; i < 16; i++) {
if (bluetoothPins.isPinEnabled(i)) {
Serial.print(" Pin " + String(i) + ": ");
Serial.println(bluetoothPins.getPinMode(i) == BT_PIN_OUTPUT ? "OUTPUT" : "INPUT");
}
}
Serial.println("========================");
}
Bluetooth-Lichtschalter-Controller
Multi-Raum-Relais-Steuerungspanel
Garagentor-Öffner
Garten-Bewässerungs-Ventilsteuerung
Digitalelektronik-Lernwerkzeug
GPIO-Pin-Erforschung
Input/Output-Schaltungs-Tests
Breadboard-Projekt-Controller
Verwenden Sie Digital Pins für Ein/Aus und Slider für PWM-Intensität:
bluetoothPins.onPinWrite([](int pin, int state) {
if (state == HIGH) {
analogWrite(pin, map(currentSlider1, 0, 100, 0, 255));
} else {
analogWrite(pin, 0);
}
});
Loggen Sie Pin-Änderungen zum Monitor:
bluetoothPins.onPinWrite([](int pin, int state) {
digitalWrite(pin, state);
bluetoothMonitor.send("Pin " + String(pin) + " -> " + String(state ? "ON" : "OFF"));
});
Nach dem Beherrschen des Bluetooth Digital Pins Beispiels, versuchen Sie:
Bluetooth Slider - Für analog-ähnliche PWM-Steuerung
Bluetooth Monitor - Für Debugging von Pin-Zuständen
Bluetooth Table - Für strukturierte Pin-Daten-Anzeige
Multiple Bluetooth Apps - Kombination von Pin-Steuerung mit anderen Features