ArduinoESP32 DevKit V1Lab virtual

Bluetooth LED switch (ESP32)

Pair the phone with ESP32_LED (its Bluetooth app) and send 1 or 0: the LED follows and the board answers.

Bluetooth LED switch (ESP32) in Argynix Lab

The code

sketch.inoC++
// An LED switched from a phone over Bluetooth (Classic, serial). Open the phone at the
// bench's foot, its Bluetooth app, connect to ESP32_LED and send 1 or 0.
#include "BluetoothSerial.h"

BluetoothSerial SerialBT;
const int LED = 2;

void setup() {
  Serial.begin(115200);
  pinMode(LED, OUTPUT);
  SerialBT.begin("ESP32_LED");
  Serial.println("Bluetooth up: connect to ESP32_LED");
}

void loop() {
  if (SerialBT.available()) {
    char c = SerialBT.read();
    if (c == '1') {
      digitalWrite(LED, HIGH);
      SerialBT.println("LED on");
      Serial.println("The phone turned the LED on");
    } else if (c == '0') {
      digitalWrite(LED, LOW);
      SerialBT.println("LED off");
      Serial.println("The phone turned the LED off");
    }
  }
  delay(10);
}